3 // TuxKart - a fun racing game with go-kart
4 // Copyright (C) 2004 Matthias Braun <matze@braunis.de>
5 // code in this file based on lispreader from Mark Probst
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 #ifndef __LISPREADER_H__
21 #define __LISPREADER_H__
43 LispType get_type() const
47 { return v.cons.car; }
49 { return v.cons.cdr; }
51 bool get(std::string& val) const
53 if(type != TYPE_STRING && type != TYPE_SYMBOL)
59 std::string get_string() const
61 assert(type == TYPE_STRING);
65 bool get(unsigned int& val) const
67 if(type != TYPE_INTEGER)
73 bool get(int& val) const
75 if(type != TYPE_INTEGER)
83 assert(type == TYPE_INTEGER);
87 bool get(float& val) const
89 if(type != TYPE_REAL) {
90 if(type == TYPE_INTEGER) {
100 float get_float() const
102 assert(type == TYPE_REAL);
106 bool get(bool& val) const
108 if(type != TYPE_BOOLEAN)
114 bool get_bool() const
116 assert(type == TYPE_BOOLEAN);
120 /** conveniance functions which traverse the list until a child with a
121 * specified name is found. The value part is then interpreted in a specific
122 * way. The functions return true, if a child was found and could be
123 * interpreted correctly, otherwise false is returned and the variable value
125 * (Please note that searching the lisp structure is O(n) so these functions
126 * are no good idea for performance critical areas)
129 bool get(const char* name, T& val) const
131 const Lisp* lisp = get_lisp(name);
135 if(lisp->get_type() != TYPE_CONS)
137 lisp = lisp->get_car();
140 return lisp->get(val);
144 bool get_vector(const char* name, std::vector<T>& vec) const
148 const Lisp* child = get_lisp(name);
152 for( ; child != 0; child = child->get_cdr()) {
154 if(!child->get_car())
156 if(child->get_car()->get(val)) {
164 Lisp* get_lisp(const char* name) const;
165 Lisp* get_lisp(const std::string& name) const
166 { return get_lisp(name.c_str()); }
169 void print(int indent = 0) const;
173 Lisp(LispType newtype);
191 } // end of namespace lisp