From 36f05628f818530019d7355445a4a35dec2e244a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20H=C3=B6glund?= Date: Mon, 26 Mar 2012 17:20:04 +0200 Subject: [PATCH] kwin: Add a ScopedCPointer class This class is functionally the same as QScopedPointer, but uses free() instead of delete. --- utils.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/utils.h b/utils.h index 8fae0925fb..d880e08b8e 100644 --- a/utils.h +++ b/utils.h @@ -245,6 +245,39 @@ private: T orig; }; +// Light weight scoped pointer class that stores a pointer to a +// dynamically allocated object and automatically free()'s it +// upon destruction. +// +// This class works the same way as QScopedPointer, but uses +// free() instead of delete. +template +class ScopedCPointer +{ +public: + ScopedCPointer() : m_ptr(0) {} + ScopedCPointer(T *ptr) : m_ptr(ptr) {} + ~ScopedCPointer() { if (m_ptr) free(m_ptr); } + + T *data() const { return m_ptr; } + bool isNull() const { return !m_ptr; } + void reset(T *other = 0) { m_ptr = other; } + T *take() { T *ret = m_ptr; m_ptr = 0; return ret; } + + T ** operator & () { return &m_ptr; } + operator bool () const { return bool(m_ptr); } + bool operator ! () const { return !m_ptr; } + operator T * () const { return m_ptr; } + T * operator -> () const { return m_ptr; } + ScopedCPointer & operator = (T *ptr) { m_ptr = ptr; } + +private: + ScopedCPointer & operator = (const ScopedCPointer &); + +private: + T *m_ptr; +}; + QByteArray getStringProperty(WId w, Atom prop, char separator = 0); void updateXTime(); void grabXServer();