4 * Created on: Aug 26, 2012
8 #ifndef LOADER_INTERPRETER_H_
9 #define LOADER_INTERPRETER_H_
11 #include "TypeDescription.h"
12 #include "../geometry/Vector.h"
13 #include "../graphics/Color.h"
14 #include "../graphics/ComplexAnimation.h"
42 struct MenuProperties;
43 class SimpleAnimation;
58 class Error: public std::runtime_error {
60 Error(const std::string &msg) : std::runtime_error("interpreter error: " + msg) { }
64 Interpreter(const ParsedSource &source) : source(source) { }
67 Interpreter(const Interpreter &);
68 Interpreter &operator =(const Interpreter &);
72 void *GetObject(int typeId, const std::string &name);
74 static void CreateTypeDescriptions();
75 struct PostponedDefinition {
76 PostponedDefinition(int type, int id, std::ptrdiff_t offset, const char *identifier, int linkedType)
77 : type(type), id(id), offset(offset), identifier(identifier), linkedType(linkedType) { }
80 std::ptrdiff_t offset;
81 const char *identifier;
85 const std::vector<PostponedDefinition> &PostponedDefinitions() { return postponedDefinitions; }
88 void ReadDefinition(const Definition &);
89 void ReadLiteral(const Definition &);
90 void ReadObject(const Definition &);
92 void ReadLiteral(int typeId, int id, char *dest, const Literal &);
93 void *GetObject(int typeId, const Value &value);
94 void ReadObject(int typeId, int id, char *dest, const PropertyList &);
97 const ParsedSource &source;
98 struct ParsedDefinition {
99 ParsedDefinition(const Definition *dfn, int type, int id)
100 : dfn(dfn), type(type), id(id) { }
101 const Definition *dfn;
105 std::map<std::string, ParsedDefinition> parsedDefinitions;
107 bool CanLink(const Value &) const;
108 void Postpone(int type, int id, std::ptrdiff_t offset, const std::string &identifier, int linkedType);
109 std::vector<PostponedDefinition> postponedDefinitions;
111 std::map<std::string, SDL_Surface *> imageCache;
113 std::map<int, std::vector<void *> > values;
119 #endif /* LOADER_INTERPRETER_H_ */