4 * Created on: Aug 26, 2012
8 #ifndef LOADER_PARSEDSOURCE_H_
9 #define LOADER_PARSEDSOURCE_H_
37 explicit Literal(const std::vector<Value *> &);
38 Literal(const std::string &, const std::vector<PropertyList *> &);
39 explicit Literal(bool);
40 Literal(int r, int g, int b, int a = 255);
41 explicit Literal(int number);
42 Literal(const std::string &dir, const std::string &path);
43 Literal(const std::string &);
44 Literal(int x, int y);
45 Literal(const std::string &typeName, PropertyList *properties);
48 Literal(const Literal &);
49 Literal &operator =(const Literal &);
52 Type GetType() const { return type; }
53 bool IsArray() const { return GetType() == ARRAY_VALUES || GetType() == ARRAY_PROPS; }
54 bool IsObject() const { return GetType() == OBJECT; }
55 int ArraySize() const { return GetType() == ARRAY_VALUES ? GetValues().size() : GetPropertyLists().size(); }
57 const std::vector<Value *> &GetValues() const;
58 const std::vector<PropertyList *> &GetPropertyLists() const;
59 bool GetBoolean() const;
64 int GetNumber() const;
65 const std::string &GetString() const;
68 const std::string &GetTypeName() const;
69 const PropertyList *GetProperties() const;
73 std::string typeName, str;
74 std::vector<Value *> values;
75 std::vector<PropertyList *> propertyLists;
86 explicit Value(const std::string &identifier)
87 : literal(0), identifier(identifier), isLiteral(false) { }
88 explicit Value(Literal *literal)
89 : literal(literal), isLiteral(true) { }
93 Value &operator =(const Value &);
96 bool IsLiteral() const { return isLiteral; }
97 const Literal &GetLiteral() const;
98 const std::string &GetIdentifier() const;
102 std::string identifier;
114 PropertyList(const PropertyList &);
115 PropertyList &operator =(const PropertyList &);
118 void SetProperty(const std::string &name, Value *value) {
122 typedef std::map<std::string, Value *>::iterator Iterator;
123 typedef std::map<std::string, Value *>::const_iterator ConstIterator;
124 Iterator Begin() { return props.begin(); }
125 ConstIterator Begin() const { return props.begin(); }
126 Iterator End() { return props.end(); }
127 ConstIterator End() const { return props.end(); }
130 std::map<std::string, Value *> props;
138 Declaration(const std::string &typeName, const std::string &identifier)
139 : typeName(typeName), identifier(identifier) { }
140 virtual ~Declaration() { }
142 Declaration(const Declaration &);
143 Declaration &operator =(const Declaration &);
146 const std::string &TypeName() const { return typeName; }
147 const std::string &Identifier() const { return identifier; }
150 std::string typeName;
151 std::string identifier;
157 : public Declaration {
160 Definition(const std::string &typeName, const std::string &identifier)
161 : Declaration(typeName, identifier), value(0), isLiteral(false) { }
162 virtual ~Definition();
164 Definition(const Definition &);
165 Definition &operator =(const Definition &);
168 void SetValue(Literal *);
169 void SetValue(PropertyList *);
171 bool HasLiteralValue() const { return isLiteral && value; }
172 bool HasProperties() const { return !isLiteral && value; }
173 Literal *GetLiteral();
174 const Literal *GetLiteral() const;
175 PropertyList *GetProperties();
176 const PropertyList *GetProperties() const;
191 ParsedSource(const ParsedSource &);
192 ParsedSource &operator =(const ParsedSource &);
195 void AddDeclaration(Declaration *);
196 void AddDefinition(Definition *);
197 void ExportDeclaration(Declaration *);
198 void ExportIdentifier(const std::string &);
200 bool IsDeclared(const std::string &) const;
201 Declaration &GetDeclaration(const std::string &);
202 const Declaration &GetDeclaration(const std::string &) const;
203 bool IsDefined(const std::string &) const;
204 Definition &GetDefinition(const std::string &);
205 const Definition &GetDefinition(const std::string &) const;
207 const std::map<std::string, Declaration *> &Declarations() const { return declarations; }
208 const std::map<std::string, Definition *> &Definitions() const { return definitions; }
209 const std::set<std::string> &Exports() const { return exports; }
212 void WriteHeader(std::ostream &) const;
215 std::map<std::string, Declaration *> declarations;
216 std::map<std::string, Definition *> definitions;
217 std::set<std::string> exports;
226 ostream &operator <<(ostream &, const loader::ParsedSource &);
227 ostream &operator <<(ostream &, const loader::Literal &);
231 #endif /* LOADER_PARSEDSOURCE_H_ */