| QxOrm 1.2.7 C++ Object Relational Mapping library

- Main Page
- Modules
- Namespaces
- Classes
- Files
- Directories

- Class List
- Class Index
- Class Hierarchy
- Class Members

Classes | Public Types | Public Member Functions | Protected Types | Protected Attributes | Private Member Functions
qx::QxCollection< Key, Value > Class Template Reference
QxCollection : QxOrm library container (keep insertion order + quick access by index + quick access by key)

qx::QxCollection<Key, Value> : QxOrm container (keep insertion order + quick access by index + quick access by key) More...

`#include <QxCollection.h>`

Inheritance diagram for qx::QxCollection< Key, Value >:

List of all members.

## Classes
struct | compareKeyValue
struct | compareKeyValue< true, dummy >
## Public Types
typedef QPair< Key, Value > | type_pair_key_value
typedef type_index_rand::iterator | iterator
typedef type_index_rand::const_iterator | const_iterator
typedef type_index_rand::reverse_iterator | reverse_iterator
typedef type_index_rand::const_reverse_iterator | const_reverse_iterator
typedef const Key & | const_reference_key
typedef const Value & | const_reference_value
## Public Member Functions
| QxCollection ()
| Construct an empty list.
| QxCollection (const QxCollection< Key, Value > &other)
| Construct a copy of 'other'.
virtual | ~QxCollection ()
| Destroy the list.
QxCollection< Key, Value > & | operator= (const QxCollection< Key, Value > &other)
| Assign 'other' to this list and return a reference to this list.
bool | operator== (const QxCollection< Key, Value > &other) const
| Return 'true' if 'other' is equal to this list, otherwise return 'false' (same values in the same order)
bool | operator!= (const QxCollection< Key, Value > &other) const
| Return 'true' if 'other' is not equal to this list, otherwise return 'false'.
iterator | begin ()
| Return an STL-style iterator pointing to the first item in the list.
iterator | end ()
| Return an STL-style iterator pointing to the imaginary item after the last item in the list.
const_iterator | begin () const
| Return a const STL-style iterator pointing to the first item in the list.
const_iterator | end () const
| Return a const STL-style iterator pointing to the imaginary item after the last item in the list.
reverse_iterator | rbegin ()
| Return a reverse STL-style iterator pointing to the first item in the list.
reverse_iterator | rend ()
| Return a reverse STL-style iterator pointing to the imaginary item after the last item in the list.
const_reverse_iterator | rbegin () const
| Return a const reverse STL-style iterator pointing to the first item in the list.
const_reverse_iterator | rend () const
| Return a const reverse STL-style iterator pointing to the imaginary item after the last item in the list.
long | capacity () const
| Return size of allocated storage capacity.
void | reserve (long size)
| Request that the capacity of the allocated storage space for the items of the container be at least enough to hold 'size' elements.
void | reverse ()
| Reverse all items in the list.
void | clear ()
| Remove all items from the list.
long | count () const
| Return the number of items in the list (same as 'size()')
long | size () const
| Return the number of items in the list (same as 'count()')
bool | contains (const Key &key) const
| Return 'true' if the list contains an occurrence of 'key', otherwise return 'false' (same as 'exist()')
bool | exist (const Key &key) const
| Return 'true' if the list contains an occurrence of 'key', otherwise return 'false' (same as 'contains()')
bool | empty () const
| Return 'true' if the list contains no items; otherwise return 'false'.
bool | push_back (const Key &key, const Value &value)
| Add element 'value' at the end of the list indexed by 'key'.
bool | push_front (const Key &key, const Value &value)
| Insert 'value' at the beginning of the list indexed by 'key'.
bool | insert (const Key &key, const Value &value)
| Add element 'value' at the end of the list indexed by 'key'.
bool | insert (long index, const Key &key, const Value &value)
| Insert element 'value' at position 'index' in the list indexed by 'key'.
bool | insert (const QxCollection< Key, Value > &other)
| Add all items of 'other' at the end of the list.
bool | insert (long index, const QxCollection< Key, Value > &other)
| Insert all items of 'other' at the end of the list.
bool | replace (long index, const Key &key, const Value &value)
| Replace the item at index position 'index' with element 'value' indexed by 'key'.
bool | swap (long index1, long index2)
| Exchange the item at index position 'index1' with the item at index position 'index2'.
bool | move (long indexFrom, long indexTo)
| Move the item at index position 'indexFrom' to index position 'indexTo'.
bool | removeByKey (const Key &key)
| Remove the item indexed by 'key' in the list.
bool | removeByIndex (long index)
| Remove the item at index position 'index'.
bool | removeByIndex (long first, long last)
| Remove all items from index position 'first' to index position 'last'.
bool | removeFirst ()
| Remove the first item in the list.
bool | removeLast ()
| Remove the last item in the list.
const_reference_value | getByKey (const Key &key) const
| Return the item associated with the 'key'.
const_reference_value | getByIndex (long index) const
| Return the item at index position 'index'.
const_reference_value | getFirst () const
| Return the first element in the list.
const_reference_value | getLast () const
| Return the last element in the list.
const_reference_key | getKeyByIndex (long index) const
| Return the key associated with the element at index position 'index'.
void | sortByKey (bool bAscending=true)
| Sort all items in the list using associated keys to compare.
void | sortByValue (bool bAscending=true)
| Sort all items in the list.
template<typename Compare >
void | sort (Compare comp)
virtual long | _count () const
virtual void | _clear ()
virtual bool | _remove (long index)
virtual boost::any | _at (long index) const
## Protected Types
typedef boost::multi_index::member < type_pair_key_value, Key,&type_pair_key_value::first > | type_member
typedef boost::multi_index::random_access | type_first_index
typedef boost::multi_index::hashed_unique < type_member > | type_second_index
typedef boost::multi_index::indexed_by < type_first_index, type_second_index > | type_indexed_by
typedef boost::multi_index::multi_index_container < type_pair_key_value, type_indexed_by > | type_container
typedef type_container::template nth_index< 0 >::type | type_index_rand
typedef type_container::template nth_index< 1 >::type | type_index_hash
## Protected Attributes
type_container | m_qxCollection
| Collection with random access (like std::vector) and fast lookup by key (like boost::unordered_map)
## Private Member Functions
void | cloneCollection (QxCollection< Key, Value > *pClone, const QxCollection< Key, Value > &pRef)
bool | isSameCollection (const QxCollection< Key, Value > *p1, const QxCollection< Key, Value > &p2) const

## Detailed Description

### template<typename Key, typename Value>
class qx::QxCollection< Key, Value >

qx::QxCollection<Key, Value> : QxOrm container (keep insertion order + quick access by index + quick access by key)

Based on boost::multi_index_container, this collection has advantages of std::vector<T> (keep insertion order + quick access by index) and boost::unordered_map<Key, Value> or QHash<Key, Value> (quick access by key : hash-map).

Note : qx::QxCollection<Key, Value> is compatible with the foreach macro provided by Qt library and the BOOST_FOREACH macro provided by boost library. However, each element returned by these 2 macros corresponds to an object of type std::pair<Key, Value>. To obtain a more natural and more readable result, it is advised to use the _foreach macro : this macro uses BOOST_FOREACH for all the containers except for qx::QxCollection<Key, Value>. In this case, the returned element corresponds to the Value type (cf. following sample). The macro _foreach is compatible with all containers (stl, Qt, boost...) since it uses the macro BOOST_FOREACH.

Additional note : qx::QxCollection<Key, Value> is particularly suited to receive data resulting from a database. Indeed, these data can be sorted (by using ORDER BY in a SQL request for example), it is thus important to preserve the insertion order of the elements in the list. Furthermore, each data resulting from a database has a unique id. It is thus important to be able to access quickly to an element based on this single identifier (hash-map).

Quick sample using qx::QxCollection<Key, Value> container :

    // definition of drug class with 3 properties : 'code', 'name' and 'description'
    class drug { public: QString code; QString name; QString desc; };

    // typedef a smart-pointer of drug class
    typedef boost::shared_ptr<drug> drug_ptr;

    // collection of drugs indexed by 'code' property (QString type)
    qx::QxCollection<QString, drug_ptr> lstDrugs;

    // create 3 new drugs
    drug_ptr d1; d1.reset(new drug()); d1->code = "code1"; d1->name = "name1"; d1->desc = "desc1";
    drug_ptr d2; d2.reset(new drug()); d2->code = "code2"; d2->name = "name2"; d2->desc = "desc2";
    drug_ptr d3; d3.reset(new drug()); d3->code = "code3"; d3->name = "name3"; d3->desc = "desc3";

    // insert 3 drugs into the collection
    lstDrugs.insert(d1->code, d1);
    lstDrugs.insert(d2->code, d2);
    lstDrugs.insert(d3->code, d3);

    // iterate over drugs container using QxOrm '_foreach' keyword
    _foreach(drug_ptr p, lstDrugs)
    { qDebug() << qPrintable(p->name) << " " << qPrintable(p->desc); }

    // iterate over drugs container using classic C++ 'for' keyword
    for (long l = 0; l < lstDrugs.count(); ++l)
    {
       drug_ptr p = lstDrugs.getByIndex(l);
       QString code = lstDrugs.getKeyByIndex(l);
       qDebug() << qPrintable(p->name) << " " << qPrintable(p->desc);
    }

    // iterate over drugs container using 'qx::QxCollectionIterator' Java-style iterator
    qx::QxCollectionIterator<QString, drug_ptr> itr(lstDrugs);
    while (itr.next())
    {
       QString code = itr.key();
       qDebug() << qPrintable(itr.value()->name) << " " << qPrintable(itr.value()->desc);
    }

    // sort drugs container ascending by key and sort descending by value
    lstDrugs.sortByKey(true);
    lstDrugs.sortByValue(false);

    // access to a drug into the collection by its 'code' property
    drug_ptr p = lstDrugs.getByKey("code2");

    // access to a drug into the collection by index (position in the list)
    drug_ptr p = lstDrugs.getByIndex(2);

    // test if a drug exists into the collection and if the collection is empty
    bool bExist = lstDrugs.exist("code3");
    bool bEmpty = lstDrugs.empty();

    // remove the second drug from the collection
    lstDrugs.removeByIndex(2);

    // remove a drug from the collection using its 'code' property
    lstDrugs.removeByKey("code3");

    // clear the collection : remove all items from the list
    lstDrugs.clear();

Definition at line 153 of file QxCollection.h.

## Member Typedef Documentation

template<typename Key, typename Value>

typedef type_index_rand::const_iterator qx::QxCollection< Key, Value >::const_iterator

Definition at line 174 of file QxCollection.h.

template<typename Key, typename Value>

typedef const Key& qx::QxCollection< Key, Value >::const_reference_key

Definition at line 178 of file QxCollection.h.

template<typename Key, typename Value>

typedef const Value& qx::QxCollection< Key, Value >::const_reference_value

Definition at line 179 of file QxCollection.h.

template<typename Key, typename Value>

typedef type_index_rand::const_reverse_iterator qx::QxCollection< Key, Value >::const_reverse_iterator

Definition at line 176 of file QxCollection.h.

template<typename Key, typename Value>

typedef type_index_rand::iterator qx::QxCollection< Key, Value >::iterator

Definition at line 173 of file QxCollection.h.

template<typename Key, typename Value>

typedef type_index_rand::reverse_iterator qx::QxCollection< Key, Value >::reverse_iterator

Definition at line 175 of file QxCollection.h.

template<typename Key, typename Value>

typedef boost::multi_index::multi_index_container<type_pair_key_value, type_indexed_by> qx::QxCollection< Key, Value >::type_container`[protected]`

Definition at line 166 of file QxCollection.h.

template<typename Key, typename Value>

typedef boost::multi_index::random_access qx::QxCollection< Key, Value >::type_first_index`[protected]`

Definition at line 163 of file QxCollection.h.

template<typename Key, typename Value>

typedef type_container::template nth_index<1>::type qx::QxCollection< Key, Value >::type_index_hash`[protected]`

Definition at line 169 of file QxCollection.h.

template<typename Key, typename Value>

typedef type_container::template nth_index<0>::type qx::QxCollection< Key, Value >::type_index_rand`[protected]`

Definition at line 168 of file QxCollection.h.

template<typename Key, typename Value>

typedef boost::multi_index::indexed_by<type_first_index, type_second_index> qx::QxCollection< Key, Value >::type_indexed_by`[protected]`

Definition at line 165 of file QxCollection.h.

template<typename Key, typename Value>

typedef boost::multi_index::member<type_pair_key_value, Key, & type_pair_key_value::first> qx::QxCollection< Key, Value >::type_member`[protected]`

Definition at line 162 of file QxCollection.h.

template<typename Key, typename Value>

typedef QPair<Key, Value> qx::QxCollection< Key, Value >::type_pair_key_value

Definition at line 158 of file QxCollection.h.

template<typename Key, typename Value>

typedef boost::multi_index::hashed_unique<type_member> qx::QxCollection< Key, Value >::type_second_index`[protected]`

Definition at line 164 of file QxCollection.h.

## Constructor & Destructor Documentation

template<typename Key, typename Value>

qx::QxCollection< Key, Value >::QxCollection | ( |  | ) |

Construct an empty list.

template<typename Key, typename Value>

qx::QxCollection< Key, Value >::QxCollection | ( | const QxCollection< Key, Value > & | other | ) |

Construct a copy of 'other'.

template<typename Key, typename Value>

virtual qx::QxCollection< Key, Value >::~QxCollection | ( |  | ) | `[virtual]`

Destroy the list.

## Member Function Documentation

template<typename Key, typename Value>

virtual boost::any qx::QxCollection< Key, Value >::_at | ( | long | index | ) | const`[inline, virtual]`

Implements qx::IxCollection.

Definition at line 271 of file QxCollection.h.

template<typename Key, typename Value>

virtual void qx::QxCollection< Key, Value >::_clear | ( |  | ) | `[inline, virtual]`

Implements qx::IxCollection.

Definition at line 269 of file QxCollection.h.

template<typename Key, typename Value>

virtual long qx::QxCollection< Key, Value >::_count | ( |  | ) | const`[inline, virtual]`

Implements qx::IxCollection.

Definition at line 268 of file QxCollection.h.

template<typename Key, typename Value>

virtual bool qx::QxCollection< Key, Value >::_remove | ( | long | index | ) | `[inline, virtual]`

Implements qx::IxCollection.

Definition at line 270 of file QxCollection.h.

template<typename Key, typename Value>

iterator qx::QxCollection< Key, Value >::begin | ( |  | ) | `[inline]`

Return an STL-style iterator pointing to the first item in the list.

template<typename Key, typename Value>

const_iterator qx::QxCollection< Key, Value >::begin | ( |  | ) | const`[inline]`

Return a const STL-style iterator pointing to the first item in the list.

template<typename Key, typename Value>

long qx::QxCollection< Key, Value >::capacity | ( |  | ) | const`[inline]`

Return size of allocated storage capacity.

template<typename Key, typename Value>

void qx::QxCollection< Key, Value >::clear | ( |  | ) | `[inline]`

Remove all items from the list.

template<typename Key, typename Value>

void qx::QxCollection< Key, Value >::cloneCollection | ( | QxCollection< Key, Value > * | pClone,
|  | const QxCollection< Key, Value > & | pRef
| ) |  | `[private]`

template<typename Key, typename Value>

bool qx::QxCollection< Key, Value >::contains | ( | const Key & | key | ) | const`[inline]`

Return 'true' if the list contains an occurrence of 'key', otherwise return 'false' (same as 'exist()')

template<typename Key, typename Value>

long qx::QxCollection< Key, Value >::count | ( |  | ) | const`[inline]`

Return the number of items in the list (same as 'size()')

template<typename Key, typename Value>

bool qx::QxCollection< Key, Value >::empty | ( |  | ) | const`[inline]`

Return 'true' if the list contains no items; otherwise return 'false'.

template<typename Key, typename Value>

iterator qx::QxCollection< Key, Value >::end | ( |  | ) | `[inline]`

Return an STL-style iterator pointing to the imaginary item after the last item in the list.

template<typename Key, typename Value>

const_iterator qx::QxCollection< Key, Value >::end | ( |  | ) | const`[inline]`

Return a const STL-style iterator pointing to the imaginary item after the last item in the list.

template<typename Key, typename Value>

bool qx::QxCollection< Key, Value >::exist | ( | const Key & | key | ) | const`[inline]`

Return 'true' if the list contains an occurrence of 'key', otherwise return 'false' (same as 'contains()')

template<typename Key, typename Value>

const_reference_value qx::QxCollection< Key, Value >::getByIndex | ( | long | index | ) | const`[inline]`

Return the item at index position 'index'.

template<typename Key, typename Value>

const_reference_value qx::QxCollection< Key, Value >::getByKey | ( | const Key & | key | ) | const`[inline]`

Return the item associated with the 'key'.

template<typename Key, typename Value>

const_reference_value qx::QxCollection< Key, Value >::getFirst | ( |  | ) | const`[inline]`

Return the first element in the list.

template<typename Key, typename Value>

const_reference_key qx::QxCollection< Key, Value >::getKeyByIndex | ( | long | index | ) | const`[inline]`

Return the key associated with the element at index position 'index'.

template<typename Key, typename Value>

const_reference_value qx::QxCollection< Key, Value >::getLast | ( |  | ) | const`[inline]`

Return the last element in the list.

template<typename Key, typename Value>

bool qx::QxCollection< Key, Value >::insert | ( | const Key & | key,
|  | const Value & | value
| ) |  | `[inline]`

Add element 'value' at the end of the list indexed by 'key'.

template<typename Key, typename Value>

bool qx::QxCollection< Key, Value >::insert | ( | long | index,
|  | const Key & | key,
|  | const Value & | value
| ) |  | `[inline]`

Insert element 'value' at position 'index' in the list indexed by 'key'.

template<typename Key, typename Value>

bool qx::QxCollection< Key, Value >::insert | ( | const QxCollection< Key, Value > & | other | ) | `[inline]`

Add all items of 'other' at the end of the list.

template<typename Key, typename Value>

bool qx::QxCollection< Key, Value >::insert | ( | long | index,
|  | const QxCollection< Key, Value > & | other
| ) |  | `[inline]`

Insert all items of 'other' at the end of the list.

template<typename Key, typename Value>

bool qx::QxCollection< Key, Value >::isSameCollection | ( | const QxCollection< Key, Value > * | p1,
|  | const QxCollection< Key, Value > & | p2
| ) |  | const`[private]`

template<typename Key, typename Value>

bool qx::QxCollection< Key, Value >::move | ( | long | indexFrom,
|  | long | indexTo
| ) |  | `[inline]`

Move the item at index position 'indexFrom' to index position 'indexTo'.

template<typename Key, typename Value>

bool qx::QxCollection< Key, Value >::operator!= | ( | const QxCollection< Key, Value > & | other | ) | const

Return 'true' if 'other' is not equal to this list, otherwise return 'false'.

template<typename Key, typename Value>

QxCollection<Key, Value>& qx::QxCollection< Key, Value >::operator= | ( | const QxCollection< Key, Value > & | other | ) |

Assign 'other' to this list and return a reference to this list.

template<typename Key, typename Value>

bool qx::QxCollection< Key, Value >::operator== | ( | const QxCollection< Key, Value > & | other | ) | const

Return 'true' if 'other' is equal to this list, otherwise return 'false' (same values in the same order)

template<typename Key, typename Value>

bool qx::QxCollection< Key, Value >::push_back | ( | const Key & | key,
|  | const Value & | value
| ) |  | `[inline]`

Add element 'value' at the end of the list indexed by 'key'.

template<typename Key, typename Value>

bool qx::QxCollection< Key, Value >::push_front | ( | const Key & | key,
|  | const Value & | value
| ) |  | `[inline]`

Insert 'value' at the beginning of the list indexed by 'key'.

template<typename Key, typename Value>

reverse_iterator qx::QxCollection< Key, Value >::rbegin | ( |  | ) | `[inline]`

Return a reverse STL-style iterator pointing to the first item in the list.

template<typename Key, typename Value>

const_reverse_iterator qx::QxCollection< Key, Value >::rbegin | ( |  | ) | const`[inline]`

Return a const reverse STL-style iterator pointing to the first item in the list.

template<typename Key, typename Value>

bool qx::QxCollection< Key, Value >::removeByIndex | ( | long | index | ) | `[inline]`

Remove the item at index position 'index'.

template<typename Key, typename Value>

bool qx::QxCollection< Key, Value >::removeByIndex | ( | long | first,
|  | long | last
| ) |  | `[inline]`

Remove all items from index position 'first' to index position 'last'.

template<typename Key, typename Value>

bool qx::QxCollection< Key, Value >::removeByKey | ( | const Key & | key | ) | `[inline]`

Remove the item indexed by 'key' in the list.

template<typename Key, typename Value>

bool qx::QxCollection< Key, Value >::removeFirst | ( |  | ) | `[inline]`

Remove the first item in the list.

template<typename Key, typename Value>

bool qx::QxCollection< Key, Value >::removeLast | ( |  | ) | `[inline]`

Remove the last item in the list.

template<typename Key, typename Value>

reverse_iterator qx::QxCollection< Key, Value >::rend | ( |  | ) | `[inline]`

Return a reverse STL-style iterator pointing to the imaginary item after the last item in the list.

template<typename Key, typename Value>

const_reverse_iterator qx::QxCollection< Key, Value >::rend | ( |  | ) | const`[inline]`

Return a const reverse STL-style iterator pointing to the imaginary item after the last item in the list.

template<typename Key, typename Value>

bool qx::QxCollection< Key, Value >::replace | ( | long | index,
|  | const Key & | key,
|  | const Value & | value
| ) |  | `[inline]`

Replace the item at index position 'index' with element 'value' indexed by 'key'.

template<typename Key, typename Value>

void qx::QxCollection< Key, Value >::reserve | ( | long | size | ) | `[inline]`

Request that the capacity of the allocated storage space for the items of the container be at least enough to hold 'size' elements.

template<typename Key, typename Value>

void qx::QxCollection< Key, Value >::reverse | ( |  | ) | `[inline]`

Reverse all items in the list.

template<typename Key, typename Value>

long qx::QxCollection< Key, Value >::size | ( |  | ) | const`[inline]`

Return the number of items in the list (same as 'count()')

template<typename Key, typename Value>
template<typename Compare >

void qx::QxCollection< Key, Value >::sort | ( | Compare | comp | ) | `[inline]`

Definition at line 241 of file QxCollection.h.

template<typename Key, typename Value>

void qx::QxCollection< Key, Value >::sortByKey | ( | bool | bAscending = `true` | ) | `[inline]`

Sort all items in the list using associated keys to compare.

template<typename Key, typename Value>

void qx::QxCollection< Key, Value >::sortByValue | ( | bool | bAscending = `true` | ) | `[inline]`

Sort all items in the list.

template<typename Key, typename Value>

bool qx::QxCollection< Key, Value >::swap | ( | long | index1,
|  | long | index2
| ) |  | `[inline]`

Exchange the item at index position 'index1' with the item at index position 'index2'.

## Member Data Documentation

template<typename Key, typename Value>

type_container qx::QxCollection< Key, Value >::m_qxCollection`[protected]`

Collection with random access (like std::vector) and fast lookup by key (like boost::unordered_map)

Definition at line 183 of file QxCollection.h.

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

- D:/Dvlp/_Perso/QxOrm/include/QxCollection/QxCollection.h