]> git.localhorst.tv Git - l2e.git/blob - src/loader/Interpreter.h
added linkage type and some getters to Interpreter
[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 "ParsedSource.h"
12 #include "TypeDescription.h"
13 #include "../geometry/Vector.h"
14 #include "../graphics/Color.h"
15 #include "../graphics/ComplexAnimation.h"
16
17 #include <map>
18 #include <set>
19 #include <stdexcept>
20 #include <string>
21 #include <vector>
22 #include <SDL.h>
23
24 namespace battle {
25         class Hero;
26         class Monster;
27         class PartyLayout;
28         struct Resources;
29         class Stats;
30 }
31
32 namespace common {
33         class Ikari;
34         class Item;
35         class Spell;
36         class TargetingMode;
37 }
38
39 namespace graphics {
40         class Animation;
41         class Font;
42         class Frame;
43         class Gauge;
44         struct MenuProperties;
45         class SimpleAnimation;
46         class Sprite;
47 }
48
49 namespace loader {
50
51 class Definition;
52 class Literal;
53 class PropertyList;
54 class Value;
55
56 class Interpreter {
57
58 public:
59         class Error: public std::runtime_error {
60         public:
61                 Error(const std::string &msg) : std::runtime_error("interpreter error: " + msg) { }
62         };
63
64 public:
65         Interpreter(const ParsedSource &source) : source(source) { }
66         ~Interpreter();
67 private:
68         Interpreter(const Interpreter &);
69         Interpreter &operator =(const Interpreter &);
70
71 public:
72         void ReadSource();
73         void *GetObject(int typeId, const std::string &name);
74
75         static void CreateTypeDescriptions();
76         struct ParsedDefinition {
77                 ParsedDefinition(const Definition *dfn, int type, int id)
78                 : dfn(dfn), type(type), id(id) { }
79                 const Definition *dfn;
80                 int type;
81                 int id;
82         };
83         struct PostponedDefinition {
84                 PostponedDefinition(int type, int id, std::ptrdiff_t offset, const char *identifier, int linkedType, bool inlined)
85                 : type(type), id(id), offset(offset), identifier(identifier), linkedType(linkedType), inlined(inlined) { }
86                 int type;
87                 int id;
88                 std::ptrdiff_t offset;
89                 const char *identifier;
90                 int linkedType;
91                 bool inlined;
92         };
93
94         const std::set<std::string> &ExportedIdentifiers() const { return source.Exports(); }
95         const ParsedDefinition &GetDefinition(const std::string &identifier) const { return parsedDefinitions.at(identifier); }
96         const std::map<std::string, SDL_Surface *> &Images() const { return imageCache; }
97         const std::vector<PostponedDefinition> &PostponedDefinitions() const { return postponedDefinitions; }
98         const std::map<int, std::vector<void *> > &Values() const { return values; }
99
100 private:
101         void ReadDefinition(const Definition &);
102         void ReadLiteral(const Definition &);
103         void ReadObject(const Definition &);
104
105         void ReadLiteral(int typeId, int id, char *dest, const Literal &);
106         void *GetObject(int typeId, const Value &value);
107         void ReadObject(int typeId, int id, char *dest, const PropertyList &);
108
109         SDL_Surface *GetImage(const std::string &);
110
111         bool CanLink(const Value &) const;
112         void Postpone(int type, int id, std::ptrdiff_t offset, const std::string &identifier, int linkedType, bool inlined);
113
114 private:
115         const ParsedSource &source;
116
117         std::map<std::string, ParsedDefinition> parsedDefinitions;
118         std::vector<PostponedDefinition> postponedDefinitions;
119         std::map<std::string, SDL_Surface *> imageCache;
120         std::map<int, std::vector<void *> > values;
121
122 };
123
124 }
125
126 #endif /* LOADER_INTERPRETER_H_ */