Enrico Granata | 16376ed | 2012-02-15 02:34:21 +0000 | [diff] [blame] | 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 | |
Daniel Malea | d891f9b | 2012-12-05 00:20:57 +0000 | [diff] [blame^] | 10 | #include "lldb/lldb-python.h" |
| 11 | |
Enrico Granata | 16376ed | 2012-02-15 02:34:21 +0000 | [diff] [blame] | 12 | #include "lldb/API/SBTypeFormat.h" |
| 13 | |
| 14 | #include "lldb/API/SBStream.h" |
| 15 | |
| 16 | #include "lldb/Core/DataVisualization.h" |
| 17 | |
| 18 | using namespace lldb; |
| 19 | using namespace lldb_private; |
| 20 | |
| 21 | SBTypeFormat::SBTypeFormat() : |
| 22 | m_opaque_sp() |
| 23 | { |
| 24 | } |
| 25 | |
| 26 | SBTypeFormat::SBTypeFormat (lldb::Format format, |
| 27 | uint32_t options) |
| 28 | : m_opaque_sp(TypeFormatImplSP(new TypeFormatImpl(format,options))) |
| 29 | { |
| 30 | } |
| 31 | |
| 32 | SBTypeFormat::SBTypeFormat (const lldb::SBTypeFormat &rhs) : |
| 33 | m_opaque_sp(rhs.m_opaque_sp) |
| 34 | { |
| 35 | } |
| 36 | |
| 37 | SBTypeFormat::~SBTypeFormat () |
| 38 | { |
| 39 | } |
| 40 | |
| 41 | bool |
| 42 | SBTypeFormat::IsValid() const |
| 43 | { |
| 44 | return m_opaque_sp.get() != NULL; |
| 45 | } |
| 46 | |
| 47 | lldb::Format |
| 48 | SBTypeFormat::GetFormat () |
| 49 | { |
| 50 | if (IsValid()) |
| 51 | return m_opaque_sp->GetFormat(); |
| 52 | return lldb::eFormatInvalid; |
| 53 | } |
| 54 | |
| 55 | uint32_t |
| 56 | SBTypeFormat::GetOptions() |
| 57 | { |
| 58 | if (IsValid()) |
| 59 | return m_opaque_sp->GetOptions(); |
| 60 | return 0; |
| 61 | } |
| 62 | |
| 63 | void |
| 64 | SBTypeFormat::SetFormat (lldb::Format fmt) |
| 65 | { |
| 66 | if (CopyOnWrite_Impl()) |
| 67 | m_opaque_sp->SetFormat(fmt); |
| 68 | } |
| 69 | |
| 70 | void |
| 71 | SBTypeFormat::SetOptions (uint32_t value) |
| 72 | { |
| 73 | if (CopyOnWrite_Impl()) |
| 74 | m_opaque_sp->SetOptions(value); |
| 75 | } |
| 76 | |
| 77 | bool |
| 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 & |
| 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 |
| 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 |
| 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 |
| 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 |
| 129 | SBTypeFormat::GetSP () |
| 130 | { |
| 131 | return m_opaque_sp; |
| 132 | } |
| 133 | |
| 134 | void |
| 135 | SBTypeFormat::SetSP (const lldb::TypeFormatImplSP &typeformat_impl_sp) |
| 136 | { |
| 137 | m_opaque_sp = typeformat_impl_sp; |
| 138 | } |
| 139 | |
| 140 | SBTypeFormat::SBTypeFormat (const lldb::TypeFormatImplSP &typeformat_impl_sp) : |
| 141 | m_opaque_sp(typeformat_impl_sp) |
| 142 | { |
| 143 | } |
| 144 | |
| 145 | bool |
| 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 | } |