diff --git a/src/Core/ObjectFactory.h b/src/Core/ObjectFactory.h index 02bd111..e132ce9 100644 --- a/src/Core/ObjectFactory.h +++ b/src/Core/ObjectFactory.h @@ -67,6 +67,12 @@ public: static uLib::ObjectRegistrar ULIB_REG_CONCAT( \ g_ObjectRegistrar_, __LINE__)(registeredName); + + + + +// Object Wrapper + template class ObjectWrapper { public: ObjectWrapper(const std::string &className) { @@ -75,6 +81,7 @@ public: } ObjectWrapper(T *model) : m_model(model) {} + ObjectWrapper(T &model) : m_model(model) {} template >> diff --git a/src/Core/testing/ObjectWrapperTest.cpp b/src/Core/testing/ObjectWrapperTest.cpp index 06b9e72..73920f3 100644 --- a/src/Core/testing/ObjectWrapperTest.cpp +++ b/src/Core/testing/ObjectWrapperTest.cpp @@ -16,7 +16,7 @@ int main() { std::cout << "Testing ObjectWrapper with Non-Default Constructible type..." << std::endl; NonDefault nd(10); - uLib::ObjectWrapper w2(&nd); + uLib::ObjectWrapper w2(nd); // The following would NOT compile without SFINAE: // uLib::ObjectWrapper w3; diff --git a/src/Core/testing/SerializeTest.cpp b/src/Core/testing/SerializeTest.cpp index aba950c..d996f05 100644 --- a/src/Core/testing/SerializeTest.cpp +++ b/src/Core/testing/SerializeTest.cpp @@ -150,11 +150,58 @@ int testing_hrt_class() { + + +class B : public virtual Object { + uLibTypeMacro(B, Object) + ULIB_SERIALIZE_ACCESS + +public: + B() : m_b(1234567), m_a(nullptr) {} + + int m_b; + + // reference to A (serializes through ID) + A *m_a; +}; + +ULIB_SERIALIZABLE_OBJECT(B) +ULIB_SERIALIZE_OBJECT(B, Object) { + ar & "Object B : " & "--> m_b = " & AR(m_b) & "--> m_a = " & AR(m_a); +} + + + +int test_referece_serialization() { + A a; + { + B b,b2 ; + b.m_a = &a; + b2.m_a = &a; + + std::ofstream file("test_ref.xml"); + Archive::xml_oarchive(file) << NVP(b) << NVP(b2); + } + + + B b,b2; + { + std::ifstream file("test_ref.xml"); + Archive::xml_iarchive(file) >> NVP(b) >> NVP(b2); + } + + return (b.m_a->a() == a.a() && b2.m_a->a() == a.a()); +} + + + + int main() { BEGIN_TESTING(Serialize Test); TEST1(test_V3f()); TEST1(testing_xml_class()); + TEST1(test_referece_serialization()); // TEST1(testing_hrt_class()); END_TESTING;