PIP 0.7.1 Platform-Independent Primitives

Static Public Member Functions | Related Functions | List of all members
PICollection Class Reference

Interface to discover element groups. More...

## Static Public Member Functions
static PIStringList | groups ()
| Returns all existing groups by their names.
static PIVector< const PIObject *> | groupElements (const PIString &group)
| Returns all elements of group "group".

## Related Functions
(Note that these are not member functions.)
#define | ADD_TO_COLLECTION(group, object)
| Add existing element "object" in group with name "group". More...
#define | ADD_NEW_TO_COLLECTION(group, class)
| Add new element of class "class" in group with name "group". More...

## Detailed Description

Interface to discover element groups.

# Synopsis

This class has only static functions so no need to create instance of the PICollection. This class provide macros to add some classes or existing objects to global collection and access to them from any place of the code.

class ElementA: public PIObject {
PIOBJECT(ElementA)
// ...
};
ADD_NEW_TO_COLLECTION(ab_group, ElementA)
class ElementB: public PIObject {
PIOBJECT(ElementB)
// ...
};
ADD_NEW_TO_COLLECTION(ab_group, ElementB)
class ElementC: public PIObject {
PIOBJECT(ElementC)
// ...
};
ADD_NEW_TO_COLLECTION(c_group, ElementC)
class ElementD: public PIObject {
PIOBJECT(ElementD)
// ...
};
int main() {
ElementD * el_d = new ElementD();
ADD_TO_COLLECTION(ab_group, el_d)
PIStringList gl = PICollection::groups();
piCout << gl; // {"ab_group", "c_group"}
piForeachC (PIString g, gl) {
PIVector<const PIObject * > go = PICollection::groupElements(g);
piCout << "group" << g << ":";
piForeachC (PIObject * o, go)
piCout << Tab << o->className();
}
/*
group ab_group :
ElementA
ElementB
ElementD
group c_group :
ElementC
*/
};

## Friends And Related Function Documentation

## ◆ ADD_TO_COLLECTION

#define ADD_TO_COLLECTION | ( |  | group,
|  |  | object
| ) |  |
| related

Add existing element "object" in group with name "group".

If there is no group with name "group" it will be created. Only one element of the class "object" can be in group "group". If this is already exists nothing be happens.
"object" should to be pointer to object based on PIObject.

## ◆ ADD_NEW_TO_COLLECTION

#define ADD_NEW_TO_COLLECTION | ( |  | group,
|  |  | class
| ) |  |
| related

Add new element of class "class" in group with name "group".

If there is no group with name "group" it will be created. Only one element of the class "class" can be in group "group". If this is already exists nothing be happens.
"class" should to be name of the any class based on PIObject.