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