wrapper fix

This commit is contained in:
AndreaRigoni
2026-04-16 11:05:26 +00:00
parent 865282aefc
commit 83af9a180f
3 changed files with 55 additions and 1 deletions

View File

@@ -67,6 +67,12 @@ public:
static uLib::ObjectRegistrar<className> ULIB_REG_CONCAT( \
g_ObjectRegistrar_, __LINE__)(registeredName);
// Object Wrapper
template <typename T> 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 <typename U = T,
typename = std::enable_if_t<std::is_default_constructible_v<U>>>

View File

@@ -16,7 +16,7 @@ int main() {
std::cout << "Testing ObjectWrapper with Non-Default Constructible type..." << std::endl;
NonDefault nd(10);
uLib::ObjectWrapper<NonDefault> w2(&nd);
uLib::ObjectWrapper<NonDefault> w2(nd);
// The following would NOT compile without SFINAE:
// uLib::ObjectWrapper<NonDefault> w3;

View File

@@ -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;