[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    koffice/kexi/kexiutils
From:       Jarosław Staniek <staniek () kde ! org>
Date:       2009-09-03 21:50:54
Message-ID: 1252014654.867211.24265.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 1019566 by staniek:

Utils
* Added Setter helper that sets given variable to specified value on destruction. \
Object of type Setter are supposed to be created on the stack.



 M  +24 -0     utils.h  


--- trunk/koffice/kexi/kexiutils/utils.h #1019565:1019566
@@ -536,6 +536,30 @@
     Private * const d;
 };
 
+//! Helper that sets given variable to specified value on destruction
+//! Object of type Setter are supposed to be created on the stack.
+template <typename T>
+class KEXIUTILS_EXPORT Setter
+{
+public:
+    //! Creates a new setter object for variable @a var,
+    //! which will be set to value @a val on setter's destruction.
+    Setter(T* var, const T& val)
+        : m_var(var), m_value(val)
+    {
+    }
+    ~Setter() {
+        if (m_var)
+            *m_var = m_value;
+    }
+    //! Clears the assignment, so the setter
+    //! will not alter the variable on destruction
+    void clear() { m_var = 0; }
+private:
+    T* m_var;
+    const T m_value;
+};
+
 /*! A modified QFrame which sets up sunken styled panel frame style depending
  on the current widget style. The widget also reacts on style changes. */
 class KEXIUTILS_EXPORT KTextEditorFrame : public QFrame


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic