aboutsummaryrefslogtreecommitdiffstats
path: root/SQLiteStudio3/coreSQLiteStudio/common/global.h
diff options
context:
space:
mode:
authorLibravatarUnit 193 <unit193@ubuntu.com>2014-12-06 17:33:25 -0500
committerLibravatarUnit 193 <unit193@ubuntu.com>2014-12-06 17:33:25 -0500
commit7167ce41b61d2ba2cdb526777a4233eb84a3b66a (patch)
treea35c14143716e1f2c98f808c81f89426045a946f /SQLiteStudio3/coreSQLiteStudio/common/global.h
Imported Upstream version 2.99.6upstream/2.99.6
Diffstat (limited to 'SQLiteStudio3/coreSQLiteStudio/common/global.h')
-rw-r--r--SQLiteStudio3/coreSQLiteStudio/common/global.h66
1 files changed, 66 insertions, 0 deletions
diff --git a/SQLiteStudio3/coreSQLiteStudio/common/global.h b/SQLiteStudio3/coreSQLiteStudio/common/global.h
new file mode 100644
index 0000000..bc228ca
--- /dev/null
+++ b/SQLiteStudio3/coreSQLiteStudio/common/global.h
@@ -0,0 +1,66 @@
+#ifndef GLOBAL_H
+#define GLOBAL_H
+
+/** @file */
+
+#define DEEP_COPY_FIELD(T, F) \
+ if (other.F) \
+ { \
+ F = new T(*other.F); \
+ F->setParent(this); \
+ }
+
+#define DEEP_COPY_COLLECTION(T, F) \
+ T* _new##T; \
+ foreach (T* _element, other.F) \
+ { \
+ _new##T = new T(*_element); \
+ _new##T->setParent(this); \
+ F << _new##T; \
+ }
+
+/**
+ * @brief Deletes object and sets the pointer to null.
+ *
+ * Deletes object under given pointer, but only if the pointer is not null.
+ * Also sets the pointer to the null after deleting is done.
+ */
+#define safe_delete(var) \
+ if (var) \
+ { \
+ delete var; \
+ var = nullptr; \
+ }
+
+#define static_char static constexpr const char
+
+#define static_qstring(N,V) const static QString N = QStringLiteral(V)
+
+#define DECLARE_SINGLETON(Cls) \
+ public: \
+ static Cls* getInstance(); \
+ static void destroy(); \
+ \
+ private: \
+ static Cls* _instance;
+
+#define DEFINE_SINGLETON(Cls) \
+ Cls* Cls::_instance = nullptr; \
+ \
+ Cls* Cls::getInstance() \
+ { \
+ if (!_instance) \
+ _instance = new Cls(); \
+ \
+ return _instance; \
+ } \
+ \
+ void Cls::destroy() \
+ { \
+ safe_delete(_instance); \
+ }
+
+#define STRINGIFY(s) _STRINGIFY(s)
+#define _STRINGIFY(s) #s
+
+#endif // GLOBAL_H