diff options
Diffstat (limited to 'sources/shiboken6/tests/libsample/objecttype.cpp')
-rw-r--r-- | sources/shiboken6/tests/libsample/objecttype.cpp | 133 |
1 files changed, 55 insertions, 78 deletions
diff --git a/sources/shiboken6/tests/libsample/objecttype.cpp b/sources/shiboken6/tests/libsample/objecttype.cpp index 03c677104..fa3e7357c 100644 --- a/sources/shiboken6/tests/libsample/objecttype.cpp +++ b/sources/shiboken6/tests/libsample/objecttype.cpp @@ -3,44 +3,36 @@ #include "objecttype.h" #include "objecttypelayout.h" + #include <algorithm> #include <iostream> #include <string> #include <assert.h> -#include <algorithm> - -using namespace std; - -ObjectType::ObjectType(ObjectType* parent) : m_parent(nullptr), m_layout(nullptr), m_call_id(-1) +ObjectType::ObjectType(ObjectType *parent) { setParent(parent); } +ObjectType::ObjectType(ObjectType &&) noexcept = default; +ObjectType &ObjectType::operator=(ObjectType &&) noexcept = default; + ObjectType::~ObjectType() { for (auto *o : m_children) delete o; } -ObjectType* -ObjectType::createWithChild() +ObjectType *ObjectType::createWithChild() { - ObjectType* parent = create(); - ObjectType* child = create(); + ObjectType *parent = create(); + ObjectType *child = create(); child->setObjectName("child"); child->setParent(parent); return parent; } -const ObjectType *ObjectType::defaultInstance() -{ - static ObjectType result; - return &result; -} - -void -ObjectType::removeChild(ObjectType* child) +void ObjectType::removeChild(ObjectType *child) { if (!child) return; @@ -52,8 +44,7 @@ ObjectType::removeChild(ObjectType* child) } } -ObjectType* -ObjectType::takeChild(ObjectType* child) +ObjectType *ObjectType::takeChild(ObjectType *child) { if (!child) return nullptr; @@ -67,8 +58,7 @@ ObjectType::takeChild(ObjectType* child) return nullptr; } -ObjectType* -ObjectType::takeChild(const Str& name) +ObjectType *ObjectType::takeChild(const Str &name) { return takeChild(findChild(name)); @@ -82,15 +72,13 @@ ObjectTypeList::iterator ObjectType::findChildByName(const Str &name) }); } -ObjectType* -ObjectType::findChild(const Str& name) +ObjectType *ObjectType::findChild(const Str &name) { auto it = findChildByName(name); return it != m_children.end() ? *it : nullptr; } -void -ObjectType::killChild(const Str& name) +void ObjectType::killChild(const Str &name) { auto it = findChildByName(name); if (it != m_children.end()) { @@ -100,8 +88,7 @@ ObjectType::killChild(const Str& name) } } -void -ObjectType::setParent(ObjectType* parent) +void ObjectType::setParent(ObjectType *parent) { if (m_parent == parent) return; @@ -114,33 +101,28 @@ ObjectType::setParent(ObjectType* parent) m_parent->m_children.push_back(this); } -void -ObjectType::setObjectName(const Str& name) +void ObjectType::setObjectName(const Str &name) { m_objectName = name; } -Str -ObjectType::objectName() const +Str ObjectType::objectName() const { return m_objectName; } -bool -ObjectType::causeEvent(Event::EventType eventType) +bool ObjectType::causeEvent(Event::EventType eventType) { Event e(eventType); return event(&e); } -bool -ObjectType::event(Event* event) +bool ObjectType::event(Event *) { return true; } -int -ObjectType::processEvent(ObjectTypeList objects, Event *event) +int ObjectType::processEvent(ObjectTypeList objects, Event *event) { return std::count_if(objects.begin(), objects.end(), [event] (ObjectType *o) { @@ -148,38 +130,43 @@ ObjectType::processEvent(ObjectTypeList objects, Event *event) }); } -void -ObjectType::callInvalidateEvent(Event* event) +void ObjectType::callInvalidateEvent(Event *event) { invalidateEvent(event); } -void -ObjectType::setLayout(ObjectTypeLayout* l) +void ObjectType::invalidateEvent(Event *) +{ +} + +void ObjectType::setLayout(ObjectTypeLayout *l) { if (!l) { - cerr << "[WARNING] ObjectType::setLayout: Cannot set layout to 0." << endl; + std::cerr << "[WARNING] ObjectType::setLayout: Cannot set layout to 0.\n"; return; } if (layout()) { if (layout() != l) { - cerr << "[WARNING] ObjectType::setLayout: Attempting to set ObjectTypeLayout '" << l->objectName().cstring(); - cerr << "' on ObjectType '" << objectName().cstring() << "', which already has a layout." << endl; + std::cerr << "[WARNING] ObjectType::setLayout: Attempting to set ObjectTypeLayout '" + << l->objectName().cstring() + << "' on ObjectType '" << objectName().cstring() + << "', which already has a layout.\n"; } return; } - ObjectType* oldParent = l->parent(); + ObjectType *oldParent = l->parent(); if (oldParent && oldParent != this) { if (oldParent->isLayoutType()) { - cerr << "[WARNING] ObjectType::setLayout: Attempting to set ObjectTypeLayout '" << l->objectName().cstring(); - cerr << "' on ObjectType '" << objectName().cstring() << "', when the ObjectTypeLayout already has a parent layout." << endl; + std::cerr << "[WARNING] ObjectType::setLayout: Attempting to set ObjectTypeLayout '" + << l->objectName().cstring() + << "' on ObjectType '" << objectName().cstring() + << "', when the ObjectTypeLayout already has a parent layout.\n"; return; - } else { - // Steal the layout from an ObjectType parent. - oldParent->takeLayout(); } + // Steal the layout from an ObjectType parent. + oldParent->takeLayout(); } m_layout = l; @@ -189,9 +176,9 @@ ObjectType::setLayout(ObjectTypeLayout* l) } } -ObjectTypeLayout* ObjectType::takeLayout() +ObjectTypeLayout *ObjectType::takeLayout() { - ObjectTypeLayout* l = layout(); + ObjectTypeLayout *l = layout(); if (!l) return nullptr; m_layout = nullptr; @@ -199,39 +186,35 @@ ObjectTypeLayout* ObjectType::takeLayout() return l; } -unsigned int -objectTypeHash(const ObjectType* objectType) +unsigned int objectTypeHash(const ObjectType *objectType) { return reinterpret_cast<std::size_t>(objectType); } -unsigned char -ObjectType::callWithEnum(const Str& prefix, Event::EventType type, unsigned char value){ - return value*value; +unsigned char ObjectType::callWithEnum(const Str &, Event::EventType, unsigned char value) +{ + return value * value; } -unsigned char -ObjectType::callWithEnum(const Str& prefix, unsigned char value) { +unsigned char ObjectType::callWithEnum(const Str &, unsigned char value) +{ return value; } -void -ObjectType::setObjectSplittedName(const char*, const Str& prefix, const Str& suffix) +void ObjectType::setObjectSplittedName(const char *, const Str &prefix, const Str &suffix) { std::string result(prefix.cstring()); result += suffix.cstring(); m_objectName = result.c_str(); } -void -ObjectType::setObjectNameWithSize(const char*, int size, const Str& name) +void ObjectType::setObjectNameWithSize(const char *, int size, const Str &name) { std::string result(name.cstring(), size); m_objectName = result.c_str(); } -void -ObjectType::setObjectNameWithSize(const Str& name, int size) +void ObjectType::setObjectNameWithSize(const Str &name, int size) { setObjectNameWithSize("", size, name); } @@ -251,37 +234,31 @@ int ObjectType::callId() const return m_call_id; } - void ObjectType::callVirtualCreateChild() { - ObjectType* fake_parent = new ObjectType(); - ObjectType* fake_child = createChild(fake_parent); + auto *fake_parent = new ObjectType(); + ObjectType *fake_child = createChild(fake_parent); assert(fake_child->isPython()); (void)fake_child; delete fake_parent; } -ObjectType* ObjectType::createChild(ObjectType* parent) +ObjectType *ObjectType::createChild(ObjectType *parent) { return new ObjectType(parent); } std::size_t ObjectType::createObjectType() { - void* addr = new ObjectType(); + void *addr = new ObjectType(); return (std::size_t) addr; } -OtherBase::~OtherBase() -{ -} +OtherBase::~OtherBase() = default; -ObjectTypeDerived::~ObjectTypeDerived() -{ -} +ObjectTypeDerived::~ObjectTypeDerived() = default; -bool -ObjectTypeDerived::event(Event* event) +bool ObjectTypeDerived::event(Event *) { return true; } |