1 //===-- SBTypeEnumMember.cpp ---------------------------------- -*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/API/SBTypeEnumMember.h"
11 #include "lldb/API/SBDefines.h"
12 #include "lldb/API/SBStream.h"
13 #include "lldb/API/SBType.h"
14 #include "lldb/Symbol/CompilerType.h"
15 #include "lldb/Symbol/Type.h"
16 #include "lldb/Utility/Stream.h"
19 using namespace lldb_private;
21 SBTypeEnumMember::SBTypeEnumMember() : m_opaque_sp() {}
23 SBTypeEnumMember::~SBTypeEnumMember() {}
24 SBTypeEnumMember::SBTypeEnumMember(
25 const lldb::TypeEnumMemberImplSP &enum_member_sp)
26 : m_opaque_sp(enum_member_sp) {}
28 SBTypeEnumMember::SBTypeEnumMember(const SBTypeEnumMember &rhs)
32 m_opaque_sp.reset(new TypeEnumMemberImpl(rhs.ref()));
36 SBTypeEnumMember &SBTypeEnumMember::operator=(const SBTypeEnumMember &rhs) {
39 m_opaque_sp.reset(new TypeEnumMemberImpl(rhs.ref()));
44 bool SBTypeEnumMember::IsValid() const { return m_opaque_sp.get(); }
46 const char *SBTypeEnumMember::GetName() {
47 if (m_opaque_sp.get())
48 return m_opaque_sp->GetName().GetCString();
52 int64_t SBTypeEnumMember::GetValueAsSigned() {
53 if (m_opaque_sp.get())
54 return m_opaque_sp->GetValueAsSigned();
58 uint64_t SBTypeEnumMember::GetValueAsUnsigned() {
59 if (m_opaque_sp.get())
60 return m_opaque_sp->GetValueAsUnsigned();
64 SBType SBTypeEnumMember::GetType() {
66 if (m_opaque_sp.get()) {
67 sb_type.SetSP(m_opaque_sp->GetIntegerType());
72 void SBTypeEnumMember::reset(TypeEnumMemberImpl *type_member_impl) {
73 m_opaque_sp.reset(type_member_impl);
76 TypeEnumMemberImpl &SBTypeEnumMember::ref() {
77 if (m_opaque_sp.get() == NULL)
78 m_opaque_sp.reset(new TypeEnumMemberImpl());
79 return *m_opaque_sp.get();
82 const TypeEnumMemberImpl &SBTypeEnumMember::ref() const {
83 return *m_opaque_sp.get();
86 SBTypeEnumMemberList::SBTypeEnumMemberList()
87 : m_opaque_ap(new TypeEnumMemberListImpl()) {}
89 SBTypeEnumMemberList::SBTypeEnumMemberList(const SBTypeEnumMemberList &rhs)
90 : m_opaque_ap(new TypeEnumMemberListImpl()) {
92 rhs_size = const_cast<SBTypeEnumMemberList &>(rhs).GetSize();
94 Append(const_cast<SBTypeEnumMemberList &>(rhs).GetTypeEnumMemberAtIndex(i));
97 bool SBTypeEnumMemberList::IsValid() { return (m_opaque_ap.get() != NULL); }
99 SBTypeEnumMemberList &SBTypeEnumMemberList::
100 operator=(const SBTypeEnumMemberList &rhs) {
102 m_opaque_ap.reset(new TypeEnumMemberListImpl());
104 rhs_size = const_cast<SBTypeEnumMemberList &>(rhs).GetSize();
107 const_cast<SBTypeEnumMemberList &>(rhs).GetTypeEnumMemberAtIndex(i));
112 void SBTypeEnumMemberList::Append(SBTypeEnumMember enum_member) {
113 if (enum_member.IsValid())
114 m_opaque_ap->Append(enum_member.m_opaque_sp);
118 SBTypeEnumMemberList::GetTypeEnumMemberAtIndex(uint32_t index) {
119 if (m_opaque_ap.get())
120 return SBTypeEnumMember(m_opaque_ap->GetTypeEnumMemberAtIndex(index));
121 return SBTypeEnumMember();
124 uint32_t SBTypeEnumMemberList::GetSize() { return m_opaque_ap->GetSize(); }
126 SBTypeEnumMemberList::~SBTypeEnumMemberList() {}
128 bool SBTypeEnumMember::GetDescription(
129 lldb::SBStream &description, lldb::DescriptionLevel description_level) {
130 Stream &strm = description.ref();
132 if (m_opaque_sp.get()) {
133 if (m_opaque_sp->GetIntegerType()->GetDescription(strm,
134 description_level)) {
135 strm.Printf(" %s", m_opaque_sp->GetName().GetCString());
138 strm.PutCString("No value");