diff --git a/src/oatpp/core/data/mapping/type/Type.hpp b/src/oatpp/core/data/mapping/type/Type.hpp index 628f3f08..90cba2ae 100644 --- a/src/oatpp/core/data/mapping/type/Type.hpp +++ b/src/oatpp/core/data/mapping/type/Type.hpp @@ -154,19 +154,13 @@ public: inline ObjectWrapper& operator=(const ObjectWrapper& other){ m_ptr = other.m_ptr; - m_valueType = other.m_valueType; return *this; } inline ObjectWrapper& operator=(ObjectWrapper&& other){ m_ptr = std::move(other.m_ptr); - m_valueType = other.m_valueType; return *this; } - - inline operator ObjectWrapper() const { - return ObjectWrapper(this->m_ptr, m_valueType); - } template Wrapper staticCast() const { @@ -219,7 +213,88 @@ public: }; -typedef ObjectWrapper Void; +class Void : public ObjectWrapper { +public: + Void(const std::shared_ptr& ptr, const type::Type* const valueType) + : ObjectWrapper(ptr, valueType) + {} +public: + + Void() {} + + template::value, void>::type + > + Void(T) {} + + Void(const Type* const type) + : ObjectWrapper(type) + {} + + Void(const std::shared_ptr& ptr) + : type::ObjectWrapper(ptr) + {} + + Void(std::shared_ptr&& ptr) + : type::ObjectWrapper(std::forward>(ptr)) + {} + + template + Void(const ObjectWrapper& other) + : type::ObjectWrapper(other.getPtr(), other.getValueType()) + {} + + template + Void(ObjectWrapper&& other) + : type::ObjectWrapper(std::move(other.getPtr()), other.getValueType()) + {} + + template::value, void>::type + > + inline Void& operator = (std::nullptr_t) { + m_ptr.reset(); + return *this; + } + + template + inline Void& operator = (const ObjectWrapper& other){ + m_ptr = other.m_ptr; + m_valueType = other.getValueType(); + return *this; + } + + template + inline Void& operator = (ObjectWrapper&& other){ + m_ptr = std::move(other.m_ptr); + m_valueType = other.getValueType(); + return *this; + } + + template::value, void>::type + > + inline bool operator == (T) const { + return m_ptr.get() == nullptr; + } + + template::value, void>::type + > + inline bool operator != (T) const { + return m_ptr.get() != nullptr; + } + + template + inline bool operator == (const ObjectWrapper &other) const { + return m_ptr.get() == other.get(); + } + + template + inline bool operator != (const ObjectWrapper &other) const { + return m_ptr.get() != other.get(); + } +}; template struct ObjectWrapperByUnderlyingType {}; diff --git a/test/oatpp/AllTestsMain.cpp b/test/oatpp/AllTestsMain.cpp index 5b753cfe..db4ac695 100644 --- a/test/oatpp/AllTestsMain.cpp +++ b/test/oatpp/AllTestsMain.cpp @@ -106,6 +106,7 @@ void runTests() { OATPP_RUN_TEST(oatpp::test::core::data::mapping::type::UnorderedMapTest); OATPP_RUN_TEST(oatpp::test::core::data::mapping::type::AnyTest); OATPP_RUN_TEST(oatpp::test::core::data::mapping::type::EnumTest); + OATPP_RUN_TEST(oatpp::test::core::data::mapping::type::ObjectTest); OATPP_RUN_TEST(oatpp::test::core::data::mapping::type::InterpretationTest); diff --git a/test/oatpp/core/data/mapping/type/ObjectTest.cpp b/test/oatpp/core/data/mapping/type/ObjectTest.cpp index b9468eef..bb637509 100644 --- a/test/oatpp/core/data/mapping/type/ObjectTest.cpp +++ b/test/oatpp/core/data/mapping/type/ObjectTest.cpp @@ -86,6 +86,14 @@ class DtoC : public DtoA { }; +class DtoD : public DtoA { + + DTO_INIT(DtoD, DtoA) + + DTO_FIELD(Int32, a) = Int64(64); + +}; + #include OATPP_CODEGEN_END(DTO) void runDtoInitializations() { @@ -302,6 +310,13 @@ void ObjectTest::onRun() { OATPP_LOGI(TAG, "OK"); } + { + auto dto = DtoD::createShared(); + OATPP_ASSERT(dto->a.getValueType() == oatpp::Int32::Class::getType()); + OATPP_ASSERT(dto->a); + OATPP_ASSERT(dto->a == 64); + } + } }}}}}}