1 | #ifndef TRAITS_H__ |
1 | #ifndef TRAITS_H__ |
2 | #define TRAITS_H__ |
2 | #define TRAITS_H__ |
3 | |
3 | |
|
|
4 | struct client_container; |
|
|
5 | struct client; |
4 | struct pl; |
6 | struct player; |
5 | struct object; |
7 | struct object; |
6 | struct mapstruct; |
8 | struct maptile; |
7 | struct archt; |
9 | struct archetype; |
8 | struct region; |
10 | struct region; |
9 | struct party; |
11 | struct party; |
10 | struct mapstruct; |
12 | struct treasurelist; |
11 | |
13 | |
12 | // could have used templates, but a more traditional C api |
14 | // could have used templates, but a more traditional C api |
13 | // uses more explicit typing which is ok for this purpose. |
15 | // uses more explicit typing which is ok for this purpose. |
14 | enum data_type |
16 | enum data_type |
15 | { |
17 | { |
… | |
… | |
20 | DT_DOUBLE, |
22 | DT_DOUBLE, |
21 | DT_STRING, // 0-terminated string |
23 | DT_STRING, // 0-terminated string |
22 | DT_DATA, // string + length |
24 | DT_DATA, // string + length |
23 | DT_OBJECT, |
25 | DT_OBJECT, |
24 | DT_MAP, |
26 | DT_MAP, |
|
|
27 | DT_CLIENT, |
25 | DT_PLAYER, |
28 | DT_PLAYER, |
26 | DT_ARCH, |
29 | DT_ARCH, |
27 | DT_PARTY, |
30 | DT_PARTY, |
28 | DT_REGION, |
31 | DT_REGION, |
29 | |
32 | |
… | |
… | |
33 | template<typename T> |
36 | template<typename T> |
34 | struct cftype { }; |
37 | struct cftype { }; |
35 | |
38 | |
36 | template<> |
39 | template<> |
37 | struct cftype<int> { |
40 | struct cftype<int> { |
38 | enum { dt = DT_INT }; |
41 | static const data_type dt = DT_INT; |
39 | }; |
42 | }; |
40 | |
43 | |
41 | template<> |
44 | template<> |
42 | struct cftype<sint64> { |
45 | struct cftype<sint64> { |
43 | enum { dt = DT_INT64 }; |
46 | static const data_type dt = DT_INT64; |
44 | }; |
47 | }; |
45 | |
48 | |
46 | template<> |
49 | template<> |
47 | struct cftype<double> { |
50 | struct cftype<double> { |
48 | enum { dt = DT_DOUBLE }; |
51 | static const data_type dt = DT_DOUBLE; |
49 | }; |
52 | }; |
50 | |
53 | |
51 | template<> |
54 | template<> |
52 | struct cftype<const char *> { |
55 | struct cftype<const char *> { |
53 | enum { dt = DT_STRING }; |
56 | static const data_type dt = DT_STRING; |
54 | }; |
57 | }; |
55 | |
58 | |
56 | template<> |
59 | template<> |
57 | struct cftype<object> { |
60 | struct cftype<object> { |
58 | enum { dt = DT_OBJECT }; |
61 | static const data_type dt = DT_OBJECT; |
59 | }; |
62 | }; |
60 | |
63 | |
61 | template<> |
64 | template<> |
62 | struct cftype<struct pl> { |
65 | struct cftype<client> { |
63 | enum { dt = DT_PLAYER }; |
66 | static const data_type dt = DT_CLIENT; |
64 | }; |
67 | }; |
65 | |
68 | |
66 | template<> |
69 | template<> |
67 | struct cftype<mapstruct> { |
70 | struct cftype<player> { |
68 | enum { dt = DT_MAP }; |
71 | static const data_type dt = DT_PLAYER; |
69 | }; |
72 | }; |
70 | |
73 | |
71 | template<> |
74 | template<> |
|
|
75 | struct cftype<maptile> { |
|
|
76 | static const data_type dt = DT_MAP; |
|
|
77 | }; |
|
|
78 | |
|
|
79 | template<> |
72 | struct cftype<struct archt> { |
80 | struct cftype<archetype> { |
73 | enum { dt = DT_ARCH }; |
81 | static const data_type dt = DT_ARCH; |
74 | }; |
82 | }; |
75 | |
83 | |
76 | template<> |
84 | template<> |
77 | struct cftype<party> { |
85 | struct cftype<party> { |
78 | enum { dt = DT_PARTY }; |
86 | static const data_type dt = DT_PARTY; |
79 | }; |
87 | }; |
80 | |
88 | |
81 | template<> |
89 | template<> |
82 | struct cftype<region> { |
90 | struct cftype<region> { |
83 | enum { dt = DT_REGION }; |
91 | static const data_type dt = DT_REGION; |
|
|
92 | }; |
|
|
93 | |
|
|
94 | template<> |
|
|
95 | struct cftype<treasurelist> { |
|
|
96 | static const data_type dt = DT_REGION; |
84 | }; |
97 | }; |
85 | |
98 | |
86 | #endif |
99 | #endif |
87 | |
100 | |