Go to the documentation of this file.
26 #include <type_traits>
28 #define ARMARX_MINIMAL_PLACEMENT_CONSTRUCTION_HELPER_BASE(CommonBaseType) \
29 using _typeBase = CommonBaseType; \
30 virtual std::size_t _alignof() const = 0; \
31 virtual std::size_t _sizeof() const = 0; \
32 virtual _typeBase* _placementCopyConstruct(void* place) const = 0; \
33 std::size_t _accumulateSize(std::size_t offset = 0) const \
35 return offset + (_alignof() - (offset % _alignof())) % _alignof() + _sizeof(); \
38 #define ARMARX_PLACEMENT_CONSTRUCTION_HELPER_BASE(CommonBaseType) \
39 ARMARX_MINIMAL_PLACEMENT_CONSTRUCTION_HELPER_BASE(CommonBaseType) \
40 virtual void _copyTo(_typeBase* target) const = 0; \
41 virtual std::unique_ptr<_typeBase> _clone() const = 0; \
42 virtual _typeBase* _placementConstruct(void* place) const = 0;
44 #define ARMARX_MINIMAL_PLACEMENT_CONSTRUCTION_HELPER \
45 std::size_t _alignof() const override \
47 using _type = typename std::decay<decltype(*this)>::type; \
48 return alignof(_type); \
50 std::size_t _sizeof() const override \
52 using _type = typename std::decay<decltype(*this)>::type; \
53 return sizeof(_type); \
55 _typeBase* _placementCopyConstruct(void* place) const override \
57 using _type = typename std::decay<decltype(*this)>::type; \
58 return new (place) _type(*this); \
60 void _checkBaseType() \
62 using _type = typename std::decay<decltype(*this)>::type; \
63 static_assert(std::is_base_of<_typeBase, _type>::value, \
64 "This class has to derive the common base class"); \
67 #define ARMARX_PLACEMENT_CONSTRUCTION_HELPER \
68 ARMARX_MINIMAL_PLACEMENT_CONSTRUCTION_HELPER \
69 void _copyTo(_typeBase* target) const override \
71 using _type = typename std::decay<decltype(*this)>::type; \
72 _type* const castedTarget = dynamic_cast<_type*>(target); \
73 ARMARX_CHECK_NOT_NULL(castedTarget); \
74 *castedTarget = *this; \
76 std::unique_ptr<_typeBase> _clone() const override \
78 using _type = typename std::decay<decltype(*this)>::type; \
79 return std::unique_ptr<_typeBase>{new _type(*this)}; \
81 _typeBase* _placementConstruct(void* place) const override \
83 using _type = typename std::decay<decltype(*this)>::type; \
84 return new (place) _type; \