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/lldb-python.h"
12 #include "lldb/API/SBTypeFormat.h"
14 #include "lldb/API/SBStream.h"
16 #include "lldb/DataFormatters/DataVisualization.h"
19 using namespace lldb_private;
21 SBTypeFormat::SBTypeFormat() :
26 SBTypeFormat::SBTypeFormat (lldb::Format format,
28 : m_opaque_sp(TypeFormatImplSP(new TypeFormatImpl_Format(format,options)))
32 SBTypeFormat::SBTypeFormat (const char* type,
34 : m_opaque_sp(TypeFormatImplSP(new TypeFormatImpl_EnumType(ConstString(type ? type : ""),options)))
38 SBTypeFormat::SBTypeFormat (const lldb::SBTypeFormat &rhs) :
39 m_opaque_sp(rhs.m_opaque_sp)
43 SBTypeFormat::~SBTypeFormat ()
48 SBTypeFormat::IsValid() const
50 return m_opaque_sp.get() != NULL;
54 SBTypeFormat::GetFormat ()
56 if (IsValid() && m_opaque_sp->GetType() == TypeFormatImpl::Type::eTypeFormat)
57 return ((TypeFormatImpl_Format*)m_opaque_sp.get())->GetFormat();
58 return lldb::eFormatInvalid;
62 SBTypeFormat::GetTypeName ()
64 if (IsValid() && m_opaque_sp->GetType() == TypeFormatImpl::Type::eTypeEnum)
65 return ((TypeFormatImpl_EnumType*)m_opaque_sp.get())->GetTypeName().AsCString("");
70 SBTypeFormat::GetOptions()
73 return m_opaque_sp->GetOptions();
78 SBTypeFormat::SetFormat (lldb::Format fmt)
80 if (CopyOnWrite_Impl(Type::eTypeFormat))
81 ((TypeFormatImpl_Format*)m_opaque_sp.get())->SetFormat(fmt);
85 SBTypeFormat::SetTypeName (const char* type)
87 if (CopyOnWrite_Impl(Type::eTypeEnum))
88 ((TypeFormatImpl_EnumType*)m_opaque_sp.get())->SetTypeName(ConstString(type ? type : ""));
92 SBTypeFormat::SetOptions (uint32_t value)
94 if (CopyOnWrite_Impl(Type::eTypeKeepSame))
95 m_opaque_sp->SetOptions(value);
99 SBTypeFormat::GetDescription (lldb::SBStream &description,
100 lldb::DescriptionLevel description_level)
105 description.Printf("%s\n",
106 m_opaque_sp->GetDescription().c_str());
112 SBTypeFormat::operator = (const lldb::SBTypeFormat &rhs)
116 m_opaque_sp = rhs.m_opaque_sp;
122 SBTypeFormat::operator == (lldb::SBTypeFormat &rhs)
124 if (IsValid() == false)
125 return !rhs.IsValid();
126 return m_opaque_sp == rhs.m_opaque_sp;
130 SBTypeFormat::IsEqualTo (lldb::SBTypeFormat &rhs)
132 if (IsValid() == false)
133 return !rhs.IsValid();
135 if (GetFormat() == rhs.GetFormat())
136 return GetOptions() == rhs.GetOptions();
142 SBTypeFormat::operator != (lldb::SBTypeFormat &rhs)
144 if (IsValid() == false)
145 return !rhs.IsValid();
146 return m_opaque_sp != rhs.m_opaque_sp;
149 lldb::TypeFormatImplSP
150 SBTypeFormat::GetSP ()
156 SBTypeFormat::SetSP (const lldb::TypeFormatImplSP &typeformat_impl_sp)
158 m_opaque_sp = typeformat_impl_sp;
161 SBTypeFormat::SBTypeFormat (const lldb::TypeFormatImplSP &typeformat_impl_sp) :
162 m_opaque_sp(typeformat_impl_sp)
167 SBTypeFormat::CopyOnWrite_Impl(Type type)
172 if (m_opaque_sp.unique() &&
173 ((type == Type::eTypeKeepSame) ||
174 (type == Type::eTypeFormat && m_opaque_sp->GetType() == TypeFormatImpl::Type::eTypeFormat) ||
175 (type == Type::eTypeEnum && m_opaque_sp->GetType() == TypeFormatImpl::Type::eTypeEnum))
179 if (type == Type::eTypeKeepSame)
181 if (m_opaque_sp->GetType() == TypeFormatImpl::Type::eTypeFormat)
182 type = Type::eTypeFormat;
184 type = Type::eTypeEnum;
187 if (type == Type::eTypeFormat)
188 SetSP(TypeFormatImplSP(new TypeFormatImpl_Format(GetFormat(),GetOptions())));
190 SetSP(TypeFormatImplSP(new TypeFormatImpl_EnumType(ConstString(GetTypeName()),GetOptions())));