aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken2/tests/libsmart/smart.cpp
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2019-11-12 15:58:15 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2019-11-14 09:03:25 +0100
commit03e233550f2c49797c69080d4923e46f2d82d98c (patch)
tree082d1b98a617ed9cd8068754ecd0dc0a689c4ae5 /sources/shiboken2/tests/libsmart/smart.cpp
parentda5f43b6cbecac437f80fbb1b1405292b3962d3b (diff)
shiboken: Split the headers of libsmart
Prepare for adding further tests. On this occasion, polish the code a bit, move the logging of the shared pointer into a base class to get rid of the iostream include in the header. Task-number: PYSIDE-454 Change-Id: Ifd05a7d3ceeae1c85e7193991907bf6d1e8e98ee Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources/shiboken2/tests/libsmart/smart.cpp')
-rw-r--r--sources/shiboken2/tests/libsmart/smart.cpp49
1 files changed, 45 insertions, 4 deletions
diff --git a/sources/shiboken2/tests/libsmart/smart.cpp b/sources/shiboken2/tests/libsmart/smart.cpp
index 8d85d67a1..6a4deb50a 100644
--- a/sources/shiboken2/tests/libsmart/smart.cpp
+++ b/sources/shiboken2/tests/libsmart/smart.cpp
@@ -28,10 +28,52 @@
#include "smart.h"
-bool shouldPrint() {
+#include <algorithm>
+#include <iostream>
+
+static inline bool shouldPrint()
+{
return Registry::getInstance()->shouldPrint();
}
+void SharedPtrBase::logDefaultConstructor(const void *t)
+{
+ if (shouldPrint())
+ std::cout << "shared_ptr default constructor " << t << '\n';
+}
+
+void SharedPtrBase::logConstructor(const void *t, const void *pointee)
+{
+ if (shouldPrint()) {
+ std::cout << "shared_ptr constructor " << t << " with pointer "
+ << pointee << '\n';
+ }
+}
+
+void SharedPtrBase::logCopyConstructor(const void *t, const void *refData)
+{
+ if (shouldPrint()) {
+ std::cout << "shared_ptr copy constructor " << t << " with pointer "
+ << refData << '\n';
+ }
+}
+
+void SharedPtrBase::logAssignment(const void *t, const void *refData)
+{
+ if (shouldPrint()) {
+ std::cout << "shared_ptr assignment operator " << t << " with pointer "
+ << refData << "\n";
+ }
+}
+
+void SharedPtrBase::logDestructor(const void *t, int remainingRefCount)
+{
+ if (shouldPrint()) {
+ std::cout << "shared_ptr destructor " << t << " remaining refcount "
+ << remainingRefCount << '\n';
+ }
+}
+
Obj::Obj() : m_integer(123), m_internalInteger(new Integer)
{
Registry::getInstance()->add(this);
@@ -143,10 +185,9 @@ Registry *Registry::getInstance()
return &registry;
}
-Registry::Registry() : m_printStuff(false)
-{
+Registry::Registry() = default;
-}
+Registry::~Registry() = default;
void Registry::add(Obj *p)
{