4 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 #ifndef __LISPREADER_H__
21 #define __LISPREADER_H__
44 LispType get_type() const
48 { return v.cons.car; }
50 { return v.cons.cdr; }
52 bool get(std::string& val) const
54 if(type != TYPE_STRING && type != TYPE_SYMBOL)
60 std::string get_string() const
62 assert(type == TYPE_STRING);
66 bool get(unsigned int& val) const
68 if(type != TYPE_INTEGER)
74 bool get(int& val) const
76 if(type != TYPE_INTEGER)
84 assert(type == TYPE_INTEGER);
88 bool get(float& val) const
90 if(type != TYPE_REAL) {
91 if(type == TYPE_INTEGER) {
101 float get_float() const
103 assert(type == TYPE_REAL);
107 bool get(bool& val) const
109 if(type != TYPE_BOOLEAN)
115 bool get_bool() const
117 assert(type == TYPE_BOOLEAN);
121 /** conveniance functions which traverse the list until a child with a
122 * specified name is found. The value part is then interpreted in a specific
123 * way. The functions return true, if a child was found and could be
124 * interpreted correctly, otherwise false is returned and the variable value
126 * (Please note that searching the lisp structure is O(n) so these functions
127 * are no good idea for performance critical areas)
130 bool get(const char* name, T& val) const
132 const Lisp* lisp = get_lisp(name);
136 if(lisp->get_type() != TYPE_CONS)
138 lisp = lisp->get_car();
141 return lisp->get(val);
145 bool get_vector(const char* name, std::vector<T>& vec) const
149 const Lisp* child = get_lisp(name);
153 for( ; child != 0; child = child->get_cdr()) {
155 if(!child->get_car())
157 if(child->get_car()->get(val)) {
165 Lisp* get_lisp(const char* name) const;
166 Lisp* get_lisp(const std::string& name) const
167 { return get_lisp(name.c_str()); }
170 void print(int indent = 0) const;
174 Lisp(LispType newtype);
192 } // end of namespace lisp