1 //===-- SBTypeFormat.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/SBTypeFormat.h"
12 #include "lldb/API/SBStream.h"
14 #include "lldb/DataFormatters/DataVisualization.h"
17 using namespace lldb_private;
19 SBTypeFormat::SBTypeFormat() :
24 SBTypeFormat::SBTypeFormat (lldb::Format format,
26 : m_opaque_sp(TypeFormatImplSP(new TypeFormatImpl_Format(format,options)))
30 SBTypeFormat::SBTypeFormat (const char* type,
32 : m_opaque_sp(TypeFormatImplSP(new TypeFormatImpl_EnumType(ConstString(type ? type : ""),options)))
36 SBTypeFormat::SBTypeFormat (const lldb::SBTypeFormat &rhs) :
37 m_opaque_sp(rhs.m_opaque_sp)
41 SBTypeFormat::~SBTypeFormat ()
46 SBTypeFormat::IsValid() const
48 return m_opaque_sp.get() != NULL;
52 SBTypeFormat::GetFormat ()
54 if (IsValid() && m_opaque_sp->GetType() == TypeFormatImpl::Type::eTypeFormat)
55 return ((TypeFormatImpl_Format*)m_opaque_sp.get())->GetFormat();
56 return lldb::eFormatInvalid;
60 SBTypeFormat::GetTypeName ()
62 if (IsValid() && m_opaque_sp->GetType() == TypeFormatImpl::Type::eTypeEnum)
63 return ((TypeFormatImpl_EnumType*)m_opaque_sp.get())->GetTypeName().AsCString("");
68 SBTypeFormat::GetOptions()
71 return m_opaque_sp->GetOptions();
76 SBTypeFormat::SetFormat (lldb::Format fmt)
78 if (CopyOnWrite_Impl(Type::eTypeFormat))
79 ((TypeFormatImpl_Format*)m_opaque_sp.get())->SetFormat(fmt);
83 SBTypeFormat::SetTypeName (const char* type)
85 if (CopyOnWrite_Impl(Type::eTypeEnum))
86 ((TypeFormatImpl_EnumType*)m_opaque_sp.get())->SetTypeName(ConstString(type ? type : ""));
90 SBTypeFormat::SetOptions (uint32_t value)
92 if (CopyOnWrite_Impl(Type::eTypeKeepSame))
93 m_opaque_sp->SetOptions(value);
97 SBTypeFormat::GetDescription (lldb::SBStream &description,
98 lldb::DescriptionLevel description_level)
103 description.Printf("%s\n",
104 m_opaque_sp->GetDescription().c_str());
110 SBTypeFormat::operator = (const lldb::SBTypeFormat &rhs)
114 m_opaque_sp = rhs.m_opaque_sp;
120 SBTypeFormat::operator == (lldb::SBTypeFormat &rhs)
122 if (IsValid() == false)
123 return !rhs.IsValid();
124 return m_opaque_sp == rhs.m_opaque_sp;
128 SBTypeFormat::IsEqualTo (lldb::SBTypeFormat &rhs)
130 if (IsValid() == false)
131 return !rhs.IsValid();
133 if (GetFormat() == rhs.GetFormat())
134 return GetOptions() == rhs.GetOptions();
140 SBTypeFormat::operator != (lldb::SBTypeFormat &rhs)
142 if (IsValid() == false)
143 return !rhs.IsValid();
144 return m_opaque_sp != rhs.m_opaque_sp;
147 lldb::TypeFormatImplSP
148 SBTypeFormat::GetSP ()
154 SBTypeFormat::SetSP (const lldb::TypeFormatImplSP &typeformat_impl_sp)
156 m_opaque_sp = typeformat_impl_sp;
159 SBTypeFormat::SBTypeFormat (const lldb::TypeFormatImplSP &typeformat_impl_sp) :
160 m_opaque_sp(typeformat_impl_sp)
165 SBTypeFormat::CopyOnWrite_Impl(Type type)
170 if (m_opaque_sp.unique() &&
171 ((type == Type::eTypeKeepSame) ||
172 (type == Type::eTypeFormat && m_opaque_sp->GetType() == TypeFormatImpl::Type::eTypeFormat) ||
173 (type == Type::eTypeEnum && m_opaque_sp->GetType() == TypeFormatImpl::Type::eTypeEnum))
177 if (type == Type::eTypeKeepSame)
179 if (m_opaque_sp->GetType() == TypeFormatImpl::Type::eTypeFormat)
180 type = Type::eTypeFormat;
182 type = Type::eTypeEnum;
185 if (type == Type::eTypeFormat)
186 SetSP(TypeFormatImplSP(new TypeFormatImpl_Format(GetFormat(),GetOptions())));
188 SetSP(TypeFormatImplSP(new TypeFormatImpl_EnumType(ConstString(GetTypeName()),GetOptions())));