| 1 |
/* |
| 2 |
* Copyright (C) 2013-2015, 2019 by the Konclude Developer Team. |
| 3 |
* |
| 4 |
* This file is part of the reasoning system Konclude. |
| 5 |
* For details and support, see <http://konclude.com/>. |
| 6 |
* |
| 7 |
* Konclude is free software: you can redistribute it and/or modify |
| 8 |
* it under the terms of version 3 of the GNU Lesser General Public |
| 9 |
* License (LGPLv3) as published by the Free Software Foundation. |
| 10 |
* |
| 11 |
* Konclude is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
* GNU (Lesser) General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU (Lesser) General Public |
| 17 |
* License along with Konclude. If not, see <http://www.gnu.org/licenses/>. |
| 18 |
* |
| 19 |
* This file incorporates work covered by the following copyright and |
| 20 |
* permission notice (to be compatible with LGPLv2.1, |
| 21 |
* this code is available/released under GPLv3, |
| 22 |
* see https://www.gnu.org/licenses/gpl-faq.html#AllCompatibility): |
| 23 |
* |
| 24 |
* |
| 25 |
* Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). |
| 26 |
* Contact: http://www.qt-project.org/legal |
| 27 |
* |
| 28 |
* This file is part of the QtCore module of the Qt Toolkit. |
| 29 |
* |
| 30 |
* $QT_BEGIN_LICENSE:LGPL$ |
| 31 |
* Commercial License Usage |
| 32 |
* Licensees holding valid commercial Qt licenses may use this file in |
| 33 |
* accordance with the commercial license agreement provided with the |
| 34 |
* Software or, alternatively, in accordance with the terms contained in |
| 35 |
* a written agreement between you and Digia. For licensing terms and |
| 36 |
* conditions see http://qt.digia.com/licensing. For further information |
| 37 |
* use the contact form at http://qt.digia.com/contact-us. |
| 38 |
* |
| 39 |
* GNU Lesser General Public License Usage |
| 40 |
* Alternatively, this file may be used under the terms of the GNU Lesser |
| 41 |
* General Public License version 2.1 as published by the Free Software |
| 42 |
* Foundation and appearing in the file LICENSE.LGPL included in the |
| 43 |
* packaging of this file. Please review the following information to |
| 44 |
* ensure the GNU Lesser General Public License version 2.1 requirements |
| 45 |
* will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
| 46 |
* |
| 47 |
* In addition, as a special exception, Digia gives you certain additional |
| 48 |
* rights. These rights are described in the Digia Qt LGPL Exception |
| 49 |
* version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
| 50 |
* |
| 51 |
* GNU General Public License Usage |
| 52 |
* Alternatively, this file may be used under the terms of the GNU |
| 53 |
* General Public License version 3.0 as published by the Free Software |
| 54 |
* Foundation and appearing in the file LICENSE.GPL included in the |
| 55 |
* packaging of this file. Please review the following information to |
| 56 |
* ensure the GNU General Public License version 3.0 requirements will be |
| 57 |
* met: http://www.gnu.org/copyleft/gpl.html. |
| 58 |
* |
| 59 |
* |
| 60 |
* $QT_END_LICENSE$ |
| 61 |
* |
| 62 |
* |
| 63 |
*/ |
| 64 |
|
| 65 |
#ifndef KONCLUDE_UTILITIES_CONTAINER_CQTMANAGEDRESTRICTEDMODIFICATIONSET_H |
| 66 |
#define KONCLUDE_UTILITIES_CONTAINER_CQTMANAGEDRESTRICTEDMODIFICATIONSET_H |
| 67 |
|
| 68 |
// Namespace includes |
| 69 |
#include "ContainerSettings.h" |
| 70 |
#include "CQtManagedRestrictedModificationHash.h" |
| 71 |
|
| 72 |
#ifdef KONCLUDE_EMPLOY_QT_MANAGED_RESTRICTED_MODIFICATION_SET_CONTAINER |
| 73 |
|
| 74 |
// Library includes |
| 75 |
#include <QSet> |
| 76 |
#include <QHash> |
| 77 |
|
| 78 |
// Other includes |
| 79 |
#include "Context/CContext.h" |
| 80 |
|
| 81 |
|
| 82 |
// Logger includes |
| 83 |
#include "Logger/CLogger.h" |
| 84 |
|
| 85 |
|
| 86 |
namespace Konclude { |
| 87 |
|
| 88 |
using namespace Context; |
| 89 |
|
| 90 |
namespace Utilities { |
| 91 |
|
| 92 |
namespace Container { |
| 93 |
|
| 94 |
/*! |
| 95 |
* |
| 96 |
* \class CQtManagedRestrictedModificationSet |
| 97 |
* \author Andreas Steigmiller |
| 98 |
* \version 0.1 |
| 99 |
* \brief TODO |
| 100 |
* |
| 101 |
*/ |
| 102 |
template <class T> |
| 103 |
class CQtManagedRestrictedModificationSet |
| 104 |
{ |
| 105 |
typedef CQtManagedRestrictedModificationHash<T, CQtManagedRestrictedModificationHashDummyValue> Hash; |
| 106 |
|
| 107 |
public: |
| 108 |
inline CQtManagedRestrictedModificationSet(CContext* context = nullptr) : mContext(context),mHash(context) {} |
| 109 |
inline CQtManagedRestrictedModificationSet(const CQtManagedRestrictedModificationSet<T> &other) : mHash(other.mHash,nullptr),mContext(nullptr) {} |
| 110 |
inline CQtManagedRestrictedModificationSet(const CQtManagedRestrictedModificationSet<T> &other, CContext* context) : mContext(context),mHash(other.mHash,context) {} |
| 111 |
|
| 112 |
|
| 113 |
CQtManagedRestrictedModificationSet<T>* init(CContext* context = nullptr); |
| 114 |
CQtManagedRestrictedModificationSet<T>* init(const CQtManagedRestrictedModificationSet<T> &other, CContext* context = nullptr); |
| 115 |
CQtManagedRestrictedModificationSet<T>* init(CQtManagedRestrictedModificationSet<T> *other, CContext* context = nullptr); |
| 116 |
|
| 117 |
|
| 118 |
inline CQtManagedRestrictedModificationSet<T> &operator=(const CQtManagedRestrictedModificationSet<T> &other) |
| 119 |
{ mHash.init(other.mHash,mContext); return *this; } |
| 120 |
|
| 121 |
inline bool operator==(const CQtManagedRestrictedModificationSet<T> &other) const |
| 122 |
{ return mHash == other.mHash; } |
| 123 |
inline bool operator!=(const CQtManagedRestrictedModificationSet<T> &other) const |
| 124 |
{ return mHash != other.mHash; } |
| 125 |
|
| 126 |
inline int size() const { return mHash.size(); } |
| 127 |
|
| 128 |
inline bool isEmpty() const { return mHash.isEmpty(); } |
| 129 |
|
| 130 |
inline int capacity() const { return mHash.capacity(); } |
| 131 |
inline void reserve(int size); |
| 132 |
inline void squeeze() { mHash.squeeze(); } |
| 133 |
|
| 134 |
inline void detach() { mHash.detach(); } |
| 135 |
inline bool isDetached() const { return mHash.isDetached(); } |
| 136 |
inline void setSharable(bool sharable) { mHash.setSharable(sharable); } |
| 137 |
|
| 138 |
inline void clear() { mHash.clear(); } |
| 139 |
|
| 140 |
inline bool remove(const T &value) { return mHash.remove(value) != 0; } |
| 141 |
|
| 142 |
inline bool contains(const T &value) const { return mHash.contains(value); } |
| 143 |
|
| 144 |
bool contains(const CQtManagedRestrictedModificationSet<T> &set) const; |
| 145 |
|
| 146 |
class const_iterator; |
| 147 |
|
| 148 |
class iterator |
| 149 |
{ |
| 150 |
typedef CQtManagedRestrictedModificationHash<T, CQtManagedRestrictedModificationHashDummyValue> Hash; |
| 151 |
typename Hash::iterator i; |
| 152 |
friend class const_iterator; |
| 153 |
|
| 154 |
public: |
| 155 |
typedef std::bidirectional_iterator_tag iterator_category; |
| 156 |
typedef qptrdiff difference_type; |
| 157 |
typedef T value_type; |
| 158 |
typedef const T *pointer; |
| 159 |
typedef const T &reference; |
| 160 |
|
| 161 |
inline iterator() {} |
| 162 |
inline iterator(typename Hash::iterator o) : i(o) {} |
| 163 |
inline iterator(const iterator &o) : i(o.i) {} |
| 164 |
inline iterator &operator=(const iterator &o) { i = o.i; return *this; } |
| 165 |
inline const T &operator*() const { return i.key(); } |
| 166 |
inline const T *operator->() const { return &i.key(); } |
| 167 |
inline bool operator==(const iterator &o) const { return i == o.i; } |
| 168 |
inline bool operator!=(const iterator &o) const { return i != o.i; } |
| 169 |
inline bool operator==(const const_iterator &o) const |
| 170 |
{ return i == o.i; } |
| 171 |
inline bool operator!=(const const_iterator &o) const |
| 172 |
{ return i != o.i; } |
| 173 |
inline iterator &operator++() { ++i; return *this; } |
| 174 |
inline iterator operator++(int) { iterator r = *this; ++i; return r; } |
| 175 |
inline iterator &operator--() { --i; return *this; } |
| 176 |
inline iterator operator--(int) { iterator r = *this; --i; return r; } |
| 177 |
inline iterator operator+(int j) const { return i + j; } |
| 178 |
inline iterator operator-(int j) const { return i - j; } |
| 179 |
inline iterator &operator+=(int j) { i += j; return *this; } |
| 180 |
inline iterator &operator-=(int j) { i -= j; return *this; } |
| 181 |
}; |
| 182 |
|
| 183 |
class const_iterator |
| 184 |
{ |
| 185 |
typedef CQtManagedRestrictedModificationHash<T, CQtManagedRestrictedModificationHashDummyValue> Hash; |
| 186 |
typename Hash::const_iterator i; |
| 187 |
friend class iterator; |
| 188 |
|
| 189 |
public: |
| 190 |
typedef std::bidirectional_iterator_tag iterator_category; |
| 191 |
typedef qptrdiff difference_type; |
| 192 |
typedef T value_type; |
| 193 |
typedef const T *pointer; |
| 194 |
typedef const T &reference; |
| 195 |
|
| 196 |
inline const_iterator() {} |
| 197 |
inline const_iterator(typename Hash::const_iterator o) : i(o) {} |
| 198 |
inline const_iterator(const const_iterator &o) : i(o.i) {} |
| 199 |
inline const_iterator(const iterator &o) |
| 200 |
: i(o.i) {} |
| 201 |
inline const_iterator &operator=(const const_iterator &o) { i = o.i; return *this; } |
| 202 |
inline const T &operator*() const { return i.key(); } |
| 203 |
inline const T *operator->() const { return &i.key(); } |
| 204 |
inline bool operator==(const const_iterator &o) const { return i == o.i; } |
| 205 |
inline bool operator!=(const const_iterator &o) const { return i != o.i; } |
| 206 |
inline const_iterator &operator++() { ++i; return *this; } |
| 207 |
inline const_iterator operator++(int) { const_iterator r = *this; ++i; return r; } |
| 208 |
inline const_iterator &operator--() { --i; return *this; } |
| 209 |
inline const_iterator operator--(int) { const_iterator r = *this; --i; return r; } |
| 210 |
inline const_iterator operator+(int j) const { return i + j; } |
| 211 |
inline const_iterator operator-(int j) const { return i - j; } |
| 212 |
inline const_iterator &operator+=(int j) { i += j; return *this; } |
| 213 |
inline const_iterator &operator-=(int j) { i -= j; return *this; } |
| 214 |
}; |
| 215 |
|
| 216 |
// STL style |
| 217 |
inline iterator begin() { return mHash.begin(); } |
| 218 |
inline const_iterator begin() const { return mHash.begin(); } |
| 219 |
inline const_iterator constBegin() const { return mHash.constBegin(); } |
| 220 |
inline iterator end() { return mHash.end(); } |
| 221 |
inline const_iterator end() const { return mHash.end(); } |
| 222 |
inline const_iterator constEnd() const { return mHash.constEnd(); } |
| 223 |
iterator erase(iterator i) |
| 224 |
{ return mHash.erase(reinterpret_cast<typename Hash::iterator &>(i)); } |
| 225 |
|
| 226 |
// more Qt |
| 227 |
typedef iterator Iterator; |
| 228 |
typedef const_iterator ConstIterator; |
| 229 |
inline int count() const { return mHash.count(); } |
| 230 |
inline const_iterator insert(const T &value) // ### Qt 5: should return an 'iterator' |
| 231 |
{ return static_cast<typename Hash::const_iterator>(mHash.insert(value, |
| 232 |
CQtManagedRestrictedModificationHashDummyValue())); } |
| 233 |
iterator find(const T &value) { return mHash.find(value); } |
| 234 |
const_iterator find(const T &value) const { return mHash.find(value); } |
| 235 |
inline const_iterator constFind(const T &value) const { return find(value); } |
| 236 |
CQtManagedRestrictedModificationSet<T> &unite(const CQtManagedRestrictedModificationSet<T> &other); |
| 237 |
CQtManagedRestrictedModificationSet<T> &intersect(const CQtManagedRestrictedModificationSet<T> &other); |
| 238 |
CQtManagedRestrictedModificationSet<T> &subtract(const CQtManagedRestrictedModificationSet<T> &other); |
| 239 |
|
| 240 |
// STL compatibility |
| 241 |
typedef T key_type; |
| 242 |
typedef T value_type; |
| 243 |
typedef value_type *pointer; |
| 244 |
typedef const value_type *const_pointer; |
| 245 |
typedef value_type &reference; |
| 246 |
typedef const value_type &const_reference; |
| 247 |
typedef qptrdiff difference_type; |
| 248 |
typedef int size_type; |
| 249 |
|
| 250 |
inline bool empty() const { return isEmpty(); } |
| 251 |
// comfort |
| 252 |
inline CQtManagedRestrictedModificationSet<T> &operator<<(const T &value) { insert(value); return *this; } |
| 253 |
inline CQtManagedRestrictedModificationSet<T> &operator|=(const CQtManagedRestrictedModificationSet<T> &other) { unite(other); return *this; } |
| 254 |
inline CQtManagedRestrictedModificationSet<T> &operator|=(const T &value) { insert(value); return *this; } |
| 255 |
inline CQtManagedRestrictedModificationSet<T> &operator&=(const CQtManagedRestrictedModificationSet<T> &other) { intersect(other); return *this; } |
| 256 |
inline CQtManagedRestrictedModificationSet<T> &operator&=(const T &value) |
| 257 |
{ CQtManagedRestrictedModificationSet<T> result; if (contains(value)) result.insert(value); return (*this = result); } |
| 258 |
inline CQtManagedRestrictedModificationSet<T> &operator+=(const CQtManagedRestrictedModificationSet<T> &other) { unite(other); return *this; } |
| 259 |
inline CQtManagedRestrictedModificationSet<T> &operator+=(const T &value) { insert(value); return *this; } |
| 260 |
inline CQtManagedRestrictedModificationSet<T> &operator-=(const CQtManagedRestrictedModificationSet<T> &other) { subtract(other); return *this; } |
| 261 |
inline CQtManagedRestrictedModificationSet<T> &operator-=(const T &value) { remove(value); return *this; } |
| 262 |
inline CQtManagedRestrictedModificationSet<T> operator|(const CQtManagedRestrictedModificationSet<T> &other) const |
| 263 |
{ CQtManagedRestrictedModificationSet<T> result = *this; result |= other; return result; } |
| 264 |
inline CQtManagedRestrictedModificationSet<T> operator&(const CQtManagedRestrictedModificationSet<T> &other) const |
| 265 |
{ CQtManagedRestrictedModificationSet<T> result = *this; result &= other; return result; } |
| 266 |
inline CQtManagedRestrictedModificationSet<T> operator+(const CQtManagedRestrictedModificationSet<T> &other) const |
| 267 |
{ CQtManagedRestrictedModificationSet<T> result = *this; result += other; return result; } |
| 268 |
inline CQtManagedRestrictedModificationSet<T> operator-(const CQtManagedRestrictedModificationSet<T> &other) const |
| 269 |
{ CQtManagedRestrictedModificationSet<T> result = *this; result -= other; return result; } |
| 270 |
#if QT_VERSION < 0x050000 |
| 271 |
// ### Qt 5: remove |
| 272 |
inline CQtManagedRestrictedModificationSet<T> operator|(const CQtManagedRestrictedModificationSet<T> &other) |
| 273 |
{ CQtManagedRestrictedModificationSet<T> result = *this; result |= other; return result; } |
| 274 |
inline CQtManagedRestrictedModificationSet<T> operator&(const CQtManagedRestrictedModificationSet<T> &other) |
| 275 |
{ CQtManagedRestrictedModificationSet<T> result = *this; result &= other; return result; } |
| 276 |
inline CQtManagedRestrictedModificationSet<T> operator+(const CQtManagedRestrictedModificationSet<T> &other) |
| 277 |
{ CQtManagedRestrictedModificationSet<T> result = *this; result += other; return result; } |
| 278 |
inline CQtManagedRestrictedModificationSet<T> operator-(const CQtManagedRestrictedModificationSet<T> &other) |
| 279 |
{ CQtManagedRestrictedModificationSet<T> result = *this; result -= other; return result; } |
| 280 |
#endif |
| 281 |
|
| 282 |
QList<T> toList() const; |
| 283 |
inline QList<T> values() const { return toList(); } |
| 284 |
|
| 285 |
static CQtManagedRestrictedModificationSet<T> fromList(const QList<T> &list); |
| 286 |
|
| 287 |
private: |
| 288 |
Hash mHash; |
| 289 |
CContext* mContext; |
| 290 |
}; |
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
}; // end namespace Container |
| 295 |
|
| 296 |
}; // end namespace Utilities |
| 297 |
|
| 298 |
}; // end namespace Konclude |
| 299 |
|
| 300 |
#include "CQtManagedRestrictedModificationSet.cpp" |
| 301 |
|
| 302 |
#endif // KONCLUDE_EMPLOY_QT_MANAGED_RESTRICTED_MODIFICATION_SET_CONTAINER |
| 303 |
|
| 304 |
#endif // KONCLUDE_UTILITIES_CONTAINER_CQTMANAGEDRESTRICTEDMODIFICATIONSET_H |