swift
Loading...
Searching...
No Matches
swift::misc::CCollection< T > Class Template Reference

Generic ordered container with value semantics. More...

#include <collection.h>

Inheritance diagram for swift::misc::CCollection< T >:
[legend]

Public Types

using key_type = T
 STL compatibility.
using value_type = T
 STL compatibility.
using reference = T &
 STL compatibility.
using const_reference = const T &
 STL compatibility.
using pointer = T *
 STL compatibility.
using const_pointer = const T *
 STL compatibility.
using const_iterator = typename QOrderedSet<T>::const_iterator
 STL compatibility.
using iterator = const_iterator
 STL compatibility.
using difference_type = ptrdiff_t
 STL compatibility.
using size_type = int
 STL compatibility.

Public Member Functions

 CCollection ()=default
 Default constructor.
 CCollection (std::initializer_list< T > il)
 Initializer list constructor.
 CCollection (const CCollection &other)=default
 Copy constructor.
 CCollection (const QList< T > &list)
 Constructor from QList.
 CCollection (CCollection &&other)=default
 Move constructor.
CCollection & operator= (const CCollection &other)=default
 Copy assignment.
CCollection & operator= (CCollection &&other)=default
 Move assignment.
 ~CCollection ()=default
 Destructor.
iterator begin ()
 Returns iterator at the beginning of the collection.
const_iterator begin () const
 Returns iterator at the beginning of the collection.
const_iterator cbegin () const
 Returns iterator at the beginning of the collection.
iterator end ()
 Returns iterator one past the end of the collection.
const_iterator end () const
 Returns const iterator one past the end of the collection.
const_iterator cend () const
 Returns const iterator one past the end of the collection.
void swap (CCollection &other) noexcept
 Swap this collection with another.
size_type size () const
 Returns number of elements in the collection.
bool empty () const
 Returns true if the collection is empty.
bool isEmpty () const
 Synonym for empty.
void clear ()
 Removes all elements in the collection.
iterator insert (const_iterator hint, const T &value)
 For compatibility with std::inserter.
iterator insert (const_iterator hint, T &&value)
 For compatibility with std::inserter.
iterator insert (const T &value)
 Inserts an element into the collection.
iterator insert (T &&value)
 Moves an element into the collection.
void insert (const CCollection &other)
 Inserts all elements from another collection into this collection.
void insert (CCollection &&other)
 Inserts all elements from another collection into this collection. This version moves elements instead of copying.
template<typename I>
void insert (const CRange< I > &range)
 Appends all elements from a range at the end of this collection.
iterator push_back (const T &value)
 Synonym for insert.
iterator push_back (T &&value)
 Synonym for insert.
void push_back (const CCollection &other)
 Synonym for insert.
void push_back (CCollection &&other)
 Synonym for insert.
template<typename I>
void push_back (const CRange< I > &range)
 Synonym for insert.
template<class C>
CCollection makeUnion (const C &other) const
 Returns a collection which is the union of this collection and another container.
template<class C>
CCollection intersection (const C &other) const
 Returns a collection which is the intersection of this collection and another.
template<class C>
CCollection difference (const C &other) const
 Returns a collection which contains all the elements from this collection which are not in the other collection.
iterator erase (iterator pos)
 Remove the element pointed to by the given iterator.
iterator erase (iterator it1, iterator it2)
 Remove the range of elements between two iterators.
iterator find (const T &value)
 Efficient find method using the find of the implementation container. Typically O(log n).
const_iterator find (const T &value) const
 Efficient find method using the find of the implementation container. Typically O(log n).
void remove (const T &object)
 Efficient remove using the find and erase of the implementation container. Typically O(log n).
void remove (const CCollection &other)
 Removes from this collection all of the elements of another collection.
template<class Predicate>
int removeIf (Predicate p)
 Remove elements for which a given predicate returns true.
template<class K0, class V0, class... KeysValues>
int removeIf (K0 k0, V0 v0, KeysValues... keysValues)
 Remove elements matching some particular key/value pair(s).
QList< T > toQList () const
 Convert to a QList.
void marshalToDataStream (QDataStream &stream) const
 Marshal a value to a QDataStream.
void unmarshalFromDataStream (QDataStream &stream)
 Unmarshal a value from a QDataStream.
Public Member Functions inherited from swift::misc::CContainerBase< CCollection< T > >
auto to () const
 Return a new container of a different type, containing the same elements as this one.
int removeIf (K0 k0, V0 v0, KeysValues... keysValues)
 Remove elements matching some particular key/value pair(s).
QJsonObject toJson () const
 Cast to JSON object.
QString toJsonString (QJsonDocument::JsonFormat format=QJsonDocument::Indented) const
 Convenience function JSON as string.
void convertFromJson (const QJsonObject &json)
 Assign from JSON object.
CStatusMessage convertFromJsonNoThrow (const QJsonObject &json, const CLogCategoryList &categories, const QString &prefix)
 Call convertFromJson, catch any CJsonException that is thrown and return it as CStatusMessage.
QString convertToQString (bool i18n=false) const
 Cast as QString.
QStringList toStringList (bool i18n=false) const
 To string list.
void marshallToDbus (QDBusArgument &argument) const
 Marshall without begin/endStructure, for when composed within another object.
void unmarshallFromDbus (const QDBusArgument &argument)
 Unmarshall without begin/endStructure, for when composed within another object.
Public Member Functions inherited from swift::misc::CRangeBase< CCollection< T > >
auto transform (F function) const
 Return a new container generated by applying some transformation function to all elements of this one.
auto findBy (Predicate p) const
 Return a copy containing only those elements for which a given predicate returns true.
const auto & findFirstBy (Predicate p) const
 Return a reference to the first element for which a given predicate returns true. Undefined if there is none.
auto findFirstByOrDefault (Predicate p, const Value &def) const
 Return a copy of the first element for which a given predicate returns true, or a default value if there is none.
bool containsBy (Predicate p) const
 Return true if there is an element for which a given predicate returns true.
bool contains (const T &object) const
 Return true if there is an element equal to given object. Uses the most efficient implementation available in the derived container.
bool equalsBy (const T &other, Predicate c) const
 Return true if this container equals another container according to the given element equality predicate.
bool equalsByKeys (const T &other, Key0 k0, Keys... keys) const
 Return true if this container equals another container, considering only the given element members.
T randomElement () const
 Pick one random element.
CCollection< T > randomElements (int n) const
 Copy n elements from the container at random.
CCollection< T > sampleElements (int n) const
 Copy n elements from the container, randomly selected but evenly distributed.
Public Member Functions inherited from swift::misc::mixin::MetaType< CCollection< T > >
int getMetaTypeId () const
 Returns the Qt meta type ID of this object.
QString getClassName () const
 Class name.
bool isA (int metaTypeId) const
 Returns true if this object is an instance of the class with the given meta type ID, or one of its subclasses.
Public Member Functions inherited from swift::misc::mixin::String< CCollection< T > >
QString toQString (bool i18n=false) const
 Cast as QString.
std::string toStdString (bool i18n=false) const
 To std string.
QString stringForStreaming () const
 String for streaming operators.
Public Member Functions inherited from swift::misc::mixin::Icon< CCollection< T > >
CIcons::CIcons::StandardIconUnknown16 toIcon () const
 As icon, not implemented by all classes.

Friends

bool operator== (const CCollection &a, const CCollection &b)
 Test for equality.
bool operator!= (const CCollection &a, const CCollection &b)
 Test for inequality.

Additional Inherited Members

Static Public Member Functions inherited from swift::misc::CContainerBase< CCollection< T > >
static CCollection< T > fromJson (const QJsonObject &json)
 Static version of convertFromJson.
static CCollection< T > fromJsonNoThrow (const QString &jsonString, bool acceptCacheJson, bool &success, QString &errMsg)
 Static version of convertFromJson.
Static Public Member Functions inherited from swift::misc::mixin::MetaType< CCollection< T > >
static void registerMetadata ()
 Register metadata.
Protected Member Functions inherited from swift::misc::CContainerBase< CCollection< T > >
int getMetaTypeId () const
 Returns the Qt meta type ID of this object.
Static Protected Member Functions inherited from swift::misc::CRangeBase< CCollection< T > >
static bool equalPointers (const T *a, const U *b)
 Efficiently compare addresses of two objects. Return false if types are not compatible.

Detailed Description

template<class T>
class swift::misc::CCollection< T >

Generic ordered container with value semantics.

Template Parameters
Tthe type of elements contained.

Definition at line 109 of file collection.h.

Member Typedef Documentation

◆ const_iterator

template<class T>
using swift::misc::CCollection< T >::const_iterator = typename QOrderedSet<T>::const_iterator

STL compatibility.

Definition at line 134 of file collection.h.

◆ const_pointer

template<class T>
using swift::misc::CCollection< T >::const_pointer = const T *

STL compatibility.

Definition at line 131 of file collection.h.

◆ const_reference

template<class T>
using swift::misc::CCollection< T >::const_reference = const T &

STL compatibility.

Definition at line 125 of file collection.h.

◆ difference_type

template<class T>
using swift::misc::CCollection< T >::difference_type = ptrdiff_t

STL compatibility.

Definition at line 140 of file collection.h.

◆ iterator

template<class T>
using swift::misc::CCollection< T >::iterator = const_iterator

STL compatibility.

Definition at line 137 of file collection.h.

◆ key_type

template<class T>
using swift::misc::CCollection< T >::key_type = T

STL compatibility.

Definition at line 116 of file collection.h.

◆ pointer

template<class T>
using swift::misc::CCollection< T >::pointer = T *

STL compatibility.

Definition at line 128 of file collection.h.

◆ reference

template<class T>
using swift::misc::CCollection< T >::reference = T &

STL compatibility.

Definition at line 122 of file collection.h.

◆ size_type

template<class T>
using swift::misc::CCollection< T >::size_type = int

STL compatibility.

Definition at line 143 of file collection.h.

◆ value_type

template<class T>
using swift::misc::CCollection< T >::value_type = T

STL compatibility.

Definition at line 119 of file collection.h.

Constructor & Destructor Documentation

◆ CCollection() [1/2]

template<class T>
swift::misc::CCollection< T >::CCollection ( std::initializer_list< T > il)
inline

Initializer list constructor.

Definition at line 149 of file collection.h.

◆ CCollection() [2/2]

template<class T>
swift::misc::CCollection< T >::CCollection ( const QList< T > & list)
inline

Constructor from QList.

Definition at line 155 of file collection.h.

Member Function Documentation

◆ begin() [1/2]

template<class T>
iterator swift::misc::CCollection< T >::begin ( )
inline

Returns iterator at the beginning of the collection.

Definition at line 170 of file collection.h.

◆ begin() [2/2]

template<class T>
const_iterator swift::misc::CCollection< T >::begin ( ) const
inline

Returns iterator at the beginning of the collection.

Definition at line 173 of file collection.h.

◆ cbegin()

template<class T>
const_iterator swift::misc::CCollection< T >::cbegin ( ) const
inline

Returns iterator at the beginning of the collection.

Definition at line 176 of file collection.h.

◆ cend()

template<class T>
const_iterator swift::misc::CCollection< T >::cend ( ) const
inline

Returns const iterator one past the end of the collection.

Definition at line 185 of file collection.h.

◆ clear()

template<class T>
void swift::misc::CCollection< T >::clear ( )
inline

Removes all elements in the collection.

Definition at line 200 of file collection.h.

◆ difference()

template<class T>
template<class C>
CCollection swift::misc::CCollection< T >::difference ( const C & other) const
inline

Returns a collection which contains all the elements from this collection which are not in the other collection.

Definition at line 284 of file collection.h.

◆ empty()

template<class T>
bool swift::misc::CCollection< T >::empty ( ) const
inline

Returns true if the collection is empty.

Definition at line 194 of file collection.h.

◆ end() [1/2]

template<class T>
iterator swift::misc::CCollection< T >::end ( )
inline

Returns iterator one past the end of the collection.

Definition at line 179 of file collection.h.

◆ end() [2/2]

template<class T>
const_iterator swift::misc::CCollection< T >::end ( ) const
inline

Returns const iterator one past the end of the collection.

Definition at line 182 of file collection.h.

◆ erase() [1/2]

template<class T>
iterator swift::misc::CCollection< T >::erase ( iterator it1,
iterator it2 )
inline

Remove the range of elements between two iterators.

Returns
An iterator to the position of the next element after the one removed.

Definition at line 297 of file collection.h.

◆ erase() [2/2]

template<class T>
iterator swift::misc::CCollection< T >::erase ( iterator pos)
inline

Remove the element pointed to by the given iterator.

Returns
An iterator to the position of the next element after the one removed.

Definition at line 293 of file collection.h.

◆ find() [1/2]

template<class T>
iterator swift::misc::CCollection< T >::find ( const T & value)
inline

Efficient find method using the find of the implementation container. Typically O(log n).

Returns
An iterator to the position of the found element, or the end iterator if not found.

Definition at line 308 of file collection.h.

◆ find() [2/2]

template<class T>
const_iterator swift::misc::CCollection< T >::find ( const T & value) const
inline

Efficient find method using the find of the implementation container. Typically O(log n).

Returns
An iterator to the position of the found element, or the end iterator if not found.

Definition at line 312 of file collection.h.

◆ insert() [1/7]

template<class T>
void swift::misc::CCollection< T >::insert ( CCollection< T > && other)
inline

Inserts all elements from another collection into this collection. This version moves elements instead of copying.

Definition at line 233 of file collection.h.

◆ insert() [2/7]

template<class T>
void swift::misc::CCollection< T >::insert ( const CCollection< T > & other)
inline

Inserts all elements from another collection into this collection.

Definition at line 229 of file collection.h.

◆ insert() [3/7]

template<class T>
template<typename I>
void swift::misc::CCollection< T >::insert ( const CRange< I > & range)
inline

Appends all elements from a range at the end of this collection.

Definition at line 237 of file collection.h.

◆ insert() [4/7]

template<class T>
iterator swift::misc::CCollection< T >::insert ( const T & value)
inline

Inserts an element into the collection.

Returns
An iterator to the position where value was inserted.

Definition at line 222 of file collection.h.

◆ insert() [5/7]

template<class T>
iterator swift::misc::CCollection< T >::insert ( const_iterator hint,
const T & value )
inline

For compatibility with std::inserter.

Parameters
hintIgnored.
valueThe value to insert.

Definition at line 205 of file collection.h.

◆ insert() [6/7]

template<class T>
iterator swift::misc::CCollection< T >::insert ( const_iterator hint,
T && value )
inline

For compatibility with std::inserter.

Parameters
hintIgnored.
valueThe value to move in.

Definition at line 214 of file collection.h.

◆ insert() [7/7]

template<class T>
iterator swift::misc::CCollection< T >::insert ( T && value)
inline

Moves an element into the collection.

Returns
An iterator to the position where value was inserted.

Definition at line 226 of file collection.h.

◆ intersection()

template<class T>
template<class C>
CCollection swift::misc::CCollection< T >::intersection ( const C & other) const
inline

Returns a collection which is the intersection of this collection and another.

Definition at line 274 of file collection.h.

◆ isEmpty()

template<class T>
bool swift::misc::CCollection< T >::isEmpty ( ) const
inline

Synonym for empty.

Definition at line 197 of file collection.h.

◆ makeUnion()

template<class T>
template<class C>
CCollection swift::misc::CCollection< T >::makeUnion ( const C & other) const
inline

Returns a collection which is the union of this collection and another container.

Definition at line 265 of file collection.h.

◆ marshalToDataStream()

template<class T>
void swift::misc::CCollection< T >::marshalToDataStream ( QDataStream & stream) const
inline

Marshal a value to a QDataStream.

Definition at line 372 of file collection.h.

◆ push_back() [1/5]

template<class T>
void swift::misc::CCollection< T >::push_back ( CCollection< T > && other)
inline

Synonym for insert.

Definition at line 254 of file collection.h.

◆ push_back() [2/5]

template<class T>
void swift::misc::CCollection< T >::push_back ( const CCollection< T > & other)
inline

Synonym for insert.

Definition at line 251 of file collection.h.

◆ push_back() [3/5]

template<class T>
template<typename I>
void swift::misc::CCollection< T >::push_back ( const CRange< I > & range)
inline

Synonym for insert.

Definition at line 258 of file collection.h.

◆ push_back() [4/5]

template<class T>
iterator swift::misc::CCollection< T >::push_back ( const T & value)
inline

Synonym for insert.

Returns
An iterator to the position where value was inserted.

Definition at line 244 of file collection.h.

◆ push_back() [5/5]

template<class T>
iterator swift::misc::CCollection< T >::push_back ( T && value)
inline

Synonym for insert.

Returns
An iterator to the position where value was inserted.

Definition at line 248 of file collection.h.

◆ remove() [1/2]

template<class T>
void swift::misc::CCollection< T >::remove ( const CCollection< T > & other)
inline

Removes from this collection all of the elements of another collection.

Precondition
This sequence must be initialized.

Definition at line 327 of file collection.h.

◆ remove() [2/2]

template<class T>
void swift::misc::CCollection< T >::remove ( const T & object)
inline

Efficient remove using the find and erase of the implementation container. Typically O(log n).

Precondition
The sequence must be initialized.

Definition at line 316 of file collection.h.

◆ removeIf() [1/2]

template<class T>
template<class K0, class V0, class... KeysValues>
int swift::misc::CCollection< T >::removeIf ( K0 k0,
V0 v0,
KeysValues... keysValues )
inline

Remove elements matching some particular key/value pair(s).

Parameters
k0A pointer to a member function of T.
v0A value to compare against the value returned by k0.
keysValuesZero or more additional pairs of { pointer to member function of T, value to compare it against }.
Returns
The number of elements removed.

Definition at line 353 of file collection.h.

◆ removeIf() [2/2]

template<class T>
template<class Predicate>
int swift::misc::CCollection< T >::removeIf ( Predicate p)
inline

Remove elements for which a given predicate returns true.

Precondition
The collection must be initialized.
Returns
The number of elements removed.

Definition at line 333 of file collection.h.

◆ size()

template<class T>
size_type swift::misc::CCollection< T >::size ( ) const
inline

Returns number of elements in the collection.

Definition at line 191 of file collection.h.

◆ swap()

template<class T>
void swift::misc::CCollection< T >::swap ( CCollection< T > & other)
inlinenoexcept

Swap this collection with another.

Definition at line 188 of file collection.h.

◆ toQList()

template<class T>
QList< T > swift::misc::CCollection< T >::toQList ( ) const
inline

Convert to a QList.

Definition at line 360 of file collection.h.

◆ unmarshalFromDataStream()

template<class T>
void swift::misc::CCollection< T >::unmarshalFromDataStream ( QDataStream & stream)
inline

Unmarshal a value from a QDataStream.

Definition at line 375 of file collection.h.

◆ operator!=

template<class T>
bool operator!= ( const CCollection< T > & a,
const CCollection< T > & b )
friend

Test for inequality.

Definition at line 369 of file collection.h.

◆ operator==

template<class T>
bool operator== ( const CCollection< T > & a,
const CCollection< T > & b )
friend

Test for equality.

Definition at line 366 of file collection.h.


The documentation for this class was generated from the following file: