4 * Created on: Aug 26, 2012
8 #ifndef LOADER_PARSEDSOURCE_H_
9 #define LOADER_PARSEDSOURCE_H_
38 explicit Literal(const std::vector<Value *> &);
39 explicit Literal(const std::vector<PropertyList *> &);
40 explicit Literal(bool);
41 Literal(int r, int g, int b, int a = 255);
42 explicit Literal(int number);
43 Literal(const std::string &dir, const std::string &path);
44 Literal(const std::string &);
45 Literal(int x, int y);
46 Literal(const std::string &typeName, PropertyList *properties);
49 Literal(const Literal &);
50 Literal &operator =(const Literal &);
53 Type GetType() const { return type; }
55 const std::vector<Value *> &GetValues() const;
56 const std::vector<PropertyList *> &GetPropertyLists() const;
57 bool GetBoolean() const;
62 int GetNumber() const;
63 const std::string &GetString() const;
66 const std::string &GetTypeName() const;
67 const PropertyList *GetProperties() const;
72 std::vector<Value *> values;
73 std::vector<PropertyList *> propertyLists;
84 explicit Value(const std::string &identifier)
85 : literal(0), identifier(identifier), isLiteral(false) { }
86 explicit Value(Literal *literal)
87 : literal(literal), isLiteral(true) { }
91 Value &operator =(const Value &);
94 bool IsLiteral() const { return isLiteral; }
95 const Literal &GetLiteral() const;
96 const std::string &GetIdentifier() const;
100 std::string identifier;
112 PropertyList(const PropertyList &);
113 PropertyList &operator =(const PropertyList &);
116 void SetProperty(const std::string &name, Value *value) {
120 typedef std::map<std::string, Value *>::iterator Iterator;
121 typedef std::map<std::string, Value *>::const_iterator ConstIterator;
122 Iterator Begin() { return props.begin(); }
123 ConstIterator Begin() const { return props.begin(); }
124 Iterator End() { return props.end(); }
125 ConstIterator End() const { return props.end(); }
128 std::map<std::string, Value *> props;
136 Declaration(const std::string &typeName, const std::string &identifier)
137 : typeName(typeName), identifier(identifier) { }
138 virtual ~Declaration() { }
140 Declaration(const Declaration &);
141 Declaration &operator =(const Declaration &);
144 const std::string &TypeName() const { return typeName; }
145 const std::string &Identifier() const { return identifier; }
148 std::string typeName;
149 std::string identifier;
155 : public Declaration {
158 Definition(const std::string &typeName, const std::string &identifier)
159 : Declaration(typeName, identifier), value(0), isLiteral(false) { }
160 virtual ~Definition();
162 Definition(const Definition &);
163 Definition &operator =(const Definition &);
166 void SetValue(Literal *);
167 void SetValue(PropertyList *);
169 bool HasLiteralValue() const { return isLiteral && value; }
170 bool HasProperties() const { return !isLiteral && value; }
171 Literal *GetLiteral();
172 const Literal *GetLiteral() const;
173 PropertyList *GetProperties();
174 const PropertyList *GetProperties() const;
189 ParsedSource(const ParsedSource &);
190 ParsedSource &operator =(const ParsedSource &);
193 void AddDeclaration(Declaration *);
194 void AddDefinition(Definition *);
195 void ExportDeclaration(Declaration *);
196 void ExportIdentifier(const std::string &);
198 bool IsDeclared(const std::string &) const;
199 Declaration &GetDeclaration(const std::string &);
200 const Declaration &GetDeclaration(const std::string &) const;
201 bool IsDefined(const std::string &) const;
202 Definition &GetDefinition(const std::string &);
203 const Definition &GetDefinition(const std::string &) const;
205 const std::map<std::string, Declaration *> &Declarations() const { return declarations; }
206 const std::map<std::string, Definition *> &Definitions() const { return definitions; }
207 const std::set<std::string> &Exports() const { return exports; }
210 std::map<std::string, Declaration *> declarations;
211 std::map<std::string, Definition *> definitions;
212 std::set<std::string> exports;
221 ostream &operator <<(ostream &, const loader::ParsedSource &);
222 ostream &operator <<(ostream &, const loader::Literal &);
226 #endif /* LOADER_PARSEDSOURCE_H_ */