KiCad PCB EDA Suite
SEXPR::SEXPR_STRING Struct Reference

#include <sexpr.h>

Inheritance diagram for SEXPR::SEXPR_STRING:
SEXPR::SEXPR

Public Member Functions

 SEXPR_STRING (const std::string &aValue)
 
 SEXPR_STRING (const std::string &aValue, int aLineNumber)
 
bool IsList () const
 
bool IsSymbol () const
 
bool IsString () const
 
bool IsDouble () const
 
bool IsInteger () const
 
void AddChild (SEXPR *aChild)
 
SEXPR_VECTOR const * GetChildren () const
 
SEXPRGetChild (size_t aIndex) const
 
size_t GetNumberOfChildren () const
 
int64_t GetLongInteger () const
 
int32_t GetInteger () const
 
float GetFloat () const
 
double GetDouble () const
 
std::string const & GetString () const
 
std::string const & GetSymbol () const
 
SEXPR_LISTGetList ()
 
std::string AsString (size_t aLevel=0) const
 
size_t GetLineNumber () const
 

Public Attributes

std::string m_value
 

Protected Attributes

SEXPR_TYPE m_type
 
size_t m_lineNumber
 

Detailed Description

Definition at line 97 of file sexpr.h.

Constructor & Destructor Documentation

◆ SEXPR_STRING() [1/2]

SEXPR::SEXPR_STRING::SEXPR_STRING ( const std::string &  aValue)
inline

Definition at line 101 of file sexpr.h.

101 :
SEXPR(SEXPR_TYPE aType, size_t aLineNumber)
Definition: sexpr.cpp:28
std::string m_value
Definition: sexpr.h:99

References SEXPR::SEXPR_TYPE_ATOM_STRING.

◆ SEXPR_STRING() [2/2]

SEXPR::SEXPR_STRING::SEXPR_STRING ( const std::string &  aValue,
int  aLineNumber 
)
inline

Definition at line 104 of file sexpr.h.

104 :
105 SEXPR( SEXPR_TYPE::SEXPR_TYPE_ATOM_STRING, aLineNumber ), m_value( aValue ) {};

References SEXPR::SEXPR_TYPE_ATOM_STRING.

Member Function Documentation

◆ AddChild()

void SEXPR::SEXPR::AddChild ( SEXPR aChild)
inherited

Definition at line 58 of file sexpr.cpp.

59 {
61 {
62 throw INVALID_TYPE_EXCEPTION("SEXPR is not a list type!");
63 }
64
65 SEXPR_LIST* list = static_cast< SEXPR_LIST * >( this );
66
67 list->m_children.push_back( aChild );
68 }
SEXPR_TYPE m_type
Definition: sexpr.h:69

References SEXPR::SEXPR_LIST::m_children, and SEXPR::SEXPR_TYPE_LIST.

Referenced by BOOST_AUTO_TEST_CASE(), and SEXPR::SEXPR_LIST::doAddChildren().

◆ AsString()

std::string SEXPR::SEXPR::AsString ( size_t  aLevel = 0) const
inherited

Definition at line 151 of file sexpr.cpp.

152 {
153 std::string result;
154
155 if( IsList() )
156 {
157 if( aLevel != 0 )
158 {
159 result = "\n";
160 }
161
162 result.append( aLevel * 2, ' ' );
163 aLevel++;
164 result += "(";
165
166 SEXPR_VECTOR const* list = GetChildren();
167
168 for( std::vector<SEXPR *>::const_iterator it = list->begin(); it != list->end(); ++it )
169 {
170 result += (*it)->AsString( aLevel );
171
172 if( it != list->end() - 1 )
173 {
174 result += " ";
175 }
176 }
177 result += ")";
178
179 aLevel--;
180 }
181 else if( IsString() )
182 {
183 result += "\"" + GetString() + "\"";
184 }
185 else if( IsSymbol() )
186 {
187 result += GetSymbol();
188 }
189 else if( IsInteger() )
190 {
191 std::stringstream out;
192 out << GetInteger();
193 result += out.str();
194 }
195 else if( IsDouble() )
196 {
197 std::stringstream out;
198 out << std::setprecision( 16 ) << GetDouble();
199 result += out.str();
200 }
201
202 return result;
203 }
SEXPR_VECTOR const * GetChildren() const
Definition: sexpr.cpp:38
bool IsInteger() const
Definition: sexpr.h:53
std::string const & GetSymbol() const
Definition: sexpr.cpp:128
bool IsString() const
Definition: sexpr.h:51
int32_t GetInteger() const
Definition: sexpr.cpp:90
bool IsList() const
Definition: sexpr.h:49
bool IsDouble() const
Definition: sexpr.h:52
bool IsSymbol() const
Definition: sexpr.h:50
std::string const & GetString() const
Definition: sexpr.cpp:80
double GetDouble() const
Definition: sexpr.cpp:105
std::vector< class SEXPR * > SEXPR_VECTOR
Definition: sexpr.h:43

Referenced by BOOST_TEST_PRINT_NAMESPACE_OPEN::print_log_value< SEXPR::SEXPR >::operator()(), and KI_TEST::SexprConvertsToString().

◆ GetChild()

SEXPR * SEXPR::SEXPR::GetChild ( size_t  aIndex) const
inherited

Definition at line 48 of file sexpr.cpp.

49 {
51 {
52 throw INVALID_TYPE_EXCEPTION("SEXPR is not a list type!");
53 }
54
55 return static_cast< SEXPR_LIST const * >(this)->m_children[aIndex];
56 }

References SEXPR::SEXPR_TYPE_LIST.

Referenced by BOOST_AUTO_TEST_CASE(), SEXPR::SEXPR_LIST::doScan(), and traverseSEXPR().

◆ GetChildren()

SEXPR_VECTOR const * SEXPR::SEXPR::GetChildren ( ) const
inherited

Definition at line 38 of file sexpr.cpp.

39 {
41 {
42 throw INVALID_TYPE_EXCEPTION("SEXPR is not a list type!");
43 }
44
45 return &static_cast< SEXPR_LIST const * >(this)->m_children;
46 }

References SEXPR::SEXPR_TYPE_LIST.

◆ GetDouble()

double SEXPR::SEXPR::GetDouble ( ) const
inherited

Definition at line 105 of file sexpr.cpp.

106 {
107 // we may end up parsing "intended" floats/doubles as ints
108 // so here we allow silent casting back to doubles
110 {
111 return static_cast< SEXPR_DOUBLE const * >(this)->m_value;
112 }
114 {
115 return static_cast< SEXPR_INTEGER const * >(this)->m_value;
116 }
117 else
118 {
119 throw INVALID_TYPE_EXCEPTION("SEXPR is not a double type!");
120 }
121 }

References SEXPR::SEXPR_TYPE_ATOM_DOUBLE, and SEXPR::SEXPR_TYPE_ATOM_INTEGER.

Referenced by KI_TEST::SexprIsDoubleWithValue().

◆ GetFloat()

float SEXPR::SEXPR::GetFloat ( ) const
inherited

Definition at line 123 of file sexpr.cpp.

124 {
125 return static_cast< float >( GetDouble() );
126 }

◆ GetInteger()

int32_t SEXPR::SEXPR::GetInteger ( ) const
inherited

Definition at line 90 of file sexpr.cpp.

91 {
92 return static_cast< int >( GetLongInteger() );
93 }
int64_t GetLongInteger() const
Definition: sexpr.cpp:95

◆ GetLineNumber()

size_t SEXPR::SEXPR::GetLineNumber ( ) const
inlineinherited

Definition at line 66 of file sexpr.h.

66{ return m_lineNumber; }
size_t m_lineNumber
Definition: sexpr.h:72

◆ GetList()

SEXPR_LIST * SEXPR::SEXPR::GetList ( )
inherited

Definition at line 141 of file sexpr.cpp.

142 {
144 {
145 throw INVALID_TYPE_EXCEPTION("SEXPR is not a list type!");
146 }
147
148 return static_cast< SEXPR_LIST* >(this);
149 }

References SEXPR::SEXPR_TYPE_LIST.

◆ GetLongInteger()

int64_t SEXPR::SEXPR::GetLongInteger ( ) const
inherited

Definition at line 95 of file sexpr.cpp.

96 {
98 {
99 throw INVALID_TYPE_EXCEPTION("SEXPR is not a integer type!");
100 }
101
102 return static_cast< SEXPR_INTEGER const * >(this)->m_value;
103 }

References SEXPR::SEXPR_TYPE_ATOM_INTEGER.

Referenced by KI_TEST::SexprIsIntegerWithValue().

◆ GetNumberOfChildren()

size_t SEXPR::SEXPR::GetNumberOfChildren ( ) const
inherited

Definition at line 70 of file sexpr.cpp.

71 {
73 {
74 throw INVALID_TYPE_EXCEPTION("SEXPR is not a list type!");
75 }
76
77 return static_cast< SEXPR_LIST const * >(this)->m_children.size();
78 }

References SEXPR::SEXPR_TYPE_LIST.

Referenced by KI_TEST::SexprIsListOfLength(), and traverseSEXPR().

◆ GetString()

std::string const & SEXPR::SEXPR::GetString ( ) const
inherited

Definition at line 80 of file sexpr.cpp.

81 {
83 {
84 throw INVALID_TYPE_EXCEPTION("SEXPR is not a string type!");
85 }
86
87 return static_cast< SEXPR_STRING const * >(this)->m_value;
88 }

References SEXPR::SEXPR_TYPE_ATOM_STRING.

Referenced by KI_TEST::SexprIsStringWithValue().

◆ GetSymbol()

std::string const & SEXPR::SEXPR::GetSymbol ( ) const
inherited

Definition at line 128 of file sexpr.cpp.

129 {
131 {
132 std::string err_msg( "GetSymbol(): SEXPR is not a symbol type! error line ");
133 err_msg += std::to_string( GetLineNumber() );
134 throw INVALID_TYPE_EXCEPTION( err_msg );
135 }
136
137 return static_cast< SEXPR_SYMBOL const * >(this)->m_value;
138 }
size_t GetLineNumber() const
Definition: sexpr.h:66

References SEXPR::SEXPR_TYPE_ATOM_SYMBOL.

Referenced by KI_TEST::SexprIsSymbolWithValue().

◆ IsDouble()

bool SEXPR::SEXPR::IsDouble ( ) const
inlineinherited

Definition at line 52 of file sexpr.h.

References SEXPR::SEXPR_TYPE_ATOM_DOUBLE.

Referenced by KI_TEST::getType().

◆ IsInteger()

bool SEXPR::SEXPR::IsInteger ( ) const
inlineinherited

Definition at line 53 of file sexpr.h.

References SEXPR::SEXPR_TYPE_ATOM_INTEGER.

Referenced by KI_TEST::getType().

◆ IsList()

bool SEXPR::SEXPR::IsList ( ) const
inlineinherited

Definition at line 49 of file sexpr.h.

References SEXPR::SEXPR_TYPE_LIST.

Referenced by KI_TEST::getType(), and traverseSEXPR().

◆ IsString()

bool SEXPR::SEXPR::IsString ( ) const
inlineinherited

Definition at line 51 of file sexpr.h.

References SEXPR::SEXPR_TYPE_ATOM_STRING.

Referenced by KI_TEST::getType().

◆ IsSymbol()

bool SEXPR::SEXPR::IsSymbol ( ) const
inlineinherited

Definition at line 50 of file sexpr.h.

References SEXPR::SEXPR_TYPE_ATOM_SYMBOL.

Referenced by KI_TEST::getType().

Member Data Documentation

◆ m_lineNumber

size_t SEXPR::SEXPR::m_lineNumber
protectedinherited

Definition at line 72 of file sexpr.h.

◆ m_type

SEXPR_TYPE SEXPR::SEXPR::m_type
protectedinherited

Definition at line 69 of file sexpr.h.

◆ m_value

std::string SEXPR::SEXPR_STRING::m_value

Definition at line 99 of file sexpr.h.


The documentation for this struct was generated from the following file: