1 //===-- SBTypeNameSpecifier.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/API/SBTypeNameSpecifier.h"
11 
12 #include "lldb/API/SBStream.h"
13 
14 #include "lldb/Core/DataVisualization.h"
15 
16 using namespace lldb;
17 using namespace lldb_private;
18 
19 SBTypeNameSpecifier::SBTypeNameSpecifier() :
20 m_opaque_sp()
21 {
22 }
23 
24 SBTypeNameSpecifier::SBTypeNameSpecifier (const char* name,
25                                           bool is_regex) :
26 m_opaque_sp(new TypeNameSpecifierImpl(name, is_regex))
27 {
28     if (name == NULL || (*name) == 0)
29         m_opaque_sp.reset();
30 }
31 
32 SBTypeNameSpecifier::SBTypeNameSpecifier (const lldb::SBTypeNameSpecifier &rhs) :
33 m_opaque_sp(rhs.m_opaque_sp)
34 {}
35 
36 SBTypeNameSpecifier::~SBTypeNameSpecifier ()
37 {
38 }
39 
40 bool
41 SBTypeNameSpecifier::IsValid() const
42 {
43     return m_opaque_sp.get() != NULL;
44 }
45 
46 const char*
47 SBTypeNameSpecifier::GetName ()
48 {
49     if (!IsValid())
50         return NULL;
51 
52     return m_opaque_sp->GetName();
53 }
54 
55 bool
56 SBTypeNameSpecifier::IsRegex ()
57 {
58     if (!IsValid())
59         return false;
60 
61     return m_opaque_sp->IsRegex();
62 }
63 
64 bool
65 SBTypeNameSpecifier::GetDescription (lldb::SBStream &description,
66                                      lldb::DescriptionLevel description_level)
67 {
68     if (!IsValid())
69         return false;
70     description.Printf("SBTypeNameSpecifier(%s,%s)", GetName(), IsRegex() ? "regex" : "plain");
71     return true;
72 }
73 
74 lldb::SBTypeNameSpecifier &
75 SBTypeNameSpecifier::operator = (const lldb::SBTypeNameSpecifier &rhs)
76 {
77     if (this != &rhs)
78     {
79         m_opaque_sp = rhs.m_opaque_sp;
80     }
81     return *this;
82 }
83 
84 bool
85 SBTypeNameSpecifier::operator == (lldb::SBTypeNameSpecifier &rhs)
86 {
87     if (IsValid() == false)
88         return !rhs.IsValid();
89     return m_opaque_sp == rhs.m_opaque_sp;
90 }
91 
92 bool
93 SBTypeNameSpecifier::IsEqualTo (lldb::SBTypeNameSpecifier &rhs)
94 {
95     if (IsValid() == false)
96         return !rhs.IsValid();
97 
98     if (IsRegex() != rhs.IsRegex())
99         return false;
100 
101     return (strcmp(GetName(), rhs.GetName()) == 0);
102 }
103 
104 bool
105 SBTypeNameSpecifier::operator != (lldb::SBTypeNameSpecifier &rhs)
106 {
107     if (IsValid() == false)
108         return !rhs.IsValid();
109     return m_opaque_sp != rhs.m_opaque_sp;
110 }
111 
112 lldb::TypeNameSpecifierImplSP
113 SBTypeNameSpecifier::GetSP ()
114 {
115     return m_opaque_sp;
116 }
117 
118 void
119 SBTypeNameSpecifier::SetSP (const lldb::TypeNameSpecifierImplSP &type_namespec_sp)
120 {
121     m_opaque_sp = type_namespec_sp;
122 }
123 
124 SBTypeNameSpecifier::SBTypeNameSpecifier (const lldb::TypeNameSpecifierImplSP &type_namespec_sp) :
125 m_opaque_sp(type_namespec_sp)
126 {
127 }
128