6 #ifndef SWIFT_MISC_COLLECTION_H
7 #define SWIFT_MISC_COLLECTION_H
10 #include <initializer_list>
12 #include <type_traits>
23 #define SWIFT_TEMPLATE_COLLECTION_MIXINS(NS, T, Set, Extern) \
28 namespace swift::misc::private_ns \
30 Extern template struct CValueObjectMetaInfo<NS::Set>; \
31 Extern template struct CValueObjectMetaInfo<CCollection<NS::T>>; \
32 Extern template struct MetaTypeHelper<NS::Set>; \
33 Extern template struct MetaTypeHelper<CCollection<NS::T>>; \
35 namespace swift::misc::mixin \
37 Extern template class MetaType<NS::Set>; \
38 Extern template class MetaType<CCollection<NS::T>>; \
39 Extern template class DBusOperators<CCollection<NS::T>>; \
40 Extern template class JsonOperators<CCollection<NS::T>>; \
41 Extern template class String<CCollection<NS::T>>; \
42 Extern template class DataStreamOperators<CCollection<NS::T>>; \
43 Extern template class Icon<CCollection<NS::T>>; \
57 #if defined(Q_OS_WIN) && defined(Q_CC_GNU)
58 # define SWIFT_DECLARE_COLLECTION_MIXINS(Namespace, T, Set)
59 # define SWIFT_DEFINE_COLLECTION_MIXINS(Namespace, T, Set)
61 # define SWIFT_DECLARE_COLLECTION_MIXINS(Namespace, T, Set) \
62 SWIFT_TEMPLATE_COLLECTION_MIXINS(Namespace, T, Set, extern)
63 # define SWIFT_DEFINE_COLLECTION_MIXINS(Namespace, T, Set) SWIFT_TEMPLATE_COLLECTION_MIXINS(Namespace, T, Set, )
88 for (
const auto &v : il) {
insert(v); }
94 for (
const auto &v : list) {
insert(v); }
188 bool empty()
const {
return m_impl.isEmpty(); }
211 return insert(std::move(value));
230 template <
typename I>
233 std::copy(range.
begin(), range.
end(), std::back_inserter(*
this));
251 template <
typename I>
254 std::copy(range.
begin(), range.
end(), std::back_inserter(*
this));
262 std::set_union(
begin(),
end(), other.begin(), other.end(), std::inserter(result, result.
begin()));
271 std::set_intersection(
begin(),
end(), other.begin(), other.end(), std::inserter(result, result.
begin()));
281 std::set_difference(
begin(),
end(), other.begin(), other.end(), std::inserter(result, result.
begin()));
293 while (it1 != it2) { it1 =
erase(it1); }
309 auto it =
find(
object);
320 template <
class Predicate>
324 for (
auto it =
begin(); it !=
end();)
337 template <
class K0,
class V0,
class... KeysValues>
338 int removeIf(K0 k0, V0 v0, KeysValues... keysValues)
341 return CCollection::CContainerBase::removeIf(k0, v0, keysValues...);
345 QList<T>
toQList()
const {
return this->
to(QList<T>()); }
348 void detach() { m_impl.detach(); }
Generic ordered container with value semantics.
friend bool operator==(const CCollection &a, const CCollection &b)
Test for equality.
iterator erase(iterator it1, iterator it2)
Remove the range of elements between two iterators.
const T & const_reference
STL compatibility.
ptrdiff_t difference_type
STL compatibility.
void swap(CCollection &other) noexcept
Swap this collection with another.
void push_back(const CCollection &other)
Synonym for insert.
void insert(CCollection &&other)
Inserts all elements from another collection into this collection. This version moves elements instea...
void unmarshalFromDataStream(QDataStream &stream)
Unmarshal a value from a QDataStream.
iterator insert(const_iterator hint, T &&value)
For compatibility with std::inserter.
CCollection & operator=(CCollection &&other)=default
Move assignment.
const_iterator find(const T &value) const
Efficient find method using the find of the implementation container. Typically O(log n).
size_type size() const
Returns number of elements in the collection.
CCollection difference(const C &other) const
Returns a collection which contains all the elements from this collection which are not in the other ...
void remove(const T &object)
Efficient remove using the find and erase of the implementation container. Typically O(log n).
const_iterator cbegin() const
Returns iterator at the beginning of the collection.
T * pointer
STL compatibility.
iterator insert(const_iterator hint, const T &value)
For compatibility with std::inserter.
CCollection()=default
Default constructor.
T & reference
STL compatibility.
iterator find(const T &value)
Efficient find method using the find of the implementation container. Typically O(log n).
void insert(const CCollection &other)
Inserts all elements from another collection into this collection.
T key_type
STL compatibility.
T value_type
STL compatibility.
CCollection intersection(const C &other) const
Returns a collection which is the intersection of this collection and another.
iterator insert(const T &value)
Inserts an element into the collection.
bool empty() const
Returns true if the collection is empty.
CCollection(const CCollection &other)=default
Copy constructor.
typename QOrderedSet< T >::const_iterator const_iterator
STL compatibility.
iterator begin()
Returns iterator at the beginning of the collection.
const_iterator end() const
Returns const iterator one past the end of the collection.
int size_type
STL compatibility.
const_iterator iterator
STL compatibility.
void push_back(const CRange< I > &range)
Synonym for insert.
bool isEmpty() const
Synonym for empty.
int removeIf(Predicate p)
Remove elements for which a given predicate returns true.
friend bool operator!=(const CCollection &a, const CCollection &b)
Test for inequality.
CCollection(const QList< T > &list)
Constructor from QList.
iterator push_back(T &&value)
Synonym for insert.
CCollection makeUnion(const C &other) const
Returns a collection which is the union of this collection and another container.
void insert(const CRange< I > &range)
Appends all elements from a range at the end of this collection.
void push_back(CCollection &&other)
Synonym for insert.
const_iterator cend() const
Returns const iterator one past the end of the collection.
iterator push_back(const T &value)
Synonym for insert.
CCollection(std::initializer_list< T > il)
Initializer list constructor.
void clear()
Removes all elements in the collection.
iterator erase(iterator pos)
Remove the element pointed to by the given iterator.
int removeIf(K0 k0, V0 v0, KeysValues... keysValues)
Remove elements matching some particular key/value pair(s).
const T * const_pointer
STL compatibility.
QList< T > toQList() const
Convert to a QList.
void remove(const CCollection &other)
Removes from this collection all of the elements of another collection.
iterator insert(T &&value)
Moves an element into the collection.
void marshalToDataStream(QDataStream &stream) const
Marshal a value to a QDataStream.
~CCollection()=default
Destructor.
iterator end()
Returns iterator one past the end of the collection.
CCollection(CCollection &&other)=default
Move constructor.
const_iterator begin() const
Returns iterator at the beginning of the collection.
CCollection & operator=(const CCollection &other)=default
Copy assignment.
Base class for CCollection and CSequence adding mutating operations and CValueObject facility on top ...
auto to() const
Return a new container of a different type, containing the same elements as this one.
A range is a conceptual container which does not contain any elements of its own, but is constructed ...
const_iterator end() const
Begin and end iterators.
const_iterator begin() const
Begin and end iterators.
Needed for compatibility with C++ standard algorithms which expect ordered sets.
T value_type
Type of values stored in the set.
QOrderedSet(std::initializer_list< T > il)
Initializer list constructor.
QOrderedSet()=default
Default constructor.
QMap< T, T >::iterator insert(const T &value)
Insert a new value into the set.
QOrderedSet(const QList< T > &list)
Constructor from QList.
CRTP class template to generate non-member QDataStream streaming operators.
CRTP class template from which a derived class can inherit icon-related functions.
Free functions in swift::misc.