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