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; }
54 bool IsArray() const { return GetType() == ARRAY_VALUES || GetType() == ARRAY_PROPS; }
55 bool IsObject() const { return GetType() == OBJECT; }
56 int ArraySize() const { return GetType() == ARRAY_VALUES ? GetValues().size() : GetPropertyLists().size(); }
58 const std::vector<Value *> &GetValues() const;
59 const std::vector<PropertyList *> &GetPropertyLists() const;
60 bool GetBoolean() const;
65 int GetNumber() const;
66 const std::string &GetString() const;
69 const std::string &GetTypeName() const;
70 const PropertyList *GetProperties() const;
75 std::vector<Value *> values;
76 std::vector<PropertyList *> propertyLists;
87 explicit Value(const std::string &identifier)
88 : literal(0), identifier(identifier), isLiteral(false) { }
89 explicit Value(Literal *literal)
90 : literal(literal), isLiteral(true) { }
94 Value &operator =(const Value &);
97 bool IsLiteral() const { return isLiteral; }
98 const Literal &GetLiteral() const;
99 const std::string &GetIdentifier() const;
103 std::string identifier;
115 PropertyList(const PropertyList &);
116 PropertyList &operator =(const PropertyList &);
119 void SetProperty(const std::string &name, Value *value) {
123 typedef std::map<std::string, Value *>::iterator Iterator;
124 typedef std::map<std::string, Value *>::const_iterator ConstIterator;
125 Iterator Begin() { return props.begin(); }
126 ConstIterator Begin() const { return props.begin(); }
127 Iterator End() { return props.end(); }
128 ConstIterator End() const { return props.end(); }
131 std::map<std::string, Value *> props;
139 Declaration(const std::string &typeName, const std::string &identifier)
140 : typeName(typeName), identifier(identifier) { }
141 virtual ~Declaration() { }
143 Declaration(const Declaration &);
144 Declaration &operator =(const Declaration &);
147 const std::string &TypeName() const { return typeName; }
148 const std::string &Identifier() const { return identifier; }
151 std::string typeName;
152 std::string identifier;
158 : public Declaration {
161 Definition(const std::string &typeName, const std::string &identifier)
162 : Declaration(typeName, identifier), value(0), isLiteral(false) { }
163 virtual ~Definition();
165 Definition(const Definition &);
166 Definition &operator =(const Definition &);
169 void SetValue(Literal *);
170 void SetValue(PropertyList *);
172 bool HasLiteralValue() const { return isLiteral && value; }
173 bool HasProperties() const { return !isLiteral && value; }
174 Literal *GetLiteral();
175 const Literal *GetLiteral() const;
176 PropertyList *GetProperties();
177 const PropertyList *GetProperties() const;
192 ParsedSource(const ParsedSource &);
193 ParsedSource &operator =(const ParsedSource &);
196 void AddDeclaration(Declaration *);
197 void AddDefinition(Definition *);
198 void ExportDeclaration(Declaration *);
199 void ExportIdentifier(const std::string &);
201 bool IsDeclared(const std::string &) const;
202 Declaration &GetDeclaration(const std::string &);
203 const Declaration &GetDeclaration(const std::string &) const;
204 bool IsDefined(const std::string &) const;
205 Definition &GetDefinition(const std::string &);
206 const Definition &GetDefinition(const std::string &) const;
208 const std::map<std::string, Declaration *> &Declarations() const { return declarations; }
209 const std::map<std::string, Definition *> &Definitions() const { return definitions; }
210 const std::set<std::string> &Exports() const { return exports; }
213 void WriteHeader(std::ostream &) const;
216 std::map<std::string, Declaration *> declarations;
217 std::map<std::string, Definition *> definitions;
218 std::set<std::string> exports;
227 ostream &operator <<(ostream &, const loader::ParsedSource &);
228 ostream &operator <<(ostream &, const loader::Literal &);
232 #endif /* LOADER_PARSEDSOURCE_H_ */