1 //===-- SBTypeFormat.cpp ------------------------------------------*- C++
4 // The LLVM Compiler Infrastructure
6 // This file is distributed under the University of Illinois Open Source
7 // License. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
11 #include "lldb/API/SBTypeFormat.h"
13 #include "lldb/API/SBStream.h"
15 #include "lldb/DataFormatters/DataVisualization.h"
18 using namespace lldb_private;
20 SBTypeFormat::SBTypeFormat() : m_opaque_sp() {}
22 SBTypeFormat::SBTypeFormat(lldb::Format format, uint32_t options)
24 TypeFormatImplSP(new TypeFormatImpl_Format(format, options))) {}
26 SBTypeFormat::SBTypeFormat(const char *type, uint32_t options)
27 : m_opaque_sp(TypeFormatImplSP(new TypeFormatImpl_EnumType(
28 ConstString(type ? type : ""), options))) {}
30 SBTypeFormat::SBTypeFormat(const lldb::SBTypeFormat &rhs)
31 : m_opaque_sp(rhs.m_opaque_sp) {}
33 SBTypeFormat::~SBTypeFormat() {}
35 bool SBTypeFormat::IsValid() const { return m_opaque_sp.get() != NULL; }
37 lldb::Format SBTypeFormat::GetFormat() {
38 if (IsValid() && m_opaque_sp->GetType() == TypeFormatImpl::Type::eTypeFormat)
39 return ((TypeFormatImpl_Format *)m_opaque_sp.get())->GetFormat();
40 return lldb::eFormatInvalid;
43 const char *SBTypeFormat::GetTypeName() {
44 if (IsValid() && m_opaque_sp->GetType() == TypeFormatImpl::Type::eTypeEnum)
45 return ((TypeFormatImpl_EnumType *)m_opaque_sp.get())
51 uint32_t SBTypeFormat::GetOptions() {
53 return m_opaque_sp->GetOptions();
57 void SBTypeFormat::SetFormat(lldb::Format fmt) {
58 if (CopyOnWrite_Impl(Type::eTypeFormat))
59 ((TypeFormatImpl_Format *)m_opaque_sp.get())->SetFormat(fmt);
62 void SBTypeFormat::SetTypeName(const char *type) {
63 if (CopyOnWrite_Impl(Type::eTypeEnum))
64 ((TypeFormatImpl_EnumType *)m_opaque_sp.get())
65 ->SetTypeName(ConstString(type ? type : ""));
68 void SBTypeFormat::SetOptions(uint32_t value) {
69 if (CopyOnWrite_Impl(Type::eTypeKeepSame))
70 m_opaque_sp->SetOptions(value);
73 bool SBTypeFormat::GetDescription(lldb::SBStream &description,
74 lldb::DescriptionLevel description_level) {
78 description.Printf("%s\n", m_opaque_sp->GetDescription().c_str());
83 lldb::SBTypeFormat &SBTypeFormat::operator=(const lldb::SBTypeFormat &rhs) {
85 m_opaque_sp = rhs.m_opaque_sp;
90 bool SBTypeFormat::operator==(lldb::SBTypeFormat &rhs) {
92 return !rhs.IsValid();
93 return m_opaque_sp == rhs.m_opaque_sp;
96 bool SBTypeFormat::IsEqualTo(lldb::SBTypeFormat &rhs) {
98 return !rhs.IsValid();
100 if (GetFormat() == rhs.GetFormat())
101 return GetOptions() == rhs.GetOptions();
106 bool SBTypeFormat::operator!=(lldb::SBTypeFormat &rhs) {
108 return !rhs.IsValid();
109 return m_opaque_sp != rhs.m_opaque_sp;
112 lldb::TypeFormatImplSP SBTypeFormat::GetSP() { return m_opaque_sp; }
114 void SBTypeFormat::SetSP(const lldb::TypeFormatImplSP &typeformat_impl_sp) {
115 m_opaque_sp = typeformat_impl_sp;
118 SBTypeFormat::SBTypeFormat(const lldb::TypeFormatImplSP &typeformat_impl_sp)
119 : m_opaque_sp(typeformat_impl_sp) {}
121 bool SBTypeFormat::CopyOnWrite_Impl(Type type) {
125 if (m_opaque_sp.unique() &&
126 ((type == Type::eTypeKeepSame) ||
127 (type == Type::eTypeFormat &&
128 m_opaque_sp->GetType() == TypeFormatImpl::Type::eTypeFormat) ||
129 (type == Type::eTypeEnum &&
130 m_opaque_sp->GetType() == TypeFormatImpl::Type::eTypeEnum)))
133 if (type == Type::eTypeKeepSame) {
134 if (m_opaque_sp->GetType() == TypeFormatImpl::Type::eTypeFormat)
135 type = Type::eTypeFormat;
137 type = Type::eTypeEnum;
140 if (type == Type::eTypeFormat)
142 TypeFormatImplSP(new TypeFormatImpl_Format(GetFormat(), GetOptions())));
144 SetSP(TypeFormatImplSP(
145 new TypeFormatImpl_EnumType(ConstString(GetTypeName()), GetOptions())));