forked from CleverRaven/Cataclysm-DDA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.h
80 lines (67 loc) · 1.58 KB
/
init.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#ifndef _INIT_H_
#define _INIT_H_
#include "json.h"
#include <string>
#include <vector>
//********** Functor Base, Static and Class member accessors
class TFunctor
{
public:
virtual void operator ()(JsonObject &jo) = 0; // virtual () operator
virtual void Call(JsonObject &jo) = 0; // what will be getting called
virtual ~TFunctor() {};
};
class StaticFunctionAccessor : public TFunctor
{
private:
void (*_fptr)(JsonObject &jo);
public:
virtual void operator()(JsonObject &jo)
{
(*_fptr)(jo);
}
virtual void Call(JsonObject &jo)
{
(*_fptr)(jo);
}
StaticFunctionAccessor(void (*fptr)(JsonObject &jo))
{
_fptr = fptr;
}
~StaticFunctionAccessor()
{
_fptr = NULL;
}
};
template <class TClass> class ClassFunctionAccessor : public TFunctor
{
private:
void (TClass::*_fptr)(JsonObject &jo);
TClass *ptr_to_obj;
public:
virtual void operator()(JsonObject &jo)
{
(*ptr_to_obj.*_fptr)(jo);
}
virtual void Call(JsonObject &jo)
{
(*ptr_to_obj.*_fptr)(jo);
}
ClassFunctionAccessor(TClass *ptr2obj, void (TClass::*fptr)(JsonObject &jo))
{
ptr_to_obj = ptr2obj;
_fptr = fptr;
}
~ClassFunctionAccessor()
{
_fptr = NULL;
ptr_to_obj = NULL;
}
};
//********** END - Functor Base, Static and Class member accessors
void load_object(JsonObject &jsobj);
void init_data_structures();
void release_data_structures();
void load_json_dir(std::string const &dirname);
void load_all_from_json(JsonIn &jsin);
#endif // _INIT_H_