Skip to content

Commit 214085c

Browse files
committed
removed static RObjectId. clean-up.
1 parent 11fad81 commit 214085c

File tree

4 files changed

+37
-42
lines changed

4 files changed

+37
-42
lines changed

ReflectionTemplateLib/access/inc/RObject.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ namespace rtl
4444
using Cloner = std::function< Return(const RObject&, rtl::alloc) >;
4545

4646
mutable std::any m_object;
47+
mutable detail::RObjectId m_objectId;
4748

4849
mutable const Cloner* m_getClone;
49-
mutable const detail::RObjectId* m_objectId;
5050
mutable const std::vector<traits::ConverterPair>* m_converters;
5151

5252
RObject(const RObject&) = default;
53-
RObject(const detail::RObjectId* pRObjId, std::any&& pObject, const Cloner* pCloner,
53+
RObject(std::any&& pObject, const detail::RObjectId pRObjId, const Cloner* pCloner,
5454
const std::vector<traits::ConverterPair>* pConverters) noexcept;
5555

5656
std::size_t getConverterIndex(const std::size_t pToTypeId) const;
@@ -70,15 +70,15 @@ namespace rtl
7070
RObject& operator=(const RObject&) = delete;
7171

7272
GETTER_BOOL(Empty, (m_object.has_value() == false))
73-
GETTER_BOOL(OnHeap, (m_objectId && m_objectId->m_allocatedOn == alloc::Heap))
74-
GETTER_BOOL(AllocatedByRtl, (m_objectId && m_objectId->m_allocatedOn == alloc::Heap))
75-
GETTER(std::size_t, TypeId, (m_objectId ? m_objectId->m_typeId : detail::TypeId<>::None))
73+
GETTER_BOOL(OnHeap, (m_objectId.m_allocatedOn == alloc::Heap))
74+
GETTER_BOOL(AllocatedByRtl, (m_objectId.m_allocatedOn == alloc::Heap))
75+
GETTER(std::size_t, TypeId, m_objectId.m_typeId)
7676

7777
/* Reflection Const Semantics:
7878
* - All reflected objects default to mutable internally; API enforces logical constness.
7979
* - RTL may 'const_cast' its own objects(allocated via RTL) but preserves logical constness.
8080
* - External objects (e.g. returned via Reflected call) keep original qualifier; if const, then const_cast is unsafe.
81-
*/ GETTER_BOOL(ConstCastSafe, (m_objectId && m_objectId->m_isConstCastSafe))
81+
*/ GETTER_BOOL(ConstCastSafe, m_objectId.m_isConstCastSafe)
8282

8383
template <class _asType>
8484
bool canViewAs() const;

ReflectionTemplateLib/access/inc/RObject.hpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,23 @@
2424

2525
namespace rtl
2626
{
27-
FORCE_INLINE RObject::RObject(const detail::RObjectId* pRObjId, std::any&& pObject, const Cloner* pCloner,
27+
FORCE_INLINE RObject::RObject(std::any&& pObject, const detail::RObjectId pRObjId, const Cloner* pCloner,
2828
const std::vector<traits::ConverterPair>* pConverters) noexcept
2929
: m_object(std::forward<std::any>(pObject))
30-
, m_getClone(pCloner)
3130
, m_objectId(pRObjId)
31+
, m_getClone(pCloner)
3232
, m_converters(pConverters)
3333
{ }
3434

3535
FORCE_INLINE RObject::RObject(RObject&& pOther) noexcept
3636
: m_object(std::move(pOther.m_object))
37-
, m_getClone(pOther.m_getClone)
3837
, m_objectId(pOther.m_objectId)
38+
, m_getClone(pOther.m_getClone)
3939
, m_converters(pOther.m_converters)
4040
{
4141
// Explicitly clear moved-from source
4242
pOther.m_object.reset();
43-
pOther.m_objectId = nullptr;
43+
pOther.m_objectId = {};
4444
pOther.m_getClone = nullptr;
4545
pOther.m_converters = nullptr;
4646
}
@@ -54,7 +54,7 @@ namespace rtl
5454

5555
inline std::size_t RObject::getConverterIndex(const std::size_t pToTypeId) const
5656
{
57-
if (m_objectId->m_containsAs != detail::EntityKind::None) {
57+
if (m_objectId.m_containsAs != detail::EntityKind::None) {
5858
for (std::size_t index = 0; index < m_converters->size(); index++) {
5959
if ((*m_converters)[index].first == pToTypeId) {
6060
return index;
@@ -70,12 +70,12 @@ namespace rtl
7070
{
7171
if constexpr (traits::is_bare_type<T>()) {
7272
if constexpr (traits::std_wrapper<T>::type != detail::Wrapper::None) {
73-
if (m_objectId->m_wrapperTypeId == traits::std_wrapper<T>::id()) {
73+
if (m_objectId.m_wrapperTypeId == traits::std_wrapper<T>::id()) {
7474
return true;
7575
}
7676
}
7777
const auto& typeId = detail::TypeId<T>::get();
78-
return (m_objectId->m_typeId == typeId || getConverterIndex(typeId) != index_none);
78+
return (m_objectId.m_typeId == typeId || getConverterIndex(typeId) != index_none);
7979
}
8080
}
8181

@@ -85,7 +85,7 @@ namespace rtl
8585
{
8686
detail::EntityKind newKind = detail::EntityKind::None;
8787
const traits::Converter& convert = (*m_converters)[pIndex].second;
88-
const std::any& viewObj = convert(m_object, m_objectId->m_containsAs, newKind);
88+
const std::any& viewObj = convert(m_object, m_objectId.m_containsAs, newKind);
8989
const T* viewRef = detail::RObjExtractor::getPointer<T>(viewObj, newKind);
9090

9191
if (viewRef != nullptr && newKind == detail::EntityKind::Ref) {
@@ -105,7 +105,7 @@ namespace rtl
105105
{
106106
if constexpr (traits::is_bare_type<T>())
107107
{
108-
if (detail::TypeId<T>::get() == m_objectId->m_wrapperTypeId)
108+
if (detail::TypeId<T>::get() == m_objectId.m_wrapperTypeId)
109109
{
110110
using U = detail::RObjectUPtr<typename traits::std_wrapper<T>::value_type>;
111111
const U& uptrRef = *(detail::RObjExtractor(this).getWrapper<T>());
@@ -121,7 +121,7 @@ namespace rtl
121121
{
122122
if constexpr (traits::is_bare_type<T>())
123123
{
124-
if (detail::TypeId<T>::get() == m_objectId->m_wrapperTypeId)
124+
if (detail::TypeId<T>::get() == m_objectId.m_wrapperTypeId)
125125
{
126126
const T& sptrRef = *(detail::RObjExtractor(this).getWrapper<T>());
127127
return std::optional<rtl::view<T>>(std::in_place, const_cast<T&>(sptrRef));
@@ -137,7 +137,7 @@ namespace rtl
137137
if constexpr (traits::is_bare_type<T>())
138138
{
139139
const std::size_t asTypeId = detail::TypeId<T>::get();
140-
if (asTypeId == m_objectId->m_typeId)
140+
if (asTypeId == m_objectId.m_typeId)
141141
{
142142
const T* valRef = detail::RObjExtractor(this).getPointer<T>();
143143
if (valRef != nullptr) {
@@ -184,10 +184,10 @@ namespace rtl
184184
template<>
185185
inline Return RObject::createCopy<alloc::Stack, detail::EntityKind::Wrapper>() const
186186
{
187-
if (m_objectId->m_wrapperType == detail::Wrapper::None) {
187+
if (m_objectId.m_wrapperType == detail::Wrapper::None) {
188188
return { error::NotWrapperType, RObject{} };
189189
}
190-
else if (m_objectId->m_wrapperType == detail::Wrapper::Unique)
190+
else if (m_objectId.m_wrapperType == detail::Wrapper::Unique)
191191
{
192192
return { error::TypeNotCopyConstructible, RObject{} };
193193
}
@@ -212,7 +212,7 @@ namespace rtl
212212
else if constexpr (_copyTarget == copy::Auto) {
213213
// RTL wraps the objects allocated on heap in 'std::unique_ptr'. Which by default is transparent to RTL itself.
214214
// 'std::unique_ptr' acquired via any other source, (e.g. return value) are not transparent. hence the second condition.
215-
if (m_objectId->m_wrapperType != detail::Wrapper::None && !isAllocatedByRtl())
215+
if (m_objectId.m_wrapperType != detail::Wrapper::None && !isAllocatedByRtl())
216216
{
217217
return createCopy<_allocOn, detail::EntityKind::Wrapper>();
218218
}

ReflectionTemplateLib/detail/inc/RObjExtracter.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ namespace rtl::detail
4848
const T* getPointer() const
4949
{
5050
try {
51-
switch (m_rObj.m_objectId->m_containsAs)
51+
switch (m_rObj.m_objectId.m_containsAs)
5252
{
5353
case EntityKind::Ref: {
5454
return std::any_cast<const T*>(m_rObj.m_object);
@@ -72,12 +72,12 @@ namespace rtl::detail
7272
auto getWrapper() const -> const RObjectUPtr<typename traits::std_wrapper<T>::value_type>*
7373
{
7474
try {
75-
if (m_rObj.m_objectId->m_wrapperType == detail::Wrapper::Unique)
75+
if (m_rObj.m_objectId.m_wrapperType == detail::Wrapper::Unique)
7676
{
7777
using _T = traits::std_wrapper<T>::value_type;
7878
if constexpr (traits::is_const_v<_T>)
7979
{
80-
if (m_rObj.m_objectId->m_isWrappingConst)
80+
if (m_rObj.m_objectId.m_isWrappingConst)
8181
{
8282
using U = detail::RObjectUPtr<const _T>;
8383
const U& uptrRef = std::any_cast<const U&>(m_rObj.m_object);
@@ -101,12 +101,12 @@ namespace rtl::detail
101101
const T* getWrapper() const
102102
{
103103
try {
104-
if (m_rObj.m_objectId->m_wrapperType == detail::Wrapper::Shared)
104+
if (m_rObj.m_objectId.m_wrapperType == detail::Wrapper::Shared)
105105
{
106106
using _T = traits::std_wrapper<T>::value_type;
107107
if constexpr (traits::is_const_v<_T>)
108108
{
109-
if (m_rObj.m_objectId->m_isWrappingConst) {
109+
if (m_rObj.m_objectId.m_isWrappingConst) {
110110
using U = std::shared_ptr<const _T>;
111111
const U& sptrRef = std::any_cast<const U&>(m_rObj.m_object);
112112
return static_cast<const T*>(&sptrRef);
@@ -131,9 +131,9 @@ namespace rtl::detail
131131
try {
132132
if constexpr (std::is_destructible_v<T>)
133133
{
134-
if (m_rObj.m_objectId->m_wrapperType == detail::Wrapper::Unique)
134+
if (m_rObj.m_objectId.m_wrapperType == detail::Wrapper::Unique)
135135
{
136-
if (m_rObj.m_objectId->m_isWrappingConst) {
136+
if (m_rObj.m_objectId.m_isWrappingConst) {
137137
using U = detail::RObjectUPtr<const T>;
138138
const U& uptrRef = std::any_cast<const U&>(m_rObj.m_object);
139139
return static_cast<const T*>(uptrRef.get());
@@ -144,9 +144,9 @@ namespace rtl::detail
144144
return static_cast<const T*>(uptrRef.get());
145145
}
146146
}
147-
if (m_rObj.m_objectId->m_wrapperType == detail::Wrapper::Shared)
147+
if (m_rObj.m_objectId.m_wrapperType == detail::Wrapper::Shared)
148148
{
149-
if (m_rObj.m_objectId->m_isWrappingConst) {
149+
if (m_rObj.m_objectId.m_isWrappingConst) {
150150
using U = std::shared_ptr<const T>;
151151
const auto& sptrRef = std::any_cast<const U&>(m_rObj.m_object);
152152
return static_cast<const T*>(sptrRef.get());

ReflectionTemplateLib/detail/inc/RObjectBuilder.hpp

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,11 @@ namespace rtl::detail {
8181
FORCE_INLINE RObject RObjectBuilder<T>::build(T&& pVal, bool pIsConstCastSafe) noexcept
8282
{
8383
using _T = traits::raw_t<T>;
84-
static const RObjectId robjId = RObjectId::create<std::unique_ptr<_T>, alloc::Heap>(pIsConstCastSafe);
85-
86-
return RObject( &robjId,
87-
std::any{
84+
return RObject( std::any{
8885
std::in_place_type<RObjectUPtr<_T>>,
8986
RObjectUPtr<_T>(std::unique_ptr<_T>(static_cast<_T*>(pVal)))
9087
},
88+
RObjectId::create<std::unique_ptr<_T>, alloc::Heap>(pIsConstCastSafe),
9189
&buildCloner<_T>(),
9290
&getConverters<std::unique_ptr<_T>>());
9391
}
@@ -102,9 +100,8 @@ namespace rtl::detail {
102100

103101
if constexpr (isRawPointer)
104102
{
105-
static const RObjectId robjId = RObjectId::create<T, alloc::Stack>(pIsConstCastSafe);
106-
return RObject( &robjId,
107-
std::any { static_cast<const _T*>(pVal) },
103+
return RObject( std::any { static_cast<const _T*>(pVal) },
104+
RObjectId::create<T, alloc::Stack>(pIsConstCastSafe),
108105
&buildCloner<_T>(),
109106
&getConverters<T>() );
110107
}
@@ -113,24 +110,22 @@ namespace rtl::detail {
113110
if constexpr (traits::std_wrapper<_T>::type == Wrapper::Unique)
114111
{
115112
using U = traits::std_wrapper<_T>::value_type;
116-
static const RObjectId robjId = RObjectId::create<T, alloc::Stack>(pIsConstCastSafe);
117-
return RObject( &robjId,
118-
std::any {
113+
return RObject( std::any {
119114
std::in_place_type<RObjectUPtr<U>>,
120115
RObjectUPtr<U>(std::move(pVal))
121116
},
117+
RObjectId::create<T, alloc::Stack>(pIsConstCastSafe),
122118
&buildCloner<_T>(),
123119
&getConverters<T>() );
124120
}
125121
else
126122
{
127123
static_assert(std::is_copy_constructible_v<_T>, "T must be copy-constructible (std::any requires this).");
128-
static const RObjectId robjId = RObjectId::create<T, alloc::Stack>(pIsConstCastSafe);
129-
return RObject( &robjId,
130-
std::any {
124+
return RObject( std::any {
131125
std::in_place_type<T>,
132126
std::forward<T>(pVal)
133127
},
128+
RObjectId::create<T, alloc::Stack>(pIsConstCastSafe),
134129
&buildCloner<_T>(),
135130
&getConverters<T>() );
136131
}

0 commit comments

Comments
 (0)