blob: f2c6b58f08da78579bf466dca0df479bd09c1a2b [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- SBError.cpp ---------------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "lldb/API/SBError.h"
11#include "lldb/Core/Error.h"
Eli Friedman7a62c8b2010-06-09 07:44:37 +000012#include <cstdarg>
Chris Lattner24943d22010-06-08 16:52:24 +000013
14using namespace lldb;
15using namespace lldb_private;
16
17
18SBError::SBError () :
19 m_lldb_object_ap ()
20{
21}
22
23SBError::SBError (const SBError &rhs) :
24 m_lldb_object_ap ()
25{
26 if (rhs.IsValid())
27 m_lldb_object_ap.reset (new Error(*rhs));
28}
29
30
31SBError::~SBError()
32{
33}
34
35const SBError &
36SBError::operator = (const SBError &rhs)
37{
38 if (rhs.IsValid())
39 {
40 if (m_lldb_object_ap.get())
41 *m_lldb_object_ap = *rhs;
42 else
43 m_lldb_object_ap.reset (new Error(*rhs));
44 }
45 else
46 {
47 m_lldb_object_ap.reset();
48 }
49 return *this;
50}
51
52
53const char *
54SBError::GetCString () const
55{
56 if (m_lldb_object_ap.get())
57 return m_lldb_object_ap->AsCString();
58 return NULL;
59}
60
61void
62SBError::Clear ()
63{
64 if (m_lldb_object_ap.get())
65 m_lldb_object_ap->Clear();
66}
67
68bool
69SBError::Fail () const
70{
71 if (m_lldb_object_ap.get())
72 return m_lldb_object_ap->Fail();
73 return false;
74}
75
76bool
77SBError::Success () const
78{
79 if (m_lldb_object_ap.get())
80 return m_lldb_object_ap->Success();
81 return false;
82}
83
84uint32_t
85SBError::GetError () const
86{
87 if (m_lldb_object_ap.get())
88 return m_lldb_object_ap->GetError();
89 return true;
90}
91
92ErrorType
93SBError::GetType () const
94{
95 if (m_lldb_object_ap.get())
96 return m_lldb_object_ap->GetType();
97 return eErrorTypeInvalid;
98}
99
100void
101SBError::SetError (uint32_t err, ErrorType type)
102{
103 CreateIfNeeded ();
104 m_lldb_object_ap->SetError (err, type);
105}
106
107void
108SBError::SetError (const Error &lldb_error)
109{
110 CreateIfNeeded ();
111 *m_lldb_object_ap = lldb_error;
112}
113
114
115void
116SBError::SetErrorToErrno ()
117{
118 CreateIfNeeded ();
119 m_lldb_object_ap->SetErrorToErrno ();
120}
121
122void
123SBError::SetErrorToGenericError ()
124{
125 CreateIfNeeded ();
126 m_lldb_object_ap->SetErrorToErrno ();
127}
128
129void
130SBError::SetErrorString (const char *err_str)
131{
132 CreateIfNeeded ();
133 m_lldb_object_ap->SetErrorString (err_str);
134}
135
136int
137SBError::SetErrorStringWithFormat (const char *format, ...)
138{
139 CreateIfNeeded ();
140 va_list args;
141 va_start (args, format);
142 int num_chars = m_lldb_object_ap->SetErrorStringWithVarArg (format, args);
143 va_end (args);
144 return num_chars;
145}
146
147bool
148SBError::IsValid () const
149{
150 return m_lldb_object_ap.get() != NULL;
151}
152
153void
154SBError::CreateIfNeeded ()
155{
156 if (m_lldb_object_ap.get() == NULL)
157 m_lldb_object_ap.reset(new Error ());
158}
159
160
161lldb_private::Error *
162SBError::operator->()
163{
164 return m_lldb_object_ap.get();
165}
166
167lldb_private::Error *
168SBError::get()
169{
170 return m_lldb_object_ap.get();
171}
172
173
174const lldb_private::Error &
175SBError::operator*() const
176{
177 // Be sure to call "IsValid()" before calling this function or it will crash
178 return *m_lldb_object_ap;
179}
180