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

parser.h

Go to the documentation of this file.
00001 // parser.h
00002 //
00003 // Copyright (C) 2001 Chris Laurel <claurel@shatters.net>
00004 //
00005 // This program is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU General Public License
00007 // as published by the Free Software Foundation; either version 2
00008 // of the License, or (at your option) any later version.
00009 
00010 #ifndef _PARSER_H_
00011 #define _PARSER_H_
00012 
00013 #include <vector>
00014 #include <map>
00015 #include <celmath/vecmath.h>
00016 #include <celmath/quaternion.h>
00017 #include <celutil/color.h>
00018 #include <celengine/tokenizer.h>
00019 
00020 class Value;
00021 
00022 class AssociativeArray
00023 {
00024  public:
00025     AssociativeArray();
00026     ~AssociativeArray();
00027 
00028     Value* getValue(string) const;
00029     void addValue(string, Value&);
00030 
00031     bool getNumber(const std::string&, double&) const;
00032     bool getNumber(const std::string&, float&) const;
00033     bool getNumber(const std::string&, int&) const;
00034     bool getString(const std::string&, std::string&) const;
00035     bool getBoolean(const std::string&, bool&) const;
00036     bool getVector(const std::string&, Vec3d&) const;
00037     bool getVector(const std::string&, Vec3f&) const;
00038     bool getRotation(const std::string&, Quatf&) const;
00039     bool getColor(const std::string&, Color&) const;
00040     
00041  private:
00042     map<string, Value*> assoc;
00043 };
00044 
00045 typedef vector<Value*> Array;
00046 typedef AssociativeArray Hash;
00047 
00048 class Value
00049 {
00050 public:
00051     enum ValueType {
00052         NumberType     = 0,
00053         StringType     = 1,
00054         ArrayType      = 2,
00055         HashType       = 3,
00056         BooleanType    = 4
00057     };
00058 
00059     Value(double);
00060     Value(string);
00061     Value(Array*);
00062     Value(Hash*);
00063     Value(bool);
00064     ~Value();
00065 
00066     ValueType getType() const;
00067 
00068     double getNumber() const;
00069     string getString() const;
00070     Array* getArray() const;
00071     Hash* getHash() const;
00072     bool getBoolean() const;
00073 
00074 private:
00075     ValueType type;
00076 
00077     union {
00078         string* s;
00079         double d;
00080         Array* a;
00081         Hash* h;
00082     } data;
00083 };
00084 
00085 
00086 class Parser
00087 {
00088 public:
00089     Parser(Tokenizer*);
00090 
00091     Array* readArray();
00092     Hash* readHash();
00093     Value* readValue();
00094 
00095 private:
00096     Tokenizer* tokenizer;
00097 };
00098 
00099 #endif // _PARSER_H_

Generated on Sat Jan 14 22:30:28 2006 for Celestia by  doxygen 1.4.1