source: SMSSender/common/utils/smacros.h @ 315:e6c8bb244ecd

separation-frontend-backend
Last change on this file since 315:e6c8bb244ecd was 315:e6c8bb244ecd, checked in by Sämy Zehnder <saemy.zehnder@…>, 6 years ago
  • Separates the frontend from the backend code.
  • At this point the schoolnet gateway is converted only.
  • Removes bc & da prefixes from the filenames.
File size: 2.7 KB
Line 
1/*
2 smssender - A frontend for fast and easy SMS sending over different gateways.
3 Copyright (C) 2007-2012, 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
19#ifndef SMACROS_H_
20#define SMACROS_H_
21
22#include <QHash>
23#include <QMutex>
24#include <QMutexLocker>
25#include <QSharedPointer>
26
27#define SET_IF_DIFFERENT(local, other) \
28if (local != other) { local = other; } else { return; }
29
30
31// **************
32
33#define S_QHASH(Class) \
34uint qHash(const Class& ref);
35
36// --
37
38#define S_QHASH_FRIEND(Class) \
39friend uint (::qHash) (const Class&);
40
41// --
42
43#define S_QHASH_IMPL(Class) \
44uint qHash(const Class& ref) { \
45    Q_ASSERT(ref); \
46    return qHash(QString(#Class)) ^ qHash<Class##Data>(ref.d.data()); \
47}
48
49// **************
50
51/*#define S_SINGLETON(Class) \
52public: \
53    static Class* instance(); \
54\
55protected: \
56    Class(); \
57    Class(const Class& other); \
58    bool operator =(const Class& other); \
59\
60private: \
61    static Class* instance_; \
62\
63    class CGuard { \
64    public: \
65        ~CGuard() { \
66            if (Class::instance_) { \
67                delete Class::instance_; \
68                Class::instance_ = NULL; \
69            } \
70        } \
71    public: \
72        QMutex mutex; \
73    }; \
74    friend class CGuard;
75
76#define S_SINGLETON_IMPL(Class) \
77Class* Class::instance_ = NULL; \
78Class* Class::instance() { \
79    static CGuard guard; /-* To delete the instance at the end *-/ \
80    QMutexLocker locker(&guard.mutex); \
81    if (!instance_) { \
82        instance_ = new Class; \
83    } \
84    return instance_; \
85}*/
86
87#define S_SINGLETON(Class) \
88public: \
89    static QSharedPointer<Class> instance() { \
90        static QMutex mutex; \
91        static QSharedPointer<Class> instance; \
92        \
93        QMutexLocker locker(&mutex); \
94        if (instance.isNull()) { \
95            instance = QSharedPointer<Class>(new Class); \
96        } \
97        return instance; \
98    } \
99\
100private: \
101    Class(); \
102    Class(const Class& other); \
103    bool operator =(const Class& other); \
104\
105private: \
106    static QMutex m_instanceMutex;
107
108
109// If all works correctly, just remove this macro
110#define S_SINGLETON_IMPL(Class)
111
112#endif /* SMACROS_H_ */
Note: See TracBrowser for help on using the repository browser.