Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

AssociativeArray Class Reference

#include <parser.h>

List of all members.

Public Member Functions

void addValue (string, Value &)
 AssociativeArray ()
bool getBoolean (const std::string &, bool &) const
bool getColor (const std::string &, Color &) const
bool getNumber (const std::string &, int &) const
bool getNumber (const std::string &, float &) const
bool getNumber (const std::string &, double &) const
bool getRotation (const std::string &, Quatf &) const
bool getString (const std::string &, std::string &) const
ValuegetValue (string) const
bool getVector (const std::string &, Vec3f &) const
bool getVector (const std::string &, Vec3d &) const
 ~AssociativeArray ()

Private Attributes

map< string, Value * > assoc


Constructor & Destructor Documentation

AssociativeArray::AssociativeArray  ) 
 

Definition at line 238 of file parser.cpp.

00239 {
00240 }

AssociativeArray::~AssociativeArray  ) 
 

Definition at line 242 of file parser.cpp.

References assoc.

00243 {
00244 #if 0
00245     Hash::iterator iter = data.h->begin();
00246     while (iter != data.h->end())
00247     {
00248         delete iter->second;
00249         iter++;
00250     }
00251 #endif
00252     for (map<string, Value*>::iterator iter = assoc.begin(); iter != assoc.end(); iter++)
00253         delete iter->second;
00254 }


Member Function Documentation

void AssociativeArray::addValue string  ,
Value
 

Definition at line 265 of file parser.cpp.

References assoc.

Referenced by Parser::readHash().

00266 {
00267     assoc.insert(map<string, Value*>::value_type(key, &val));
00268 }

bool AssociativeArray::getBoolean const std::string ,
bool & 
const
 

Definition at line 322 of file parser.cpp.

References Value::getBoolean(), Value::getType(), and getValue().

Referenced by ReadCelestiaConfig(), and ReadFavoritesList().

00323 {
00324     Value* v = getValue(key);
00325     if (v == NULL || v->getType() != Value::BooleanType)
00326         return false;
00327 
00328     val = v->getBoolean();
00329 
00330     return true;
00331 }

bool AssociativeArray::getColor const std::string ,
Color
const
 

Definition at line 401 of file parser.cpp.

References getVector(), Vector3< T >::x, Vector3< T >::y, and Vector3< T >::z.

Referenced by CreatePlanet().

00402 {
00403     Vec3d vecVal;
00404 
00405     if (!getVector(key, vecVal))
00406         return false;
00407 
00408     val = Color((float) vecVal.x, (float) vecVal.y, (float) vecVal.z);
00409 
00410     return true;
00411 }

bool AssociativeArray::getNumber const std::string ,
int & 
const
 

Definition at line 296 of file parser.cpp.

References getNumber().

00297 {
00298     double ival;
00299 
00300     if (!getNumber(key, ival))
00301     {
00302         return false;
00303     }
00304     else
00305     {
00306         val = (int) ival;
00307         return true;
00308     }
00309 }

bool AssociativeArray::getNumber const std::string ,
float & 
const
 

Definition at line 281 of file parser.cpp.

References getNumber().

00282 {
00283     double dval;
00284 
00285     if (!getNumber(key, dval))
00286     {
00287         return false;
00288     }
00289     else
00290     {
00291         val = (float) dval;
00292         return true;
00293     }
00294 }

bool AssociativeArray::getNumber const std::string ,
double & 
const
 

Definition at line 270 of file parser.cpp.

References Value::getNumber(), Value::getType(), and getValue().

Referenced by CreatePlanet(), getNumber(), LoadCelestiaMesh(), CommandParser::parseCommand(), ReadCelestiaConfig(), ReadDestinationList(), and ReadFavoritesList().

00271 {
00272     Value* v = getValue(key);
00273     if (v == NULL || v->getType() != Value::NumberType)
00274         return false;
00275 
00276     val = v->getNumber();
00277 
00278     return true;
00279 }

bool AssociativeArray::getRotation const std::string ,
Quatf
const
 

Definition at line 370 of file parser.cpp.

References degToRad(), Value::getArray(), Value::getNumber(), Value::getType(), and getValue().

00371 {
00372     Value* v = getValue(key);
00373     if (v == NULL || v->getType() != Value::ArrayType)
00374         return false;
00375 
00376     Array* arr = v->getArray();
00377     if (arr->size() != 4)
00378         return false;
00379 
00380     Value* w = (*arr)[0];
00381     Value* x = (*arr)[1];
00382     Value* y = (*arr)[2];
00383     Value* z = (*arr)[3];
00384 
00385     if (w->getType() != Value::NumberType ||
00386         x->getType() != Value::NumberType ||
00387         y->getType() != Value::NumberType ||
00388         z->getType() != Value::NumberType)
00389         return false;
00390 
00391     Vec3f axis((float) x->getNumber(),
00392                (float) y->getNumber(),
00393                (float) z->getNumber());
00394     axis.normalize();
00395     float angle = degToRad((float) w->getNumber());
00396     val.setAxisAngle(axis, angle);
00397 
00398     return true;
00399 }

bool AssociativeArray::getString const std::string ,
std::string
const
 

Definition at line 311 of file parser.cpp.

References Value::getString(), Value::getType(), and getValue().

Referenced by CreatePlanet(), CommandParser::parseCommand(), ReadCelestiaConfig(), ReadDestinationList(), and ReadFavoritesList().

00312 {
00313     Value* v = getValue(key);
00314     if (v == NULL || v->getType() != Value::StringType)
00315         return false;
00316 
00317     val = v->getString();
00318 
00319     return true;
00320 }

Value * AssociativeArray::getValue string   )  const
 

Definition at line 256 of file parser.cpp.

References assoc.

Referenced by getBoolean(), getNumber(), getRotation(), getString(), getVector(), and ReadCelestiaConfig().

00257 {
00258     map<string, Value*>::const_iterator iter = assoc.find(key);
00259     if (iter == assoc.end())
00260         return NULL;
00261     else
00262         return iter->second;
00263 }

bool AssociativeArray::getVector const std::string ,
Vec3f
const
 

Definition at line 357 of file parser.cpp.

References getVector(), Vector3< T >::x, Vector3< T >::y, and Vector3< T >::z.

00358 {
00359     Vec3d vecVal;
00360 
00361     if (!getVector(key, vecVal))
00362         return false;
00363 
00364     val = Vec3f((float) vecVal.x, (float) vecVal.y, (float) vecVal.z);
00365 
00366     return true;
00367 }

bool AssociativeArray::getVector const std::string ,
Vec3d
const
 

Definition at line 333 of file parser.cpp.

References Value::getArray(), Value::getNumber(), Value::getType(), and getValue().

Referenced by getColor(), getVector(), LoadCelestiaMesh(), CommandParser::parseCommand(), and ReadFavoritesList().

00334 {
00335     Value* v = getValue(key);
00336     if (v == NULL || v->getType() != Value::ArrayType)
00337         return false;
00338 
00339     Array* arr = v->getArray();
00340     if (arr->size() != 3)
00341         return false;
00342 
00343     Value* x = (*arr)[0];
00344     Value* y = (*arr)[1];
00345     Value* z = (*arr)[2];
00346 
00347     if (x->getType() != Value::NumberType ||
00348         y->getType() != Value::NumberType ||
00349         z->getType() != Value::NumberType)
00350         return false;
00351 
00352     val = Vec3d(x->getNumber(), y->getNumber(), z->getNumber());
00353 
00354     return true;
00355 }


Member Data Documentation

map<string, Value*> AssociativeArray::assoc [private]
 

Definition at line 42 of file parser.h.

Referenced by addValue(), getValue(), and ~AssociativeArray().


The documentation for this class was generated from the following files:
Generated on Sat Jan 14 22:33:06 2006 for Celestia by  doxygen 1.4.1