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; }
50 bool get(std::string& val) const
52 if(type != TYPE_STRING && type != TYPE_SYMBOL)
57 bool get(unsigned int& val) const
59 if(type != TYPE_INTEGER)
64 bool get(int& val) const
66 if(type != TYPE_INTEGER)
71 bool get(float& val) const
73 if(type != TYPE_REAL) {
74 if(type == TYPE_INTEGER) {
83 bool get(bool& val) const
85 if(type != TYPE_BOOLEAN)
91 /** conveniance functions which traverse the list until a child with a
92 * specified name is found. The value part is then interpreted in a specific
93 * way. The functions return true, if a child was found and could be
94 * interpreted correctly, otherwise false is returned and the variable value
96 * (Please note that searching the lisp structure is O(n) so these functions
97 * are no good idea for performance critical areas)
100 bool get(const char* name, T& val) const
102 const Lisp* lisp = get_lisp(name);
106 if(lisp->get_type() != TYPE_CONS)
108 lisp = lisp->get_car();
111 return lisp->get(val);
115 bool get_vector(const char* name, std::vector<T>& vec) const
119 const Lisp* child = get_lisp(name);
123 for( ; child != 0; child = child->get_cdr()) {
125 if(!child->get_car())
127 if(child->get_car()->get(val)) {
135 Lisp* get_lisp(const char* name) const;
136 Lisp* get_lisp(const std::string& name) const
137 { return get_lisp(name.c_str()); }
140 void print(int indent = 0) const;
144 Lisp(LispType newtype);
162 } // end of namespace lisp