]> git.localhorst.tv Git - l2e.git/blob - src/loader/Interpreter.h
fixed some issues to get it to compile again
[l2e.git] / src / loader / Interpreter.h
1 /*
2  * Interpreter.h
3  *
4  *  Created on: Aug 26, 2012
5  *      Author: holy
6  */
7
8 #ifndef LOADER_INTERPRETER_H_
9 #define LOADER_INTERPRETER_H_
10
11 #include "TypeDescription.h"
12 #include "../geometry/Vector.h"
13 #include "../graphics/Color.h"
14 #include "../graphics/ComplexAnimation.h"
15
16 #include <map>
17 #include <stdexcept>
18 #include <string>
19 #include <vector>
20 #include <SDL.h>
21
22 namespace battle {
23         class Hero;
24         class Monster;
25         class PartyLayout;
26         struct Resources;
27         class Stats;
28 }
29
30 namespace common {
31         class Ikari;
32         class Item;
33         class Spell;
34         class TargetingMode;
35 }
36
37 namespace graphics {
38         class Animation;
39         class Font;
40         class Frame;
41         class Gauge;
42         struct MenuProperties;
43         class SimpleAnimation;
44         class Sprite;
45 }
46
47 namespace loader {
48
49 class Definition;
50 class ParsedSource;
51 class PropertyList;
52 class Value;
53
54 class Interpreter {
55
56 public:
57         class Error: public std::runtime_error {
58         public:
59                 Error(const std::string &msg) : std::runtime_error("interpreter error: " + msg) { }
60         };
61
62 public:
63         Interpreter(const ParsedSource &source) : source(source) { }
64         ~Interpreter();
65 private:
66         Interpreter(const Interpreter &);
67         Interpreter &operator =(const Interpreter &);
68
69 public:
70         void ReadSource();
71         void *GetObject(int typeId, const std::string &name);
72
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) { }
77                 int type;
78                 int id;
79                 std::ptrdiff_t offset;
80                 const char *identifier;
81                 int linkedType;
82         };
83
84         const std::vector<PostponedDefinition> &PostponedDefinitions() { return postponedDefinitions; }
85
86 private:
87         void ReadDefinition(const Definition &);
88         void ReadLiteral(const Definition &);
89         void ReadObject(const Definition &);
90
91         void *GetObject(int typeId, const Value &value);
92         void ReadObject(int typeId, int id, char *dest, const PropertyList &);
93
94 private:
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;
100                 int type;
101                 int id;
102         };
103         std::map<std::string, ParsedDefinition> parsedDefinitions;
104
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;
108
109         std::map<std::string, SDL_Surface *> imageCache;
110
111         std::map<int, std::vector<void *> > values;
112
113 };
114
115 }
116
117 #endif /* LOADER_INTERPRETER_H_ */