… | |
… | |
76 | #define RESULT_INT(idx) RESULT(idx, INT) |
76 | #define RESULT_INT(idx) RESULT(idx, INT) |
77 | |
77 | |
78 | bool cfperl_invoke (event_type event, ...); |
78 | bool cfperl_invoke (event_type event, ...); |
79 | int cfperl_result_INT (int idx); |
79 | int cfperl_result_INT (int idx); |
80 | |
80 | |
81 | struct extendable_base |
81 | struct attachable_base |
82 | { |
82 | { |
83 | void *self, *cb; // CF+ perl self and callback |
83 | void *self, *cb; // CF+ perl self and callback |
84 | const char *attach; // generic extension attachment information |
84 | const char *attach; // generic extension attachment information |
85 | |
85 | |
86 | void clear (); // called when free'ing objects |
86 | void clear (); // called when free'ing objects |
87 | void optimise (); // possibly save some memory by destroying unneeded data |
87 | void optimise (); // possibly save some memory by destroying unneeded data |
88 | |
88 | |
89 | void extendable_init () |
89 | void attachable_init () |
90 | { |
90 | { |
91 | self = cb = 0; |
91 | self = cb = 0; |
92 | attach = 0; |
92 | attach = 0; |
93 | } |
93 | } |
94 | }; |
94 | }; |
95 | |
95 | |
96 | // objects extendable from perl (or any other extension) should include or |
96 | // objects attachable from perl (or any other extension) should include or |
97 | // derive using the curiously recurring template pattern, to avoid |
97 | // derive using the curiously recurring template pattern, to avoid |
98 | // virtual method calls etc. |
98 | // virtual method calls etc. |
99 | template<class subclass> |
99 | template<class subclass> |
100 | struct extendable : extendable_base |
100 | struct attachable : attachable_base |
101 | { |
101 | { |
102 | static data_type get_dt () |
102 | static data_type get_dt () |
103 | { |
103 | { |
104 | subclass::get_dt (); |
104 | subclass::get_dt (); |
105 | } |
105 | } |
… | |
… | |
112 | int idx; |
112 | int idx; |
113 | |
113 | |
114 | object_freezer (const char *filename); |
114 | object_freezer (const char *filename); |
115 | ~object_freezer (); |
115 | ~object_freezer (); |
116 | |
116 | |
117 | void put (extendable_base *ext); |
117 | void put (attachable_base *ext); |
118 | |
118 | |
119 | template<class subclass> |
119 | template<class subclass> |
120 | void put (extendable<subclass> *obj) |
120 | void put (attachable<subclass> *obj) |
121 | { |
121 | { |
122 | put ((extendable_base *)obj); |
122 | put ((attachable_base *)obj); |
123 | } |
123 | } |
124 | |
124 | |
125 | void finish (); |
125 | void finish (); |
126 | }; |
126 | }; |
127 | |
127 | |
… | |
… | |
131 | int idx; |
131 | int idx; |
132 | |
132 | |
133 | object_thawer (const char *filename = 0); |
133 | object_thawer (const char *filename = 0); |
134 | ~object_thawer (); |
134 | ~object_thawer (); |
135 | |
135 | |
136 | void get (data_type type, void *obj, extendable_base *ext); |
136 | void get (data_type type, void *obj, attachable_base *ext); |
137 | |
137 | |
138 | template<class subclass> |
138 | template<class subclass> |
139 | void get (extendable<subclass> *obj) |
139 | void get (attachable<subclass> *obj) |
140 | { |
140 | { |
141 | if (av) |
141 | if (av) |
142 | get (subclass::get_dt (), (subclass *)obj, obj); |
142 | get (subclass::get_dt (), (subclass *)obj, obj); |
143 | } |
143 | } |
144 | |
144 | |