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