]> git.localhorst.tv Git - l2e.git/blobdiff - src/loader/ParsedSource.h
removed stupid file headers that eclipse put in
[l2e.git] / src / loader / ParsedSource.h
index f78a49e7b66d402b11b46924ed2595d2c12ee366..b0578a78e548d017f7834d7cd810e889f0992089 100644 (file)
@@ -1,13 +1,8 @@
-/*
- * ParsedSource.h
- *
- *  Created on: Aug 26, 2012
- *      Author: holy
- */
-
 #ifndef LOADER_PARSEDSOURCE_H_
 #define LOADER_PARSEDSOURCE_H_
 
+#include "fwd.h"
+
 #include <iosfwd>
 #include <map>
 #include <set>
 
 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 {
 
+public:
        enum Type {
                ARRAY_VALUES,
                ARRAY_PROPS,
                BOOLEAN,
                COLOR,
                NUMBER,
+               PATH,
                STRING,
                VECTOR,
-               OBJECT
+               OBJECT,
+               SCRIPT,
        };
 
 public:
        explicit Literal(const std::vector<Value *> &);
-       explicit Literal(const std::vector<PropertyList *> &);
+       Literal(const std::string &, const std::vector<PropertyList *> &);
        explicit Literal(bool);
        Literal(int r, int g, int b, int a = 255);
+       explicit Literal(int number);
+       Literal(const std::string &dir, const std::string &path);
        Literal(const std::string &);
        Literal(int x, int y);
        Literal(const std::string &typeName, PropertyList *properties);
+       explicit Literal(const std::vector<ScriptToken *> &);
+       ~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; }
+       bool IsObject() const { return GetType() == OBJECT; }
+       int ArraySize() const { return GetType() == ARRAY_VALUES ? GetValues().size() : GetPropertyLists().size(); }
+
+       const std::vector<Value *> &GetValues() const;
+       const std::vector<PropertyList *> &GetPropertyLists() const;
+       bool GetBoolean() const;
+       int GetRed() const;
+       int GetGreen() const;
+       int GetBlue() const;
+       int GetAlpha() const;
+       int GetNumber() const;
+       const std::string &GetString() const;
+       int GetX() const;
+       int GetY() const;
+       const std::string &GetTypeName() const;
+       const PropertyList *GetProperties() const;
+       const std::vector<ScriptToken *> &GetScript() const;
 
 private:
        PropertyList *props;
-       std::string str;
+       std::string typeName, str;
        std::vector<Value *> values;
        std::vector<PropertyList *> propertyLists;
+       std::vector<ScriptToken *> script;
        int i1, i2, i3, i4;
        bool b;
        Type type;
@@ -59,7 +117,16 @@ 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; }
+       const Literal &GetLiteral() const;
+       const std::string &GetIdentifier() const;
 
 private:
        Literal *literal;
@@ -72,13 +139,24 @@ private:
 class PropertyList {
 
 public:
+       PropertyList() { }
        ~PropertyList();
+private:
+       PropertyList(const PropertyList &);
+       PropertyList &operator =(const PropertyList &);
 
 public:
        void SetProperty(const std::string &name, Value *value) {
                props[name] = value;
        }
 
+       typedef std::map<std::string, Value *>::iterator Iterator;
+       typedef std::map<std::string, Value *>::const_iterator ConstIterator;
+       Iterator Begin() { return props.begin(); }
+       ConstIterator Begin() const { return props.begin(); }
+       Iterator End() { return props.end(); }
+       ConstIterator End() const { return props.end(); }
+
 private:
        std::map<std::string, Value *> props;
 
@@ -91,6 +169,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; }
@@ -109,6 +190,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 *);
@@ -132,18 +217,34 @@ class ParsedSource {
 
 public:
        ParsedSource() { }
-       ~ParsedSource() { }
+       ~ParsedSource();
+private:
+       ParsedSource(const ParsedSource &);
+       ParsedSource &operator =(const ParsedSource &);
 
 public:
        void AddDeclaration(Declaration *);
+       void AddDefinition(Definition *);
        void ExportDeclaration(Declaration *);
        void ExportIdentifier(const std::string &);
 
-       const std::map<std::string, Declaration *> Declarations() const { return declarations; }
-       const std::set<std::string> Exports() const { return exports; }
+       bool IsDeclared(const std::string &) const;
+       Declaration &GetDeclaration(const std::string &);
+       const Declaration &GetDeclaration(const std::string &) const;
+       bool IsDefined(const std::string &) const;
+       Definition &GetDefinition(const std::string &);
+       const Definition &GetDefinition(const std::string &) const;
+
+       const std::map<std::string, Declaration *> &Declarations() const { return declarations; }
+       const std::map<std::string, Definition *> &Definitions() const { return definitions; }
+       const std::set<std::string> &Exports() const { return exports; }
+
+public:
+       void WriteHeader(std::ostream &) const;
 
 private:
        std::map<std::string, Declaration *> declarations;
+       std::map<std::string, Definition *> definitions;
        std::set<std::string> exports;
 
 };
@@ -154,6 +255,7 @@ private:
 namespace std {
 
 ostream &operator <<(ostream &, const loader::ParsedSource &);
+ostream &operator <<(ostream &, const loader::Literal &);
 
 }