qx::QxCollection<Key, Value> : QxOrm thread-safe container (keep insertion order + quick access by index + quick access by key)
More...
|
| 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.
|
|
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 qx::any | _at (long index) const |
|
| IxCollection () |
|
virtual | ~IxCollection ()=0 |
|
template<typename T > |
T | _get (long index) const |
|
template<typename Key, typename Value>
class qx::QxCollection< Key, Value >
qx::QxCollection<Key, Value> : QxOrm thread-safe 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 :
class drug { public: QString code; QString name; QString desc; };
typedef std::shared_ptr<drug> drug_ptr;
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";
lstDrugs.
insert(d1->code, d1);
lstDrugs.
insert(d2->code, d2);
lstDrugs.
insert(d3->code, d3);
{ qDebug() << qPrintable(p->name) << " " << qPrintable(p->desc); }
for (
long l = 0; l < lstDrugs.
count(); ++l)
{
qDebug() << qPrintable(p->name) << " " << qPrintable(p->desc);
}
while (itr.next())
{
QString code = itr.key();
qDebug() << qPrintable(itr.value()->name) << " " << qPrintable(itr.value()->desc);
}
drug_ptr p = lstDrugs.
getByKey(
"code2");
bool bExist = lstDrugs.
exist(
"code3");
bool bEmpty = lstDrugs.
empty();
qx::QxCollection<Key, Value> : QxOrm thread-safe container (keep insertion order + quick access by in...
void sortByValue(bool bAscending=true)
Sort all items in the list.
bool insert(const Key &key, const Value &value)
Add element 'value' at the end of the list indexed by 'key'.
const_reference_key getKeyByIndex(long index) const
Return the key associated with the element at index position 'index'.
const_reference_value getByKey(const Key &key) const
Return the item associated with the 'key'.
void sortByKey(bool bAscending=true)
Sort all items in the list using associated keys to compare.
bool removeByKey(const Key &key)
Remove the item indexed by 'key' in the list.
long count() const
Return the number of items in the list (same as 'size()')
void clear()
Remove all items from the list.
bool removeByIndex(long index)
Remove the item at index position 'index'.
bool empty() const
Return 'true' if the list contains no items; otherwise return 'false'.
const_reference_value getByIndex(long index) const
Return the item at index position 'index'.
bool exist(const Key &key) const
Return 'true' if the list contains an occurrence of 'key', otherwise return 'false' (same as 'contain...
qx::QxCollectionIterator : Java-style iterator to iterate over a qx::QxCollection<Key,...
Definition at line 147 of file QxCollection.h.