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;
57 class Error: public std::runtime_error {
59 Error(const std::string &msg) : std::runtime_error("interpreter error: " + msg) { }
63 Interpreter(const ParsedSource &source) : source(source) { }
66 Interpreter(const Interpreter &);
67 Interpreter &operator =(const Interpreter &);
71 void *GetObject(int typeId, const std::string &name);
73 static void CreateTypeDescriptions();
74 struct PostponedDefinition {
75 PostponedDefinition(int type, int id, std::ptrdiff_t offset, const char *identifier, int linkedType)
76 : type(type), id(id), offset(offset), identifier(identifier), linkedType(linkedType) { }
79 std::ptrdiff_t offset;
80 const char *identifier;
84 const std::vector<PostponedDefinition> &PostponedDefinitions() { return postponedDefinitions; }
87 void ReadDefinition(const Definition &);
88 void ReadLiteral(const Definition &);
89 void ReadObject(const Definition &);
91 void *GetObject(int typeId, const Value &value);
92 void ReadObject(int typeId, int id, char *dest, const PropertyList &);
95 const ParsedSource &source;
96 struct ParsedDefinition {
97 ParsedDefinition(const Definition *dfn, int type, int id)
98 : dfn(dfn), type(type), id(id) { }
99 const Definition *dfn;
103 std::map<std::string, ParsedDefinition> parsedDefinitions;
105 bool CanLink(const Value &) const;
106 void Postpone(int type, int id, std::ptrdiff_t offset, const std::string &identifier, int linkedType);
107 std::vector<PostponedDefinition> postponedDefinitions;
109 std::map<std::string, SDL_Surface *> imageCache;
111 std::map<int, std::vector<void *> > values;
117 #endif /* LOADER_INTERPRETER_H_ */