source: SMSSender/common/utils/smacros.h @ 319:1ec456878bcb

separation-frontend-backend
Last change on this file since 319:1ec456878bcb was 319:1ec456878bcb, checked in by Sämy Zehnder <saemy.zehnder@…>, 8 years ago
  • Adjusts header guards to follow common pattern based on the filename.
File size: 2.7 KB
Line 
1/*
2 smssender - A frontend for fast and easy SMS sending over different gateways.
3 Copyright (C) 2007-2014, gorrión. See http://smssender.gorrion.ch
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program.  If not, see <http://www.gnu.org/licenses/>.
17*/
18#ifndef COMMON_UTILS_SMACROS_H
19#define COMMON_UTILS_SMACROS_H
20
21#include <QHash>
22#include <QMutex>
23#include <QMutexLocker>
24#include <QSharedPointer>
25
26#define SET_IF_DIFFERENT(local, other) \
27if (local != other) { local = other; } else { return; }
28
29
30// **************
31
32#define S_QHASH(Class) \
33uint qHash(const Class& ref);
34
35// --
36
37#define S_QHASH_FRIEND(Class) \
38friend uint (::qHash) (const Class&);
39
40// --
41
42#define S_QHASH_IMPL(Class) \
43uint qHash(const Class& ref) { \
44    Q_ASSERT(ref); \
45    return qHash(QString(#Class)) ^ qHash<Class##Data>(ref.d.data()); \
46}
47
48// **************
49
50/*#define S_SINGLETON(Class) \
51public: \
52    static Class* instance(); \
53\
54protected: \
55    Class(); \
56    Class(const Class& other); \
57    bool operator =(const Class& other); \
58\
59private: \
60    static Class* instance_; \
61\
62    class CGuard { \
63    public: \
64        ~CGuard() { \
65            if (Class::instance_) { \
66                delete Class::instance_; \
67                Class::instance_ = NULL; \
68            } \
69        } \
70    public: \
71        QMutex mutex; \
72    }; \
73    friend class CGuard;
74
75#define S_SINGLETON_IMPL(Class) \
76Class* Class::instance_ = NULL; \
77Class* Class::instance() { \
78    static CGuard guard; /-* To delete the instance at the end *-/ \
79    QMutexLocker locker(&guard.mutex); \
80    if (!instance_) { \
81        instance_ = new Class; \
82    } \
83    return instance_; \
84}*/
85
86#define S_SINGLETON(Class) \
87public: \
88    static QSharedPointer<Class> instance() { \
89        static QMutex mutex; \
90        static QSharedPointer<Class> instance; \
91        \
92        QMutexLocker locker(&mutex); \
93        if (instance.isNull()) { \
94            instance = QSharedPointer<Class>(new Class); \
95        } \
96        return instance; \
97    } \
98\
99private: \
100    Class(); \
101    Class(const Class& other); \
102    bool operator =(const Class& other); \
103\
104private: \
105    static QMutex m_instanceMutex;
106
107
108// If all works correctly, just remove this macro
109#define S_SINGLETON_IMPL(Class)
110
111#endif /* COMMON_UTILS_SMACROS_H */
Note: See TracBrowser for help on using the repository browser.