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