• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===-- SBTypeFormat.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/lldb-python.h"
11 
12 #include "lldb/API/SBTypeFormat.h"
13 
14 #include "lldb/API/SBStream.h"
15 
16 #include "lldb/DataFormatters/DataVisualization.h"
17 
18 using namespace lldb;
19 using namespace lldb_private;
20 
SBTypeFormat()21 SBTypeFormat::SBTypeFormat() :
22 m_opaque_sp()
23 {
24 }
25 
SBTypeFormat(lldb::Format format,uint32_t options)26 SBTypeFormat::SBTypeFormat (lldb::Format format,
27                             uint32_t options)
28 : m_opaque_sp(TypeFormatImplSP(new TypeFormatImpl(format,options)))
29 {
30 }
31 
SBTypeFormat(const lldb::SBTypeFormat & rhs)32 SBTypeFormat::SBTypeFormat (const lldb::SBTypeFormat &rhs) :
33 m_opaque_sp(rhs.m_opaque_sp)
34 {
35 }
36 
~SBTypeFormat()37 SBTypeFormat::~SBTypeFormat ()
38 {
39 }
40 
41 bool
IsValid() const42 SBTypeFormat::IsValid() const
43 {
44     return m_opaque_sp.get() != NULL;
45 }
46 
47 lldb::Format
GetFormat()48 SBTypeFormat::GetFormat ()
49 {
50     if (IsValid())
51         return m_opaque_sp->GetFormat();
52     return lldb::eFormatInvalid;
53 }
54 
55 uint32_t
GetOptions()56 SBTypeFormat::GetOptions()
57 {
58     if (IsValid())
59         return m_opaque_sp->GetOptions();
60     return 0;
61 }
62 
63 void
SetFormat(lldb::Format fmt)64 SBTypeFormat::SetFormat (lldb::Format fmt)
65 {
66     if (CopyOnWrite_Impl())
67         m_opaque_sp->SetFormat(fmt);
68 }
69 
70 void
SetOptions(uint32_t value)71 SBTypeFormat::SetOptions (uint32_t value)
72 {
73     if (CopyOnWrite_Impl())
74         m_opaque_sp->SetOptions(value);
75 }
76 
77 bool
GetDescription(lldb::SBStream & description,lldb::DescriptionLevel description_level)78 SBTypeFormat::GetDescription (lldb::SBStream &description,
79                               lldb::DescriptionLevel description_level)
80 {
81     if (!IsValid())
82         return false;
83     else {
84         description.Printf("%s\n",
85                            m_opaque_sp->GetDescription().c_str());
86         return true;
87     }
88 }
89 
90 lldb::SBTypeFormat &
operator =(const lldb::SBTypeFormat & rhs)91 SBTypeFormat::operator = (const lldb::SBTypeFormat &rhs)
92 {
93     if (this != &rhs)
94     {
95         m_opaque_sp = rhs.m_opaque_sp;
96     }
97     return *this;
98 }
99 
100 bool
operator ==(lldb::SBTypeFormat & rhs)101 SBTypeFormat::operator == (lldb::SBTypeFormat &rhs)
102 {
103     if (IsValid() == false)
104         return !rhs.IsValid();
105     return m_opaque_sp == rhs.m_opaque_sp;
106 }
107 
108 bool
IsEqualTo(lldb::SBTypeFormat & rhs)109 SBTypeFormat::IsEqualTo (lldb::SBTypeFormat &rhs)
110 {
111     if (IsValid() == false)
112         return !rhs.IsValid();
113 
114     if (GetFormat() == rhs.GetFormat())
115         return GetOptions() == rhs.GetOptions();
116     else
117         return false;
118 }
119 
120 bool
operator !=(lldb::SBTypeFormat & rhs)121 SBTypeFormat::operator != (lldb::SBTypeFormat &rhs)
122 {
123     if (IsValid() == false)
124         return !rhs.IsValid();
125     return m_opaque_sp != rhs.m_opaque_sp;
126 }
127 
128 lldb::TypeFormatImplSP
GetSP()129 SBTypeFormat::GetSP ()
130 {
131     return m_opaque_sp;
132 }
133 
134 void
SetSP(const lldb::TypeFormatImplSP & typeformat_impl_sp)135 SBTypeFormat::SetSP (const lldb::TypeFormatImplSP &typeformat_impl_sp)
136 {
137     m_opaque_sp = typeformat_impl_sp;
138 }
139 
SBTypeFormat(const lldb::TypeFormatImplSP & typeformat_impl_sp)140 SBTypeFormat::SBTypeFormat (const lldb::TypeFormatImplSP &typeformat_impl_sp) :
141     m_opaque_sp(typeformat_impl_sp)
142 {
143 }
144 
145 bool
CopyOnWrite_Impl()146 SBTypeFormat::CopyOnWrite_Impl()
147 {
148     if (!IsValid())
149         return false;
150     if (m_opaque_sp.unique())
151         return true;
152 
153     SetSP(TypeFormatImplSP(new TypeFormatImpl(GetFormat(),GetOptions())));
154     return true;
155 }
156