|
21 | 21 |
|
22 | 22 | #include <chainbase/allocators.hpp> |
23 | 23 | #include <chainbase/state_snapshot_support.hpp> |
| 24 | +#include <chainbase/util/object.hpp> |
24 | 25 | #include <chainbase/util/object_id.hpp> |
25 | 26 |
|
26 | 27 | #include <fc/exception/exception.hpp> |
@@ -179,89 +180,6 @@ namespace chainbase { |
179 | 180 | struct needs_remove_check<T, std::void_t<decltype(std::declval<const T&>().check_on_remove())>> |
180 | 181 | : std::true_type {}; |
181 | 182 |
|
182 | | - template<uint16_t TypeNumber, typename Derived, typename HasDynamicAlloc = std::false_type, typename EnableNoUndo = std::false_type> |
183 | | - struct object |
184 | | - { |
185 | | - typedef oid<Derived> id_type; |
186 | | - typedef oid_ref<Derived> id_ref_type; |
187 | | - enum { type_id = TypeNumber }; |
188 | | - /* |
189 | | - Mark chain object class with true_type when it has elements that need to be passed an allocator. |
190 | | - It adds code that collects dynamic allocation for benchmarks. |
191 | | - */ |
192 | | - typedef HasDynamicAlloc has_dynamic_alloc_t; |
193 | | - /* |
194 | | - Do not mark chain object class with it unless you know what you are doing! It enables "no undo" |
195 | | - destructions of objects, but optimized for very specific scenario, where you are guaranteed that |
196 | | - creation/modification of object prior of its "no undo" destruction is not present on different |
197 | | - active revision of undo stack. If used in different scenario, rare forking events can lead to |
198 | | - crashes or inconsistent state. |
199 | | - Example: comment_object is not modified and there is 7 day grace period between creation and destruction |
200 | | - during migration to archive, so there is no waiting undo element when migration is performed; |
201 | | - the same is not true for volatile_comment_object |
202 | | - */ |
203 | | - typedef EnableNoUndo enable_no_undo_t; |
204 | | - }; |
205 | | - |
206 | | - /** this class is ment to be specified to enable lookup of index type by object type using |
207 | | - * the SET_INDEX_TYPE macro. |
208 | | - **/ |
209 | | - template<typename T> |
210 | | - struct get_index_type {}; |
211 | | - |
212 | | - /** |
213 | | - * This macro must be used at global scope and OBJECT_TYPE and INDEX_TYPE must be fully qualified |
214 | | - */ |
215 | | - #define CHAINBASE_SET_INDEX_TYPE( OBJECT_TYPE, INDEX_TYPE ) \ |
216 | | - namespace chainbase { template<> struct get_index_type<OBJECT_TYPE> { typedef INDEX_TYPE type; }; } |
217 | | - |
218 | | - #define CHAINBASE_OBJECT_1( object_class ) CHAINBASE_OBJECT_false( object_class ) |
219 | | - #define CHAINBASE_OBJECT_2( object_class, allow_default ) CHAINBASE_OBJECT_##allow_default( object_class ) |
220 | | - #define CHAINBASE_OBJECT_true( object_class ) CHAINBASE_OBJECT_COMMON( object_class ); public: object_class() : id(0) {} private: |
221 | | - #define CHAINBASE_OBJECT_COMMON( object_class ) \ |
222 | | - private: \ |
223 | | - id_type id; \ |
224 | | - object_class( const object_class& source ) = default; \ |
225 | | - /* problem with this being private? you most likely did \ |
226 | | - auto chain_object = db.get(...); \ |
227 | | - instead of \ |
228 | | - auto& chain_object_ref = db.get(...); \ |
229 | | - In case you actually need copy, use copy_chain_object() below \ |
230 | | - */ \ |
231 | | - object_class& operator= ( const object_class& source ) = default; \ |
232 | | - public: \ |
233 | | - id_type get_id() const { return id; } \ |
234 | | - object_class( object_class&& source ) = default; \ |
235 | | - object_class& operator= ( object_class&& source ) = default; \ |
236 | | - object_class copy_chain_object() const { return *this; } \ |
237 | | - friend class fc::reflector< object_class > |
238 | | - |
239 | | - #define CHAINBASE_OBJECT_false( object_class ) CHAINBASE_OBJECT_COMMON( object_class ); object_class() = delete; \ |
240 | | - private: |
241 | | - |
242 | | - /** |
243 | | - * use at the start of any class derived from chainbase::object<>, f.e.: |
244 | | - * CHAINBASE_OBJECT( account_object ) or |
245 | | - * CHAINBASE_OBJECT( dynamic_global_property_object, true ) |
246 | | - * first parameter is a class name, second (true or false, default false) tells if default constructor should be allowed |
247 | | - */ |
248 | | - #define CHAINBASE_OBJECT( ... ) BOOST_PP_OVERLOAD(CHAINBASE_OBJECT_,__VA_ARGS__)(__VA_ARGS__) |
249 | | - |
250 | | - |
251 | | - #define CHAINBASE_ALLOCATED_MEMBERS( r, init, member ) , member( init ) |
252 | | - #define CHAINBASE_DEFAULT_CONSTRUCTOR( OBJECT_TYPE, ALLOCATED_MEMBERS... ) \ |
253 | | - template<typename Constructor, typename Allocator> \ |
254 | | - OBJECT_TYPE( Allocator&& a, uint64_t _id, Constructor&& c ) \ |
255 | | - : id( _id ) BOOST_PP_SEQ_FOR_EACH( CHAINBASE_ALLOCATED_MEMBERS, a, ALLOCATED_MEMBERS ) \ |
256 | | - { c(*this); } |
257 | | - |
258 | | - #define CHAINBASE_UNPACK_CONSTRUCTOR( OBJECT_TYPE, ALLOCATED_MEMBERS... ) \ |
259 | | - private: template<typename Allocator> \ |
260 | | - OBJECT_TYPE( Allocator&& a, uint64_t _id, std::function<void(OBJECT_TYPE&)> unpackFn) \ |
261 | | - : id( _id ) BOOST_PP_SEQ_FOR_EACH( CHAINBASE_ALLOCATED_MEMBERS, a, ALLOCATED_MEMBERS ) \ |
262 | | - { unpackFn(*this); } \ |
263 | | - template <class T> friend class chainbase::generic_index |
264 | | - |
265 | 183 | class int_incrementer |
266 | 184 | { |
267 | 185 | public: |
@@ -1483,5 +1401,5 @@ namespace chainbase { |
1483 | 1401 | bool _at_least_one_index_is_created_now = false; |
1484 | 1402 | }; |
1485 | 1403 |
|
1486 | | -} // namepsace chainbase |
| 1404 | +} // namespace chainbase |
1487 | 1405 |
|
0 commit comments