]> git.localhorst.tv Git - l2e.git/blob - src/loader/Loader.h
c962f206119a9b67f22d11d52b9b58b806004b2e
[l2e.git] / src / loader / Loader.h
1 #ifndef LOADER_LOADER_H_
2 #define LOADER_LOADER_H_
3
4 #include "ObjectFile.h"
5 #include "TypeDescription.h"
6
7 #include <iosfwd>
8 #include <map>
9 #include <string>
10 #include <vector>
11 #include <SDL.h>
12
13 namespace loader {
14
15 class Loader {
16
17 public:
18         Loader() { }
19         ~Loader();
20
21 public:
22         void Load(const std::string &file);
23
24         const std::map<std::string, LoadedExport> &Exports() const { return exports; }
25
26         std::ostream &Dump(std::ostream &) const;
27
28 private:
29         void LoadExports(char *src, Export *begin, Export *end);
30         void LoadExternals(char *src, External *begin, External *end);
31         void LoadImages(char *src, Image *begin, Image *end);
32         void LoadObjects(char *src, Object *begin, Object *end);
33         void LoadObject(char *src, char *dest, const TypeDescription &);
34         void LoadArrays(char *src, Array *begin, Array *end);
35
36         void InitObjects(Object *begin, Object *end);
37         void InitObject(char *object, const TypeDescription &);
38         void InitArrays(Array *begin, Array *end);
39
40         struct MissingExternal {
41                 std::string identifier;
42                 char *dest;
43                 int typeId;
44                 bool inlined;
45         };
46         void LinkExternal(const MissingExternal &, const LoadedExport &);
47
48 private:
49         std::map<std::string, char *> objectFiles;
50         std::map<std::string, LoadedExport> exports;
51         std::map<std::string, SDL_Surface *> images;
52         std::vector<MissingExternal> unlinked;
53
54 };
55
56 }
57
58
59 namespace std {
60
61 inline ostream &operator <<(ostream &o, const loader::Loader &l) {
62         return l.Dump(o);
63 }
64
65 }
66
67 #endif