KiCad PCB EDA Suite
SEXPR::SEXPR Class Reference

#include <sexpr.h>

Inheritance diagram for SEXPR::SEXPR:
SEXPR::SEXPR_DOUBLE SEXPR::SEXPR_INTEGER SEXPR::SEXPR_LIST SEXPR::SEXPR_STRING SEXPR::SEXPR_SYMBOL

Public Member Functions

virtual ~SEXPR ()
 
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 ()
 

Protected Member Functions

 SEXPR (SEXPR_TYPE aType, size_t aLineNumber)
 
 SEXPR (SEXPR_TYPE aType)
 

Protected Attributes

SEXPR_TYPE m_type
 
size_t m_lineNumber
 

Detailed Description

Definition at line 44 of file sexpr.h.

Constructor & Destructor Documentation

◆ SEXPR() [1/2]

SEXPR::SEXPR::SEXPR ( SEXPR_TYPE  aType,
size_t  aLineNumber 
)
protected

Definition at line 27 of file sexpr.cpp.

27  :
28  m_type( aType ), m_lineNumber( aLineNumber )
29  {
30  }
size_t m_lineNumber
Definition: sexpr.h:50
SEXPR_TYPE m_type
Definition: sexpr.h:47

◆ SEXPR() [2/2]

SEXPR::SEXPR::SEXPR ( SEXPR_TYPE  aType)
protected

Definition at line 32 of file sexpr.cpp.

32  :
33  m_type( aType ), m_lineNumber( 1 )
34  {
35  }
size_t m_lineNumber
Definition: sexpr.h:50
SEXPR_TYPE m_type
Definition: sexpr.h:47

◆ ~SEXPR()

virtual SEXPR::SEXPR::~SEXPR ( )
inlinevirtual

Definition at line 53 of file sexpr.h.

53 {};

Member Function Documentation

◆ AddChild()

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

Definition at line 57 of file sexpr.cpp.

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

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

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

◆ AsString()

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

Definition at line 148 of file sexpr.cpp.

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

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

Definition at line 47 of file sexpr.cpp.

48  {
50  {
51  throw INVALID_TYPE_EXCEPTION("SEXPR is not a list type!");
52  }
53 
54  return static_cast< SEXPR_LIST const * >(this)->m_children[aIndex];
55  }
SEXPR_TYPE m_type
Definition: sexpr.h:47

References SEXPR::SEXPR_TYPE_LIST.

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

◆ GetChildren()

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

Definition at line 37 of file sexpr.cpp.

38  {
40  {
41  throw INVALID_TYPE_EXCEPTION("SEXPR is not a list type!");
42  }
43 
44  return &static_cast< SEXPR_LIST const * >(this)->m_children;
45  }
SEXPR_TYPE m_type
Definition: sexpr.h:47

References SEXPR::SEXPR_TYPE_LIST.

◆ GetDouble()

double SEXPR::SEXPR::GetDouble ( ) const

Definition at line 104 of file sexpr.cpp.

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

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

Referenced by KI_TEST::SexprIsDoubleWithValue().

◆ GetFloat()

float SEXPR::SEXPR::GetFloat ( ) const

Definition at line 122 of file sexpr.cpp.

123  {
124  return static_cast< float >( GetDouble() );
125  }
double GetDouble() const
Definition: sexpr.cpp:104

◆ GetInteger()

int32_t SEXPR::SEXPR::GetInteger ( ) const

Definition at line 89 of file sexpr.cpp.

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

◆ GetLineNumber()

size_t SEXPR::SEXPR::GetLineNumber ( )
inline

Definition at line 71 of file sexpr.h.

71 { return m_lineNumber; }
size_t m_lineNumber
Definition: sexpr.h:50

◆ GetList()

SEXPR_LIST * SEXPR::SEXPR::GetList ( )

Definition at line 138 of file sexpr.cpp.

139  {
141  {
142  throw INVALID_TYPE_EXCEPTION("SEXPR is not a list type!");
143  }
144 
145  return static_cast< SEXPR_LIST* >(this);
146  }
SEXPR_TYPE m_type
Definition: sexpr.h:47

References SEXPR::SEXPR_TYPE_LIST.

◆ GetLongInteger()

int64_t SEXPR::SEXPR::GetLongInteger ( ) const

Definition at line 94 of file sexpr.cpp.

95  {
97  {
98  throw INVALID_TYPE_EXCEPTION("SEXPR is not a integer type!");
99  }
100 
101  return static_cast< SEXPR_INTEGER const * >(this)->m_value;
102  }
SEXPR_TYPE m_type
Definition: sexpr.h:47

References SEXPR::SEXPR_TYPE_ATOM_INTEGER.

Referenced by KI_TEST::SexprIsIntegerWithValue().

◆ GetNumberOfChildren()

size_t SEXPR::SEXPR::GetNumberOfChildren ( ) const

Definition at line 69 of file sexpr.cpp.

70  {
72  {
73  throw INVALID_TYPE_EXCEPTION("SEXPR is not a list type!");
74  }
75 
76  return static_cast< SEXPR_LIST const * >(this)->m_children.size();
77  }
SEXPR_TYPE m_type
Definition: sexpr.h:47

References SEXPR::SEXPR_TYPE_LIST.

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

◆ GetString()

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

Definition at line 79 of file sexpr.cpp.

80  {
82  {
83  throw INVALID_TYPE_EXCEPTION("SEXPR is not a string type!");
84  }
85 
86  return static_cast< SEXPR_STRING const * >(this)->m_value;
87  }
SEXPR_TYPE m_type
Definition: sexpr.h:47

References SEXPR::SEXPR_TYPE_ATOM_STRING.

Referenced by KI_TEST::SexprIsStringWithValue().

◆ GetSymbol()

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

Definition at line 127 of file sexpr.cpp.

128  {
130  {
131  throw INVALID_TYPE_EXCEPTION("SEXPR is not a symbol type!");
132  }
133 
134  return static_cast< SEXPR_SYMBOL const * >(this)->m_value;
135  }
SEXPR_TYPE m_type
Definition: sexpr.h:47

References SEXPR::SEXPR_TYPE_ATOM_SYMBOL.

Referenced by KI_TEST::SexprIsSymbolWithValue().

◆ IsDouble()

bool SEXPR::SEXPR::IsDouble ( ) const
inline

◆ IsInteger()

bool SEXPR::SEXPR::IsInteger ( ) const
inline

◆ IsList()

bool SEXPR::SEXPR::IsList ( ) const
inline

Definition at line 54 of file sexpr.h.

References SEXPR::SEXPR_TYPE_LIST.

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

◆ IsString()

bool SEXPR::SEXPR::IsString ( ) const
inline

◆ IsSymbol()

bool SEXPR::SEXPR::IsSymbol ( ) const
inline

Member Data Documentation

◆ m_lineNumber

size_t SEXPR::SEXPR::m_lineNumber
protected

Definition at line 50 of file sexpr.h.

◆ m_type

SEXPR_TYPE SEXPR::SEXPR::m_type
protected

Definition at line 47 of file sexpr.h.


The documentation for this class was generated from the following files: