24 #include "sexpr/isexprable.h"
25 #include "sexpr/sexpr_exception.h"
33 enum class SEXPR_TYPE : char
36 SEXPR_TYPE_ATOM_INTEGER,
37 SEXPR_TYPE_ATOM_DOUBLE,
38 SEXPR_TYPE_ATOM_STRING,
39 SEXPR_TYPE_ATOM_SYMBOL,
42 typedef std::vector< class SEXPR * > SEXPR_VECTOR;
48 SEXPR( SEXPR_TYPE aType,
size_t aLineNumber );
49 SEXPR( SEXPR_TYPE aType );
54 bool IsList()
const {
return m_type == SEXPR_TYPE::SEXPR_TYPE_LIST; }
55 bool IsSymbol()
const {
return m_type == SEXPR_TYPE::SEXPR_TYPE_ATOM_SYMBOL; }
56 bool IsString()
const {
return m_type == SEXPR_TYPE::SEXPR_TYPE_ATOM_STRING; }
57 bool IsDouble()
const {
return m_type == SEXPR_TYPE::SEXPR_TYPE_ATOM_DOUBLE; }
58 bool IsInteger()
const {
return m_type == SEXPR_TYPE::SEXPR_TYPE_ATOM_INTEGER; }
59 void AddChild(
SEXPR* aChild );
60 SEXPR_VECTOR
const * GetChildren()
const;
61 SEXPR * GetChild(
size_t aIndex )
const;
62 size_t GetNumberOfChildren()
const;
65 float GetFloat()
const;
66 double GetDouble()
const;
67 std::string
const & GetString()
const;
68 std::string
const & GetSymbol()
const;
70 std::string AsString(
size_t aLevel = 0);
71 size_t GetLineNumber() {
return m_lineNumber; }
79 SEXPR( SEXPR_TYPE::SEXPR_TYPE_ATOM_INTEGER ), m_value( aValue ) {};
82 SEXPR( SEXPR_TYPE::SEXPR_TYPE_ATOM_INTEGER, aLineNumber ), m_value( aValue ) {};
90 SEXPR( SEXPR_TYPE::SEXPR_TYPE_ATOM_DOUBLE ), m_value( aValue ) {};
93 SEXPR( SEXPR_TYPE::SEXPR_TYPE_ATOM_DOUBLE, aLineNumber ), m_value( aValue ) {};
101 SEXPR( SEXPR_TYPE::SEXPR_TYPE_ATOM_STRING ), m_value(aValue) {};
104 SEXPR( SEXPR_TYPE::SEXPR_TYPE_ATOM_STRING, aLineNumber ), m_value( aValue ) {};
112 SEXPR( SEXPR_TYPE::SEXPR_TYPE_ATOM_SYMBOL ), m_value( aValue ) {};
115 SEXPR( SEXPR_TYPE::SEXPR_TYPE_ATOM_SYMBOL, aLineNumber ), m_value( aValue ) {};
121 const std::string& _String;
124 inline _OUT_STRING AsSymbol(
const std::string& aString )
130 inline _OUT_STRING AsString(
const std::string& aString )
132 struct _OUT_STRING ret = {
false, aString };
139 std::string& _String;
142 inline _IN_STRING AsSymbol( std::string& aString )
148 inline _IN_STRING AsString( std::string& aString )
150 struct _IN_STRING ret = {
false, aString };
160 type( Type::INT ) { u.int_value = aValue; }
163 type( Type::LONGINT ) { u.lint_value = aValue; }
166 type( Type::DOUBLE ) { u.dbl_value = aValue; }
169 type( Type::STRING ) { u.str_value = aValue; }
172 type( Type::SEXPR_STRING ) { u.sexpr_str = &aValue; }
175 type( Type::STRING_COMP ) { str_value = *aValue; }
178 type( Type::STRING_COMP ) { str_value = aValue; }
181 type( Type::STRING_COMP ) { str_value = aValue; }
184 enum class Type : char { INT, DOUBLE, STRING, LONGINT, STRING_COMP,
SEXPR_STRING };
192 std::string* str_value;
196 std::string str_value;
205 type( Type::INT ) { u.int_value = aValue; }
208 type( Type::LONGINT ) { u.lint_value = aValue; }
211 type( Type::DOUBLE ) { u.dbl_value = aValue; }
214 type( Type::STRING ) { str_value = aValue; }
217 type( Type::STRING ) { str_value = aValue; }
220 type( Type::SEXPR_STRING ) { str_value = aValue._String; u.symbol = aValue._Symbol; }
223 type( Type::SEXPR_ATOM ) { u.sexpr_ptr = aPointer; }
226 enum class Type : char { INT, DOUBLE, STRING, LONGINT,
SEXPR_STRING, SEXPR_ATOM };
238 std::string str_value;
244 SEXPR_LIST() :
SEXPR( SEXPR_TYPE::SEXPR_TYPE_LIST ), m_inStreamChild( 0 ) {};
247 SEXPR( SEXPR_TYPE::SEXPR_TYPE_LIST, aLineNumber), m_inStreamChild( 0 ) {};
249 template <
typename... Args>
251 SEXPR( SEXPR_TYPE::SEXPR_TYPE_LIST ), m_inStreamChild( 0 )
253 AddChildren(args...);
256 SEXPR_VECTOR m_children;
258 template <
typename... Args>
259 size_t Scan(
const Args&... args )
262 return doScan( arg_array,
sizeof...( Args ) );
265 template <
typename... Args>
266 void AddChildren(
const Args&... args )
269 doAddChildren( arg_array,
sizeof...( Args ) );