#include <lisp.hpp>
Public Types | |
enum | LispType { TYPE_CONS, TYPE_SYMBOL, TYPE_INTEGER, TYPE_STRING, TYPE_REAL, TYPE_BOOLEAN } |
Public Member Functions | |
~Lisp () | |
LispType | get_type () const |
const Lisp * | get_car () const |
const Lisp * | get_cdr () const |
bool | get (std::string &val) const |
std::string | get_symbol () const |
std::string | get_string () const |
bool | get (unsigned int &val) const |
bool | get (int &val) const |
int | get_int () const |
bool | get (float &val) const |
float | get_float () const |
bool | get (bool &val) const |
bool | get_bool () const |
template<class T> | |
bool | get (const char *name, T &val) const |
convenience functions which traverse the list until a child with a specified name is found. | |
template<class T> | |
bool | get (const char *name, std::vector< T > &vec) const |
const Lisp * | get_lisp (const char *name) const |
const Lisp * | get_lisp (const std::string &name) const |
void | print (int indent=0) const |
Private Member Functions | |
Lisp (LispType newtype) | |
Private Attributes | |
LispType | type |
union { | |
struct { | |
const Lisp * car | |
const Lisp * cdr | |
} cons | |
char * string | |
int integer | |
bool boolean | |
float real | |
} | v |
Friends | |
class | Parser |
Definition at line 26 of file lisp.hpp.
enum lisp::Lisp::LispType |
Definition at line 31 of file lisp.hpp.
00031 { 00032 TYPE_CONS, 00033 TYPE_SYMBOL, 00034 TYPE_INTEGER, 00035 TYPE_STRING, 00036 TYPE_REAL, 00037 TYPE_BOOLEAN 00038 };
lisp::Lisp::~Lisp | ( | ) |
lisp::Lisp::Lisp | ( | LispType | newtype | ) | [private] |
LispType lisp::Lisp::get_type | ( | ) | const [inline] |
Definition at line 40 of file lisp.hpp.
References type.
Referenced by get(), lisp::ListIterator::next(), and TileSetParser::parse_tile_images().
00041 { return type; }
const Lisp* lisp::Lisp::get_car | ( | ) | const [inline] |
Definition at line 43 of file lisp.hpp.
References v.
Referenced by ObjectFactory::create(), get(), get_lisp(), lisp::ListIterator::next(), TileSetParser::parse_tile_images(), and lisp::ListIterator::value().
00044 { return v.cons.car; }
const Lisp* lisp::Lisp::get_cdr | ( | ) | const [inline] |
Definition at line 45 of file lisp.hpp.
References v.
Referenced by get(), get_lisp(), lisp::ListIterator::next(), and TileSetParser::parse_tile_images().
00046 { return v.cons.cdr; }
bool lisp::Lisp::get | ( | std::string & | val | ) | const [inline] |
Definition at line 48 of file lisp.hpp.
References type, TYPE_STRING, TYPE_SYMBOL, and v.
Referenced by AmbientSound::AmbientSound(), Background::Background(), BadGuy::BadGuy(), BonusBlock::BonusBlock(), Candle::Candle(), Climbable::Climbable(), Crystallo::Crystallo(), DartTrap::DartTrap(), Decal::Decal(), Dispenser::Dispenser(), Door::Door(), Firefly::Firefly(), Flame::Flame(), get(), TitleScreen::get_level_name(), worldmap::WorldMap::get_level_title(), get_lisp(), Gradient::Gradient(), Haywire::Haywire(), InfoBlock::InfoBlock(), InvisibleWall::InvisibleWall(), Ispy::Ispy(), Kugelblitz::Kugelblitz(), Lantern::Lantern(), worldmap::LevelTile::LevelTile(), LevelTime::LevelTime(), worldmap::WorldMap::load(), World::load(), Config::load(), Level::load(), CameraConfig::load(), load_music_file(), Level::load_old_format(), World::load_state(), Font::loadFontFile(), MagicBlock::MagicBlock(), MovingSprite::MovingSprite(), MrBomb::MrBomb(), lisp::ListIterator::next(), Owl::Owl(), Sector::parse(), Camera::parse(), Addon::parse(), SpriteData::parse_action(), Sector::parse_old_format(), TileSetParser::parse_tile(), TileSetParser::parse_tile_images(), TileSetParser::parse_tiles(), TileManager::parse_tileset_definition(), Platform::Platform(), PowerUp::PowerUp(), PushButton::PushButton(), PlayerStatus::read(), Path::read(), JoystickKeyboardController::read(), AddonManager::read(), reader_get_layer(), ScriptedObject::ScriptedObject(), ScriptTrigger::ScriptTrigger(), SecretAreaTrigger::SecretAreaTrigger(), SequenceTrigger::SequenceTrigger(), ShortFuse::ShortFuse(), SpawnPoint::SpawnPoint(), worldmap::SpecialTile::SpecialTile(), Spotlight::Spotlight(), worldmap::SpriteChange::SpriteChange(), SpriteData::SpriteData(), Switch::Switch(), worldmap::Teleporter::Teleporter(), TextScroller::TextScroller(), Thunderstorm::Thunderstorm(), TileMap::TileMap(), Trampoline::Trampoline(), WillOWisp::WillOWisp(), and Wind::Wind().
00049 { 00050 if(type != TYPE_STRING && type != TYPE_SYMBOL) 00051 return false; 00052 val = v.string; 00053 return true; 00054 }
std::string lisp::Lisp::get_symbol | ( | ) | const [inline] |
Definition at line 56 of file lisp.hpp.
References type, TYPE_SYMBOL, and v.
00057 { 00058 assert(type == TYPE_SYMBOL); 00059 return v.string; 00060 }
std::string lisp::Lisp::get_string | ( | ) | const [inline] |
Definition at line 62 of file lisp.hpp.
References type, TYPE_STRING, and v.
00063 { 00064 assert(type == TYPE_STRING); 00065 return v.string; 00066 }
bool lisp::Lisp::get | ( | unsigned int & | val | ) | const [inline] |
Definition at line 68 of file lisp.hpp.
References type, TYPE_INTEGER, and v.
00069 { 00070 if(type != TYPE_INTEGER) 00071 return false; 00072 val = v.integer; 00073 return true; 00074 }
bool lisp::Lisp::get | ( | int & | val | ) | const [inline] |
Definition at line 76 of file lisp.hpp.
References type, TYPE_INTEGER, and v.
00077 { 00078 if(type != TYPE_INTEGER) 00079 return false; 00080 val = v.integer; 00081 return true; 00082 }
int lisp::Lisp::get_int | ( | ) | const [inline] |
Definition at line 84 of file lisp.hpp.
References type, TYPE_INTEGER, and v.
00085 { 00086 assert(type == TYPE_INTEGER); 00087 return v.integer; 00088 }
bool lisp::Lisp::get | ( | float & | val | ) | const [inline] |
float lisp::Lisp::get_float | ( | ) | const [inline] |
bool lisp::Lisp::get | ( | bool & | val | ) | const [inline] |
Definition at line 109 of file lisp.hpp.
References type, TYPE_BOOLEAN, and v.
00110 { 00111 if(type != TYPE_BOOLEAN) 00112 return false; 00113 val = v.boolean; 00114 return true; 00115 }
bool lisp::Lisp::get_bool | ( | ) | const [inline] |
Definition at line 117 of file lisp.hpp.
References type, TYPE_BOOLEAN, and v.
00118 { 00119 assert(type == TYPE_BOOLEAN); 00120 return v.boolean; 00121 }
bool lisp::Lisp::get | ( | const char * | name, | |
T & | val | |||
) | const [inline] |
convenience functions which traverse the list until a child with a specified name is found.
The value part is then interpreted in a specific way. The functions return true, if a child was found and could be interpreted correctly, otherwise false is returned and the variable value is not changed. (Please note that searching the lisp structure is O(n) so these functions are not a good idea for performance critical areas)
Definition at line 132 of file lisp.hpp.
References get(), get_car(), get_lisp(), get_type(), and TYPE_CONS.
00133 { 00134 const Lisp* lisp = get_lisp(name); 00135 if(!lisp) 00136 return false; 00137 00138 if(lisp->get_type() != TYPE_CONS) 00139 return false; 00140 lisp = lisp->get_car(); 00141 if(!lisp) 00142 return false; 00143 return lisp->get(val); 00144 }
bool lisp::Lisp::get | ( | const char * | name, | |
std::vector< T > & | vec | |||
) | const [inline] |
Definition at line 147 of file lisp.hpp.
References get(), get_car(), get_cdr(), and get_lisp().
00148 { 00149 vec.clear(); 00150 00151 const Lisp* child = get_lisp(name); 00152 if(!child) 00153 return false; 00154 00155 for( ; child != 0; child = child->get_cdr()) { 00156 T val; 00157 if(!child->get_car()) 00158 continue; 00159 if(child->get_car()->get(val)) { 00160 vec.push_back(val); 00161 } 00162 } 00163 00164 return true; 00165 }
const Lisp * lisp::Lisp::get_lisp | ( | const char * | name | ) | const |
Definition at line 35 of file lisp.cpp.
References get(), get_car(), get_cdr(), and TYPE_CONS.
Referenced by AddonManager::check_online(), Coin::Coin(), get(), TitleScreen::get_level_name(), worldmap::WorldMap::get_level_title(), get_lisp(), worldmap::WorldMap::load(), World::load(), Config::load(), SpriteManager::load(), Level::load(), CameraConfig::load(), load_music_file(), World::load_state(), Font::loadFontFile(), TileSetParser::parse(), Camera::parse(), Addon::parse(), Sector::parse_old_format(), TileSetParser::parse_tile(), Platform::Platform(), JoystickKeyboardController::read(), TextScroller::TextScroller(), TileMap::TileMap(), and WillOWisp::WillOWisp().
00036 { 00037 for(const Lisp* p = this; p != 0; p = p->get_cdr()) { 00038 const Lisp* child = p->get_car(); 00039 if(!child || child->get_type() != TYPE_CONS) 00040 continue; 00041 const Lisp* childname = child->get_car(); 00042 if(!childname) 00043 continue; 00044 std::string childName; 00045 if(!childname->get(childName)) 00046 continue; 00047 if(childName == name) { 00048 return child->get_cdr(); 00049 } 00050 } 00051 00052 return 0; 00053 }
const Lisp* lisp::Lisp::get_lisp | ( | const std::string & | name | ) | const [inline] |
Definition at line 168 of file lisp.hpp.
References get_lisp().
00169 { return get_lisp(name.c_str()); }
void lisp::Lisp::print | ( | int | indent = 0 |
) | const |
Definition at line 56 of file lisp.cpp.
References cons, type, TYPE_BOOLEAN, TYPE_CONS, TYPE_INTEGER, TYPE_REAL, TYPE_STRING, TYPE_SYMBOL, and v.
00057 { 00058 for(int i = 0; i < indent; ++i) 00059 printf(" "); 00060 00061 if(type == TYPE_CONS) { 00062 printf("(\n"); 00063 const Lisp* lisp = this; 00064 while(lisp) { 00065 if(lisp->v.cons.car) 00066 lisp->v.cons.car->print(indent + 1); 00067 lisp = lisp->v.cons.cdr; 00068 } 00069 for(int i = 0; i < indent; ++i) 00070 printf(" "); 00071 printf(")"); 00072 } 00073 if(type == TYPE_STRING) { 00074 printf("'%s' ", v.string); 00075 } 00076 if(type == TYPE_INTEGER) { 00077 printf("%d", v.integer); 00078 } 00079 if(type == TYPE_REAL) { 00080 printf("%f", v.real); 00081 } 00082 if(type == TYPE_SYMBOL) { 00083 printf("%s ", v.string); 00084 } 00085 if(type == TYPE_BOOLEAN) { 00086 printf("%s ", v.boolean ? "true" : "false"); 00087 } 00088 printf("\n"); 00089 }
LispType lisp::Lisp::type [private] |
Definition at line 178 of file lisp.hpp.
Referenced by get(), get_bool(), get_float(), get_int(), get_string(), get_symbol(), get_type(), and print().
const Lisp* lisp::Lisp::car [private] |
const Lisp* lisp::Lisp::cdr [private] |
struct { ... } lisp::Lisp::cons [private] |
Referenced by lisp::Parser::parse(), print(), and lisp::Parser::read().
char* lisp::Lisp::string [private] |
int lisp::Lisp::integer [private] |
bool lisp::Lisp::boolean [private] |
float lisp::Lisp::real [private] |
union { ... } lisp::Lisp::v [private] |
Referenced by get(), get_bool(), get_car(), get_cdr(), get_float(), get_int(), get_string(), get_symbol(), lisp::Parser::parse(), print(), and lisp::Parser::read().