X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Floader%2FParsedSource.h;h=619f2b952283a63009a7e8ed8224d2a5788324a7;hb=4309d259becd96ead792678257e910c03a6b4a3d;hp=e33796aa8601c0560b476972163dd47ec3581863;hpb=2bd2e92a227af66386af1dfca2f52df6941f0f94;p=l2e.git diff --git a/src/loader/ParsedSource.h b/src/loader/ParsedSource.h index e33796a..619f2b9 100644 --- a/src/loader/ParsedSource.h +++ b/src/loader/ParsedSource.h @@ -1,13 +1,12 @@ -/* - * ParsedSource.h - * - * Created on: Aug 26, 2012 - * Author: holy - */ - #ifndef LOADER_PARSEDSOURCE_H_ #define LOADER_PARSEDSOURCE_H_ +namespace loader { + class Literal; + class PropertyList; + class Value; +} + #include #include #include @@ -16,8 +15,39 @@ namespace loader { -class PropertyList; -class Value; +class ScriptToken { + +public: + enum Type { + COMMAND, + REGISTER, + IDENTIFIER, + LITERAL, + LABEL, + }; + + ScriptToken(const std::string &, Type); + explicit ScriptToken(Literal *); + ~ScriptToken(); +private: + ScriptToken(const ScriptToken &); + ScriptToken &operator =(const ScriptToken &); + +public: + Type GetType() const { return type; } + const std::string &RegisterName() const; + const std::string &CommandName() const; + const std::string &Identifier() const; + const std::string &Label() const; + const Literal *GetLiteral() const; + +private: + Literal *literal; + std::string str; + Type type; + +}; + class Literal { @@ -25,29 +55,55 @@ public: enum Type { ARRAY_VALUES, ARRAY_PROPS, + ARRAY_IDENTS, BOOLEAN, COLOR, NUMBER, + PATH, STRING, VECTOR, - OBJECT + OBJECT, + SCRIPT, }; public: + /// array of values explicit Literal(const std::vector &); - explicit Literal(const std::vector &); + /// array of objects + Literal(const std::string &, const std::vector &); + /// array of identifiers + Literal(const std::string &, const std::vector &); + /// boolean explicit Literal(bool); + /// color Literal(int r, int g, int b, int a = 255); + /// number explicit Literal(int number); + /// path string + Literal(const std::string &dir, const std::string &path); + /// string Literal(const std::string &); + /// vector Literal(int x, int y); + /// object Literal(const std::string &typeName, PropertyList *properties); + /// script + explicit Literal(const std::vector &); + ~Literal(); +private: + Literal(const Literal &); + Literal &operator =(const Literal &); public: Type GetType() const { return type; } + bool IsArray() const { return GetType() == ARRAY_VALUES || GetType() == ARRAY_PROPS || GetType() == ARRAY_IDENTS; } + bool IsObject() const { return GetType() == OBJECT; } + int ArraySize() const { return GetType() == ARRAY_VALUES ? GetValues().size() + : (GetType() == ARRAY_PROPS ? GetPropertyLists().size() : GetIdentifiers().size()); } const std::vector &GetValues() const; const std::vector &GetPropertyLists() const; + const std::vector &GetIdentifiers() const; bool GetBoolean() const; int GetRed() const; int GetGreen() const; @@ -59,12 +115,15 @@ public: int GetY() const; const std::string &GetTypeName() const; const PropertyList *GetProperties() const; + const std::vector &GetScript() const; private: PropertyList *props; - std::string str; + std::string typeName, str; std::vector values; std::vector propertyLists; + std::vector identifiers; + std::vector script; int i1, i2, i3, i4; bool b; Type type; @@ -78,7 +137,11 @@ public: explicit Value(const std::string &identifier) : literal(0), identifier(identifier), isLiteral(false) { } explicit Value(Literal *literal) - : literal(literal), isLiteral(false) { } + : literal(literal), isLiteral(true) { } + ~Value(); +private: + Value(const Value &); + Value &operator =(const Value &); public: bool IsLiteral() const { return isLiteral; } @@ -96,7 +159,11 @@ private: class PropertyList { public: + PropertyList() { } ~PropertyList(); +private: + PropertyList(const PropertyList &); + PropertyList &operator =(const PropertyList &); public: void SetProperty(const std::string &name, Value *value) { @@ -122,6 +189,9 @@ public: Declaration(const std::string &typeName, const std::string &identifier) : typeName(typeName), identifier(identifier) { } virtual ~Declaration() { } +private: + Declaration(const Declaration &); + Declaration &operator =(const Declaration &); public: const std::string &TypeName() const { return typeName; } @@ -140,6 +210,10 @@ class Definition public: Definition(const std::string &typeName, const std::string &identifier) : Declaration(typeName, identifier), value(0), isLiteral(false) { } + virtual ~Definition(); +private: + Definition(const Definition &); + Definition &operator =(const Definition &); public: void SetValue(Literal *); @@ -163,7 +237,10 @@ class ParsedSource { public: ParsedSource() { } - ~ParsedSource() { } + ~ParsedSource(); +private: + ParsedSource(const ParsedSource &); + ParsedSource &operator =(const ParsedSource &); public: void AddDeclaration(Declaration *); @@ -182,6 +259,9 @@ public: const std::map &Definitions() const { return definitions; } const std::set &Exports() const { return exports; } +public: + void WriteHeader(std::ostream &) const; + private: std::map declarations; std::map definitions; @@ -199,4 +279,4 @@ ostream &operator <<(ostream &, const loader::Literal &); } -#endif /* LOADER_PARSEDSOURCE_H_ */ +#endif