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 18using namespace lldb; 19using namespace lldb_private; 20 21SBTypeFormat::SBTypeFormat() : 22m_opaque_sp() 23{ 24} 25 26SBTypeFormat::SBTypeFormat (lldb::Format format, 27 uint32_t options) 28: m_opaque_sp(TypeFormatImplSP(new TypeFormatImpl(format,options))) 29{ 30} 31 32SBTypeFormat::SBTypeFormat (const lldb::SBTypeFormat &rhs) : 33m_opaque_sp(rhs.m_opaque_sp) 34{ 35} 36 37SBTypeFormat::~SBTypeFormat () 38{ 39} 40 41bool 42SBTypeFormat::IsValid() const 43{ 44 return m_opaque_sp.get() != NULL; 45} 46 47lldb::Format 48SBTypeFormat::GetFormat () 49{ 50 if (IsValid()) 51 return m_opaque_sp->GetFormat(); 52 return lldb::eFormatInvalid; 53} 54 55uint32_t 56SBTypeFormat::GetOptions() 57{ 58 if (IsValid()) 59 return m_opaque_sp->GetOptions(); 60 return 0; 61} 62 63void 64SBTypeFormat::SetFormat (lldb::Format fmt) 65{ 66 if (CopyOnWrite_Impl()) 67 m_opaque_sp->SetFormat(fmt); 68} 69 70void 71SBTypeFormat::SetOptions (uint32_t value) 72{ 73 if (CopyOnWrite_Impl()) 74 m_opaque_sp->SetOptions(value); 75} 76 77bool 78SBTypeFormat::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 90lldb::SBTypeFormat & 91SBTypeFormat::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 100bool 101SBTypeFormat::operator == (lldb::SBTypeFormat &rhs) 102{ 103 if (IsValid() == false) 104 return !rhs.IsValid(); 105 return m_opaque_sp == rhs.m_opaque_sp; 106} 107 108bool 109SBTypeFormat::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 120bool 121SBTypeFormat::operator != (lldb::SBTypeFormat &rhs) 122{ 123 if (IsValid() == false) 124 return !rhs.IsValid(); 125 return m_opaque_sp != rhs.m_opaque_sp; 126} 127 128lldb::TypeFormatImplSP 129SBTypeFormat::GetSP () 130{ 131 return m_opaque_sp; 132} 133 134void 135SBTypeFormat::SetSP (const lldb::TypeFormatImplSP &typeformat_impl_sp) 136{ 137 m_opaque_sp = typeformat_impl_sp; 138} 139 140SBTypeFormat::SBTypeFormat (const lldb::TypeFormatImplSP &typeformat_impl_sp) : 141 m_opaque_sp(typeformat_impl_sp) 142{ 143} 144 145bool 146SBTypeFormat::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