wrapper fix
This commit is contained in:
@@ -67,6 +67,12 @@ public:
|
|||||||
static uLib::ObjectRegistrar<className> ULIB_REG_CONCAT( \
|
static uLib::ObjectRegistrar<className> ULIB_REG_CONCAT( \
|
||||||
g_ObjectRegistrar_, __LINE__)(registeredName);
|
g_ObjectRegistrar_, __LINE__)(registeredName);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Object Wrapper
|
||||||
|
|
||||||
template <typename T> class ObjectWrapper {
|
template <typename T> class ObjectWrapper {
|
||||||
public:
|
public:
|
||||||
ObjectWrapper(const std::string &className) {
|
ObjectWrapper(const std::string &className) {
|
||||||
@@ -75,6 +81,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
ObjectWrapper(T *model) : m_model(model) {}
|
ObjectWrapper(T *model) : m_model(model) {}
|
||||||
|
ObjectWrapper(T &model) : m_model(model) {}
|
||||||
|
|
||||||
template <typename U = T,
|
template <typename U = T,
|
||||||
typename = std::enable_if_t<std::is_default_constructible_v<U>>>
|
typename = std::enable_if_t<std::is_default_constructible_v<U>>>
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ int main() {
|
|||||||
|
|
||||||
std::cout << "Testing ObjectWrapper with Non-Default Constructible type..." << std::endl;
|
std::cout << "Testing ObjectWrapper with Non-Default Constructible type..." << std::endl;
|
||||||
NonDefault nd(10);
|
NonDefault nd(10);
|
||||||
uLib::ObjectWrapper<NonDefault> w2(&nd);
|
uLib::ObjectWrapper<NonDefault> w2(nd);
|
||||||
|
|
||||||
// The following would NOT compile without SFINAE:
|
// The following would NOT compile without SFINAE:
|
||||||
// uLib::ObjectWrapper<NonDefault> w3;
|
// uLib::ObjectWrapper<NonDefault> w3;
|
||||||
|
|||||||
@@ -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() {
|
int main() {
|
||||||
BEGIN_TESTING(Serialize Test);
|
BEGIN_TESTING(Serialize Test);
|
||||||
|
|
||||||
TEST1(test_V3f());
|
TEST1(test_V3f());
|
||||||
TEST1(testing_xml_class());
|
TEST1(testing_xml_class());
|
||||||
|
TEST1(test_referece_serialization());
|
||||||
// TEST1(testing_hrt_class());
|
// TEST1(testing_hrt_class());
|
||||||
|
|
||||||
END_TESTING;
|
END_TESTING;
|
||||||
|
|||||||
Reference in New Issue
Block a user