… | |
… | |
61 | #define ARG_REGION(o) DT_REGION, (void *)static_cast<struct region *> (o) |
61 | #define ARG_REGION(o) DT_REGION, (void *)static_cast<struct region *> (o) |
62 | |
62 | |
63 | // the ", ## __VA_ARGS" is, unfortunately, a gnu-cpp extension |
63 | // the ", ## __VA_ARGS" is, unfortunately, a gnu-cpp extension |
64 | |
64 | |
65 | // all these return true when the normal event processing should be skipped (if any) |
65 | // all these return true when the normal event processing should be skipped (if any) |
66 | #define INVOKE(klass, event, ...) cfperl_invoke (EVENT_ ## klass ## _ ## event, ## __VA_ARGS__, DT_END) |
66 | #define INVOKE_(event, ...) cfperl_invoke (event, ## __VA_ARGS__, DT_END) |
67 | |
67 | |
|
|
68 | #define INVOKE(klass, event, ...) INVOKE_(EVENT_ ## klass ## _ ## event, ## __VA_ARGS__) |
68 | #define INVOKE_GLOBAL(event, ...) INVOKE (GLOBAL, event, ## __VA_ARGS__) |
69 | #define INVOKE_GLOBAL(event, ...) INVOKE_(EVENT_ ## GLOBAL ## _ ## event, ## __VA_ARGS__) |
69 | #define INVOKE_OBJECT(event, op, ...) INVOKE (OBJECT, event, ARG_OBJECT (op), ## __VA_ARGS__) |
70 | #define INVOKE_OBJECT(event, op, ...) INVOKE_(EVENT_ ## OBJECT ## _ ## event, ARG_OBJECT (op), ## __VA_ARGS__) |
70 | #define INVOKE_PLAYER(event, pl, ...) INVOKE (PLAYER, event, ARG_PLAYER (pl), ## __VA_ARGS__) |
71 | #define INVOKE_PLAYER(event, pl, ...) INVOKE_(EVENT_ ## PLAYER ## _ ## event, ARG_PLAYER (pl), ## __VA_ARGS__) |
71 | #define INVOKE_MAP(event, map, ...) INVOKE (MAP , event, ARG_MAP (map) , ## __VA_ARGS__) |
72 | #define INVOKE_MAP(event, map, ...) INVOKE_(EVENT_ ## MAP ## _ ## event, ARG_MAP (map) , ## __VA_ARGS__) |
72 | |
73 | |
73 | //TODO should index into @result |
74 | //TODO should index into @result |
74 | #define RESULT(idx,type) cfperl_result_ ## type (idx) |
75 | #define RESULT(idx,type) cfperl_result_ ## type (idx) |
75 | #define RESULT_INT(idx) RESULT(idx, INT) |
76 | #define RESULT_INT(idx) RESULT(idx, INT) |
76 | |
77 | |
77 | bool cfperl_invoke (event_type event, ...); |
78 | bool cfperl_invoke (event_type event, ...); |
78 | int cfperl_result_INT (int idx); |
79 | int cfperl_result_INT (int idx); |
79 | |
80 | |
80 | struct extendable_base |
81 | struct attachable_base |
81 | { |
82 | { |
82 | void *self, *cb; // CF+ perl self and callback |
83 | void *self, *cb; // CF+ perl self and callback |
83 | const char *attach; // generic extension attachment information |
84 | const char *attach; // generic extension attachment information |
84 | |
85 | |
85 | void clear (); // called when free'ing objects |
86 | void clear (); // called when free'ing objects |
86 | void optimise (); // possibly save some memory by destroying unneeded data |
87 | void optimise (); // possibly save some memory by destroying unneeded data |
87 | |
88 | |
88 | void extendable_init () |
89 | void attachable_init () |
89 | { |
90 | { |
90 | self = cb = 0; |
91 | self = cb = 0; |
91 | attach = 0; |
92 | attach = 0; |
92 | } |
93 | } |
93 | }; |
94 | }; |
94 | |
95 | |
95 | // objects extendable from perl (or any other extension) should include or |
96 | // objects attachable from perl (or any other extension) should include or |
96 | // derive using the curiously recurring template pattern, to avoid |
97 | // derive using the curiously recurring template pattern, to avoid |
97 | // virtual method calls etc. |
98 | // virtual method calls etc. |
98 | template<class subclass> |
99 | template<class subclass> |
99 | struct extendable : extendable_base |
100 | struct attachable : attachable_base |
100 | { |
101 | { |
101 | static data_type get_dt () |
102 | static data_type get_dt () |
102 | { |
103 | { |
103 | subclass::get_dt (); |
104 | subclass::get_dt (); |
104 | } |
105 | } |
… | |
… | |
111 | int idx; |
112 | int idx; |
112 | |
113 | |
113 | object_freezer (const char *filename); |
114 | object_freezer (const char *filename); |
114 | ~object_freezer (); |
115 | ~object_freezer (); |
115 | |
116 | |
116 | void put (extendable_base *ext); |
117 | void put (attachable_base *ext); |
117 | |
118 | |
118 | template<class subclass> |
119 | template<class subclass> |
119 | void put (extendable<subclass> *obj) |
120 | void put (attachable<subclass> *obj) |
120 | { |
121 | { |
121 | put ((extendable_base *)obj); |
122 | put ((attachable_base *)obj); |
122 | } |
123 | } |
123 | |
124 | |
124 | void finish (); |
125 | void finish (); |
125 | }; |
126 | }; |
126 | |
127 | |
… | |
… | |
130 | int idx; |
131 | int idx; |
131 | |
132 | |
132 | object_thawer (const char *filename = 0); |
133 | object_thawer (const char *filename = 0); |
133 | ~object_thawer (); |
134 | ~object_thawer (); |
134 | |
135 | |
135 | void get (data_type type, void *obj, extendable_base *ext); |
136 | void get (data_type type, void *obj, attachable_base *ext); |
136 | |
137 | |
137 | template<class subclass> |
138 | template<class subclass> |
138 | void get (extendable<subclass> *obj) |
139 | void get (attachable<subclass> *obj) |
139 | { |
140 | { |
140 | if (av) |
141 | if (av) |
141 | get (subclass::get_dt (), (subclass *)obj, obj); |
142 | get (subclass::get_dt (), (subclass *)obj, obj); |
142 | } |
143 | } |
143 | |
144 | |