QFlags: don't provide a constructor from void**
[profile/ivi/qtbase.git] / src / corelib / global / qflags.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtCore module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QFLAGS_H
43 #define QFLAGS_H
44
45 #include <QtCore/qglobal.h>
46 #include <QtCore/qtypeinfo.h>
47
48 QT_BEGIN_HEADER
49
50 QT_BEGIN_NAMESPACE
51
52 class QFlag
53 {
54     int i;
55 public:
56     Q_DECL_CONSTEXPR inline QFlag(int i);
57     Q_DECL_CONSTEXPR inline operator int() const { return i; }
58 };
59 Q_DECLARE_TYPEINFO(QFlag, Q_PRIMITIVE_TYPE);
60
61 Q_DECL_CONSTEXPR inline QFlag::QFlag(int ai) : i(ai) {}
62
63 class QIncompatibleFlag
64 {
65     int i;
66 public:
67     Q_DECL_CONSTEXPR inline explicit QIncompatibleFlag(int i);
68     Q_DECL_CONSTEXPR inline operator int() const { return i; }
69 };
70 Q_DECLARE_TYPEINFO(QIncompatibleFlag, Q_PRIMITIVE_TYPE);
71
72 Q_DECL_CONSTEXPR inline QIncompatibleFlag::QIncompatibleFlag(int ai) : i(ai) {}
73
74
75 #ifndef Q_NO_TYPESAFE_FLAGS
76
77 template<typename Enum>
78 class QFlags
79 {
80     struct Private;
81     typedef int (Private::*Zero);
82     int i;
83 public:
84     typedef Enum enum_type;
85     // compiler-generated copy/move ctor/assignment operators are fine!
86 #ifdef qdoc
87     inline QFlags(const QFlags &other);
88     inline QFlags &operator=(const QFlags &other);
89 #endif
90     Q_DECL_CONSTEXPR inline QFlags(Enum f) : i(f) {}
91     Q_DECL_CONSTEXPR inline QFlags(Zero = 0) : i(0) {}
92     Q_DECL_CONSTEXPR inline QFlags(QFlag f) : i(f) {}
93
94     inline QFlags &operator&=(int mask) { i &= mask; return *this; }
95     inline QFlags &operator&=(uint mask) { i &= mask; return *this; }
96     inline QFlags &operator|=(QFlags f) { i |= f.i; return *this; }
97     inline QFlags &operator|=(Enum f) { i |= f; return *this; }
98     inline QFlags &operator^=(QFlags f) { i ^= f.i; return *this; }
99     inline QFlags &operator^=(Enum f) { i ^= f; return *this; }
100
101     Q_DECL_CONSTEXPR  inline operator int() const { return i; }
102
103     Q_DECL_CONSTEXPR inline QFlags operator|(QFlags f) const { return QFlags(Enum(i | f.i)); }
104     Q_DECL_CONSTEXPR inline QFlags operator|(Enum f) const { return QFlags(Enum(i | f)); }
105     Q_DECL_CONSTEXPR inline QFlags operator^(QFlags f) const { return QFlags(Enum(i ^ f.i)); }
106     Q_DECL_CONSTEXPR inline QFlags operator^(Enum f) const { return QFlags(Enum(i ^ f)); }
107     Q_DECL_CONSTEXPR inline QFlags operator&(int mask) const { return QFlags(Enum(i & mask)); }
108     Q_DECL_CONSTEXPR inline QFlags operator&(uint mask) const { return QFlags(Enum(i & mask)); }
109     Q_DECL_CONSTEXPR inline QFlags operator&(Enum f) const { return QFlags(Enum(i & f)); }
110     Q_DECL_CONSTEXPR inline QFlags operator~() const { return QFlags(Enum(~i)); }
111
112     Q_DECL_CONSTEXPR inline bool operator!() const { return !i; }
113
114     Q_DECL_CONSTEXPR inline bool testFlag(Enum f) const { return (i & f) == f && (f != 0 || i == int(f) ); }
115 };
116
117 #define Q_DECLARE_FLAGS(Flags, Enum)\
118 typedef QFlags<Enum> Flags;
119
120 #define Q_DECLARE_INCOMPATIBLE_FLAGS(Flags) \
121 Q_DECL_CONSTEXPR inline QIncompatibleFlag operator|(Flags::enum_type f1, int f2) \
122 { return QIncompatibleFlag(int(f1) | f2); }
123
124 #define Q_DECLARE_OPERATORS_FOR_FLAGS(Flags) \
125 Q_DECL_CONSTEXPR inline QFlags<Flags::enum_type> operator|(Flags::enum_type f1, Flags::enum_type f2) \
126 { return QFlags<Flags::enum_type>(f1) | f2; } \
127 Q_DECL_CONSTEXPR inline QFlags<Flags::enum_type> operator|(Flags::enum_type f1, QFlags<Flags::enum_type> f2) \
128 { return f2 | f1; } Q_DECLARE_INCOMPATIBLE_FLAGS(Flags)
129
130
131 #else /* Q_NO_TYPESAFE_FLAGS */
132
133 #define Q_DECLARE_FLAGS(Flags, Enum)\
134 typedef uint Flags;
135 #define Q_DECLARE_OPERATORS_FOR_FLAGS(Flags)
136
137 #endif /* Q_NO_TYPESAFE_FLAGS */
138
139 QT_END_NAMESPACE
140
141 QT_END_HEADER
142
143 #endif // QFLAGS_H