1 #ifndef MAPOBJECTCONTAINER_H 2 #define MAPOBJECTCONTAINER_H 11 template <
typename Obj,
typename Idx =
int>
19 QMap<Idx, ObjC *> mMap;
32 Idx
add (Idx
id, Obj *
object,
int role) {
34 id = Idx(mMap.size());
36 typename QMap<Idx,ObjC *>::iterator it = mMap.find(
id);
38 if (it == mMap.end()) {
41 mMap.insert(
id, cont);
46 while (cont->mList.size() <= role)
47 cont->mList.push_back(0);
48 cont->mList[role] = object;
53 Obj *
get(Idx
id,
int role) {
54 auto it = mMap.find(
id);
55 if (it == mMap.end()) {
60 if (obj->mList.size() <= role)
62 return obj->mList.at(role);
69 typedef typename QMap<Idx,ObjC *>::const_iterator
Iterator;
72 return mMap.constBegin();
76 return it == mMap.constEnd();
84 if (obj->mList.size() <= role)
87 return obj->mList.at(role);
96 auto it = mMap.find(
id);
97 if (it == mMap.end()) {
103 swap (obj->mList[role], r);
114 auto it = mMap.find(
id);
115 if (it == mMap.end()) {
116 return QList<Obj *>();
120 QList<Obj *> r = obj->mList;
127 #endif // MAPOBJECTCONTAINER_H MapObjectContainer()
Definition: mapobjectcontainer.h:22
Obj * remove(Idx id, int role)
remove the object specified by the id and role. The collection identified by id is not removed....
Definition: mapobjectcontainer.h:95
bool atEnd(Iterator it)
Definition: mapobjectcontainer.h:75
bool isIdInvalid(const X &)=delete
A generic Container class form Map Objects.
Definition: mapobjectcontainer.h:12
Idx add(Idx id, Obj *object, int role)
add an object with the specified id and role
Definition: mapobjectcontainer.h:32
QMap< Idx, ObjC * >::const_iterator Iterator
Definition: mapobjectcontainer.h:69
Obj * get(Idx id, int role)
Definition: mapobjectcontainer.h:53
~MapObjectContainer()
Definition: mapobjectcontainer.h:26
Obj * get(Iterator it, int role)
Definition: mapobjectcontainer.h:79
QList< Obj * > remove(Idx id)
Remove all the objects identified by the id, with all roles. The collection identified by id is remov...
Definition: mapobjectcontainer.h:113
Iterator begin()
Definition: mapobjectcontainer.h:71
void clear()
Definition: mapobjectcontainer.h:65