PIP 5.6.1
Platform-Independent Primitives
Classes | Public Member Functions | Static Public Member Functions | Related Functions | List of all members
PICollection Class Reference

Global collection of PIObject-based instances grouped by name. More...

#include <picollection.h>

Classes

class  CollectionAdder
 Helper that registers object in collection during static initialization. More...
 

Public Member Functions

 PICollection ()
 Constructs collection helper.
 

Static Public Member Functions

static PIStringList groups ()
 Returns names of all existing groups.
 
static PIVector< const PIObject * > groupElements (const PIString &group)
 Returns all elements stored in group "group".
 
static bool addToGroup (const PIString &group, const PIObject *element)
 Adds object to group "group" if that group has no object of the same runtime class.
 

Related Functions

(Note that these are not member functions.)

#define ADD_TO_COLLECTION(group, object)
 Adds existing object to group "group". More...
 
#define ADD_TO_COLLECTION_WITH_NAME(group, object, name)
 Adds existing object to group "group" and assigns name "name". More...
 
#define ADD_NEW_TO_COLLECTION(group, class)
 Creates and adds new object of class "class" to group "group". More...
 
#define ADD_NEW_TO_COLLECTION_WITH_NAME(group, class, name)
 Creates and adds new object of class "class" to group "group" and assigns name "name". More...
 

Detailed Description

Global collection of PIObject-based instances grouped by name.

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)
piCout << gl; // {"ab_group", "c_group"}
piForeachC (PIString g, gl) {
piCout << "group" << g << ":";
piForeachC (PIObject * o, go)
piCout << Tab << o->className();
}
/*
group ab_group :
ElementA
ElementB
ElementD
group c_group :
ElementC
*/
};
#define ADD_TO_COLLECTION(group, object)
Adds existing object to group "group".
Definition: picollection.h:51
static PIVector< const PIObject * > groupElements(const PIString &group)
Returns all elements stored in group "group".
Definition: picollection.cpp:49
#define ADD_NEW_TO_COLLECTION(group, class)
Creates and adds new object of class "class" to group "group".
Definition: picollection.h:78
static PIStringList groups()
Returns names of all existing groups.
Definition: picollection.cpp:40
Base class for objects that declare events, event handlers and registered methods.
Definition: piobject.h:56
String class.
Definition: pistring.h:42
Based on PIDeque<PIString> strings list.
Definition: pistringlist.h:36
@ Tab
Definition: picout.h:78
#define piForeachC(i, c)
Macro for iterate any container.
Definition: picontainers.h:176
#define piCout
Definition: picout.h:36

Friends And Related Function Documentation

◆ ADD_TO_COLLECTION

#define ADD_TO_COLLECTION (   group,
  object 
)
related

Adds existing object to group "group".

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

◆ ADD_TO_COLLECTION_WITH_NAME

#define ADD_TO_COLLECTION_WITH_NAME (   group,
  object,
  name 
)
related

Adds existing object to group "group" and assigns name "name".

Similar to ADD_TO_COLLECTION(group, object), but also sets object name.

◆ ADD_NEW_TO_COLLECTION

#define ADD_NEW_TO_COLLECTION (   group,
  class 
)
related

Creates and adds new object of class "class" to group "group".

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

◆ ADD_NEW_TO_COLLECTION_WITH_NAME

#define ADD_NEW_TO_COLLECTION_WITH_NAME (   group,
  class,
  name 
)
related

Creates and adds new object of class "class" to group "group" and assigns name "name".

Similar to ADD_NEW_TO_COLLECTION(group, class), but also sets object name.