|
12 | 12 | #pragma once |
13 | 13 |
|
14 | 14 | #include "rtl_errors.h" |
| 15 | +#include "erase_constructor.h" |
| 16 | + |
15 | 17 | #include "RObjectBuilder.hpp" |
16 | 18 |
|
17 | 19 | namespace rtl::dispatch |
18 | 20 | { |
19 | | - template<class record_t> |
20 | | - struct aware_constructor |
| 21 | + template<class record_t, class ...signature_t> |
| 22 | + struct aware_constructor : public erase_constructor<traits::normal_sign_t<signature_t>...> |
21 | 23 | { |
| 24 | + using this_t = aware_constructor; |
| 25 | + using base_t = erase_constructor<traits::normal_sign_t<signature_t>...>; |
| 26 | + |
| 27 | + aware_constructor(): base_t(this_t::get_allocator()) |
| 28 | + { } |
| 29 | + |
22 | 30 | template<class ...args_t> |
23 | | - static Return allocator(const detail::FunctorId& pFunctorId, alloc pAllocType, const detail::FunctorId& pClonerId, args_t...params) |
| 31 | + static Return get_allocator() |
24 | 32 | { |
25 | | - if constexpr (sizeof...(args_t) == 0 && !std::is_default_constructible_v<record_t>) |
26 | | - { //default constructor, private or deleted. |
27 | | - return { error::TypeNotDefaultConstructible, RObject{} }; |
28 | | - } |
29 | | - else |
| 33 | + return [](const detail::FunctorId& pFunctorId, alloc pAllocType, const detail::FunctorId& pClonerId, args_t...params) |
30 | 34 | { |
31 | | - if (pAllocType == alloc::Stack) { |
| 35 | + if constexpr (sizeof...(args_t) == 0 && !std::is_default_constructible_v<record_t>) |
| 36 | + { //default constructor, private or deleted. |
| 37 | + return { error::TypeNotDefaultConstructible, RObject{} }; |
| 38 | + } |
| 39 | + else |
| 40 | + { |
| 41 | + if (pAllocType == alloc::Stack) { |
32 | 42 |
|
33 | | - if constexpr (!std::is_copy_constructible_v<record_t>) |
34 | | - { |
35 | | - return { |
36 | | - error::TypeNotCopyConstructible, RObject{} |
37 | | - }; |
| 43 | + if constexpr (!std::is_copy_constructible_v<record_t>) |
| 44 | + { |
| 45 | + return { error::TypeNotCopyConstructible, RObject{} }; |
| 46 | + } |
| 47 | + else |
| 48 | + { |
| 49 | + return { |
| 50 | + error::None, |
| 51 | + detail::RObjectBuilder<record_t>::template build<alloc::Stack>( |
| 52 | + record_t(std::forward<args_t>(params)...), pClonerId, true |
| 53 | + ) |
| 54 | + }; |
| 55 | + } |
38 | 56 | } |
39 | | - else |
| 57 | + else if (pAllocType == alloc::Heap) |
40 | 58 | { |
41 | 59 | return { |
42 | 60 | error::None, |
43 | | - detail::RObjectBuilder<record_t>::template build<alloc::Stack>( |
44 | | - record_t(std::forward<args_t>(params)...), pClonerId, true |
| 61 | + detail::RObjectBuilder<record_t*>::template build<alloc::Heap>( |
| 62 | + new record_t(std::forward<args_t>(params)...), pClonerId, true |
45 | 63 | ) |
46 | 64 | }; |
47 | 65 | } |
48 | 66 | } |
49 | | - else if (pAllocType == alloc::Heap) |
50 | | - { |
51 | | - return { |
52 | | - error::None, |
53 | | - detail::RObjectBuilder<record_t*>::template build<alloc::Heap>( |
54 | | - new record_t(std::forward<args_t>(params)...), pClonerId, true |
55 | | - ) |
56 | | - }; |
57 | | - } |
58 | | - } |
59 | | - return { error::EmptyRObject, RObject{} }; //dead code. compiler warning omitted. |
| 67 | + return { error::EmptyRObject, RObject{} }; //dead code. compiler warning omitted. |
| 68 | + }; |
60 | 69 | } |
61 | 70 |
|
62 | 71 |
|
63 | 72 | static Return cloner(const detail::FunctorId& pFunctorId, const RObject& pOther, alloc pAllocOn) |
64 | 73 | { |
65 | 74 | if constexpr (std::is_copy_constructible_v<record_t>) |
66 | 75 | { |
67 | | - return [](const detail::FunctorId& pFunctorId, const RObject& pOther, alloc pAllocOn) -> Return |
| 76 | + const auto& srcObj = pOther.view<record_t>()->get(); |
| 77 | + switch (pAllocOn) |
68 | 78 | { |
69 | | - const auto& srcObj = pOther.view<record_t>()->get(); |
70 | | - switch (pAllocOn) |
71 | | - { |
72 | | - case alloc::Stack: |
73 | | - return { |
74 | | - error::None, |
75 | | - detail::RObjectBuilder<record_t>::template build<alloc::Stack>( |
76 | | - record_t(srcObj), pFunctorId, true |
77 | | - ) |
78 | | - }; |
79 | | - case alloc::Heap: |
80 | | - return { |
81 | | - error::None, |
82 | | - detail::RObjectBuilder<record_t*>::template build<alloc::Heap>( |
83 | | - new record_t(srcObj), pFunctorId, true |
84 | | - ) |
85 | | - }; |
86 | | - default: |
87 | | - return { |
88 | | - error::EmptyRObject, |
89 | | - RObject{} |
90 | | - }; |
91 | | - } |
92 | | - }; |
| 79 | + case alloc::Stack: |
| 80 | + return { |
| 81 | + error::None, |
| 82 | + detail::RObjectBuilder<record_t>::template build<alloc::Stack>( |
| 83 | + record_t(srcObj), pFunctorId, true |
| 84 | + ) |
| 85 | + }; |
| 86 | + case alloc::Heap: |
| 87 | + return { |
| 88 | + error::None, |
| 89 | + detail::RObjectBuilder<record_t*>::template build<alloc::Heap>( |
| 90 | + new record_t(srcObj), pFunctorId, true |
| 91 | + ) |
| 92 | + }; |
| 93 | + default: |
| 94 | + return { error::EmptyRObject, RObject{} }; |
| 95 | + } |
93 | 96 | } |
94 | 97 | else |
95 | 98 | { |
96 | | - return [](const detail::FunctorId& pFunctorId, const RObject& pOther, alloc pAllocOn) -> Return |
97 | | - { |
98 | | - return { |
99 | | - error::TypeNotCopyConstructible, |
100 | | - RObject{} |
101 | | - }; |
102 | | - }; |
| 99 | + return { error::TypeNotCopyConstructible, RObject{} }; |
103 | 100 | } |
104 | 101 | } |
105 | 102 | }; |
|
0 commit comments