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
47 const Lisp* get_car() const
48 { return v.cons.car; }
49 const Lisp* get_cdr() const
50 { return v.cons.cdr; }
52 bool get(std::string& val) const
54 if(type != TYPE_STRING && type != TYPE_SYMBOL)
60 std::string get_symbol() const
62 assert(type == TYPE_SYMBOL);
66 std::string get_string() const
68 assert(type == TYPE_STRING);
72 bool get(unsigned int& val) const
74 if(type != TYPE_INTEGER)
80 bool get(int& val) const
82 if(type != TYPE_INTEGER)
90 assert(type == TYPE_INTEGER);
94 bool get(float& val) const
96 if(type != TYPE_REAL) {
97 if(type == TYPE_INTEGER) {
98 val = (float) v.integer;
107 float get_float() const
109 assert(type == TYPE_REAL);
113 bool get(bool& val) const
115 if(type != TYPE_BOOLEAN)
121 bool get_bool() const
123 assert(type == TYPE_BOOLEAN);
127 /** conveniance functions which traverse the list until a child with a
128 * specified name is found. The value part is then interpreted in a specific
129 * way. The functions return true, if a child was found and could be
130 * interpreted correctly, otherwise false is returned and the variable value
132 * (Please note that searching the lisp structure is O(n) so these functions
133 * are no good idea for performance critical areas)
136 bool get(const char* name, T& val) const
138 const Lisp* lisp = get_lisp(name);
142 if(lisp->get_type() != TYPE_CONS)
144 lisp = lisp->get_car();
147 return lisp->get(val);
151 bool get_vector(const char* name, std::vector<T>& vec) const
155 const Lisp* child = get_lisp(name);
159 for( ; child != 0; child = child->get_cdr()) {
161 if(!child->get_car())
163 if(child->get_car()->get(val)) {
171 const Lisp* get_lisp(const char* name) const;
172 const Lisp* get_lisp(const std::string& name) const
173 { return get_lisp(name.c_str()); }
176 void print(int indent = 0) const;
180 Lisp(LispType newtype);
198 } // end of namespace lisp