X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Floader%2FParsedSource.h;fp=src%2Floader%2FParsedSource.h;h=ebcc853ced570f7728b202f995cc993b8af53792;hb=af9e0b57dac45dc5591f16fb34236b1356cda8a2;hp=0000000000000000000000000000000000000000;hpb=00dafa489224450ccc0321e238c176b9e8aa34bc;p=l2e.git diff --git a/src/loader/ParsedSource.h b/src/loader/ParsedSource.h new file mode 100644 index 0000000..ebcc853 --- /dev/null +++ b/src/loader/ParsedSource.h @@ -0,0 +1,157 @@ +/* + * ParsedSource.h + * + * Created on: Aug 26, 2012 + * Author: holy + */ + +#ifndef LOADER_PARSEDSOURCE_H_ +#define LOADER_PARSEDSOURCE_H_ + +#include +#include +#include +#include +#include + +namespace loader { + +class PropertyList; +class Value; + +class Literal { + + enum Type { + ARRAY, + BOOLEAN, + COLOR, + NUMBER, + STRING, + VECTOR, + OBJECT + }; + +public: + explicit Literal(const std::vector &); + explicit Literal(bool); + Literal(int r, int g, int b, int a = 255); + Literal(const std::string &); + Literal(int x, int y); + Literal(const std::string &typeName, PropertyList *properties); + +private: + PropertyList *props; + std::string str; + std::vector values; + int i1, i2, i3, i4; + bool b; + Type type; + +}; + + +class Value { + +public: + explicit Value(const std::string &identifier) + : literal(0), identifier(identifier), isLiteral(false) { } + explicit Value(Literal *literal) + : literal(literal), isLiteral(false) { } + +private: + Literal *literal; + std::string identifier; + bool isLiteral; + +}; + + +class PropertyList { + +public: + ~PropertyList(); + +public: + void SetProperty(const std::string &name, Value *value) { + props[name] = value; + } + +private: + std::map props; + +}; + + +class Declaration { + +public: + Declaration(const std::string &typeName, const std::string &identifier) + : typeName(typeName), identifier(identifier) { } + virtual ~Declaration() { } + +public: + const std::string &TypeName() const { return typeName; } + const std::string &Identifier() const { return identifier; } + +private: + std::string typeName; + std::string identifier; + +}; + + +class Definition +: public Declaration { + +public: + Definition(const std::string &typeName, const std::string &identifier) + : Declaration(typeName, identifier), value(0), isLiteral(false) { } + +public: + void SetValue(Literal *); + void SetValue(PropertyList *); + + bool HasLiteralValue() const { return isLiteral && value; } + bool HasProperties() const { return !isLiteral && value; } + Literal *GetLiteral(); + const Literal *GetLiteral() const; + PropertyList *GetProperties(); + const PropertyList *GetProperties() const; + +private: + void *value; + bool isLiteral; + +}; + + +class ParsedSource { + +public: + ParsedSource() { } + ~ParsedSource() { } + +public: + void AddDeclaration(Declaration *); + void ExportDeclaration(Declaration *); + void ExportIdentifier(const std::string &); + + const std::map Declarations() const { return declarations; } + const std::set Exports() const { return exports; } + +private: + std::map declarations; + std::set exports; + +}; + +} + + +namespace std { + +ostream &operator <<(ostream &, const loader::ParsedSource &); + +} + +#endif /* LOADER_PARSEDSOURCE_H_ */