refactor using pimpl and fix test

This commit is contained in:
AndreaRigoni
2026-03-25 16:18:07 +00:00
parent a467b7385b
commit 7d4acaef6d
17 changed files with 479 additions and 412 deletions

View File

@@ -61,8 +61,8 @@ public:
};
std::string m_InstanceName;
Vector<Signal> sigv;
Vector<Slot> slov;
std::vector<Signal> sigv;
std::vector<Slot> slov;
std::vector<PropertyBase*> m_Properties;
std::vector<PropertyBase*> m_DynamicProperties;
bool m_SignalsBlocked;
@@ -117,15 +117,30 @@ template void Object::serialize(Archive::log_archive &, const unsigned int);
Object::Object() : d(new ObjectPrivate) {
d->m_SignalsBlocked = false;
std::cout << "Object Constructor: created d=" << d << std::endl;
}
Object::Object(const Object &copy) : d(new ObjectPrivate) {
if (copy.d) {
d->m_InstanceName = copy.d->m_InstanceName;
d->m_SignalsBlocked = copy.d->m_SignalsBlocked;
}
std::cout << "Object CopyConstructor: created d=" << d << " from copy.d=" << copy.d << std::endl;
}
Object& Object::operator=(const Object &other) {
// Intentionally does NOT share 'd'. Each Object owns its own ObjectPrivate.
// Without this, the compiler-generated operator= would copy the 'd' pointer,
// causing two objects to share the same ObjectPrivate. When both are
// destroyed, 'd' would be deleted twice, corrupting the heap.
if (this != &other && other.d) {
d->m_InstanceName = other.d->m_InstanceName;
d->m_SignalsBlocked = other.d->m_SignalsBlocked;
}
return *this;
}
Object::~Object() {
std::cout << "Object Destructor: deleting d=" << d << " name=" << d->m_InstanceName << std::endl;
for (auto* p : d->m_DynamicProperties) {
delete p;
}
@@ -135,6 +150,7 @@ Object::~Object() {
void Object::DeepCopy(const Object &copy) {
if (this == &copy) return;
if (copy.d) d->m_InstanceName = copy.d->m_InstanceName;
std::cout << "Object DeepCopy: from d=" << copy.d << " to d=" << d << std::endl;
// Note: signals, slots and properties are intentionally not copied
// to maintain instance uniquely and avoid duplicate registrations.
this->Updated();
@@ -161,9 +177,8 @@ void Object::LoadConfig(std::istream &is, int version) {
void Object::PrintSelf(std::ostream &o) const {
o << "OBJECT signals: ------------------\n";
Vector<ObjectPrivate::Signal>::Iterator itr;
for (itr = d->sigv.begin(); itr < d->sigv.end(); itr++) {
o << " signal:[ " << itr->sigstr << " ]\n";
for (const auto& sig : d->sigv) {
o << " signal:[ " << sig.sigstr << " ]\n";
}
o << "--------------------------------------\n\n";
}