refactor using pimpl and fix test
This commit is contained in:
@@ -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 ©) : 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 ©) {
|
||||
if (this == ©) 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";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user