template < class X > class genNamedObj

Template for genNamedObj

Inheritance:


Public Methods

static void add( const char *name, X x )
Adds the object X with the name to the container
inline static X begin()
Returns the first object
inline static X end()
Returns the position after the last object (i
static bool exists( const char *name )
Returns true of the object with this name exists
genNamedObj( const char *name, X x)
Constructor that add the named object x into the container
static X get( const char *name )
Returns the object of a given name or NULL if it does not exists
int getLocation()
Returns the location of the object within the map - i
inline static int getNbElements()
Returns the number of objects in the container
static X getObject( const char *name )
Returns the object of a given name or NULL if it does not exists
static int getObjects( const char *name, list<X> &theList )
Given a tag (such as "object*") find all objects that contain this string and return them in a linked list
inline const char* getObjName()
Returns the name of the object
inline static X next()
Returns the next object
static void remove( const char *name )
Removes the named object from the list
~genNamedObj()
Dtor

Private Fields

static map < const char*, X, cstring_ordering_t > ::iterator m_It
iterator that is used internally when looping over all objects
static map < const char*, X, cstring_ordering_t > m_Map
map with all the elements
char* m_Name
Name of the object

Documentation

Template for genNamedObj.

This template supports the store, retrieval and location of named objects. A named object is simply an object that has a name (in the form of a string). Internally it is implemented using the STL map container.

Typical usage:

 class XXX : public genNamedObj<X*>
 {
   XXX(const char *name, ...) : getNamedObj<X*>( name, this ) {...}
 };

 // initialize the static members
 map<const char*, X*, cstring_ordering_t> genNamedObj<XXX*>::m_Map( my_cstring_ordering );
 map<const char*, XXX*, cstring_ordering_t>::iterator genNamedObj<XXX*>::m_It = NULL;

Note that we do normally not store the object itself in the container, but only the pointer to it. The string "name" is stored and managed internally. As the container is implemented as a static map, the user has to initialize its two static members,

An working example C++ file is test_gen_named_obj.cc.

MODIFICATIONS:

genNamedObj( const char *name, X x)
Constructor that add the named object x into the container
Parameters:
name - : name of the object. A local copy of the name is made and maintained in the genNamedObj.
X - : the object. Normally the pointer to the object is passed and not the object itself in order to limit the number of copy Ctors

~genNamedObj()
Dtor. Removes the object from the container and deletes the name

inline const char* getObjName()
Returns the name of the object

static bool exists( const char *name )
Returns true of the object with this name exists

static X get( const char *name )
Returns the object of a given name or NULL if it does not exists

static X getObject( const char *name )
Returns the object of a given name or NULL if it does not exists. This function is only provided as the "generic" name get may already be used by another object leading to name conflicts. In that case we can use getObject and get will not be instantiated by the compiler from the template.

static int getObjects( const char *name, list<X> &theList )
Given a tag (such as "object*") find all objects that contain this string and return them in a linked list. The return value is the number of objects in the list.

int getLocation()
Returns the location of the object within the map - i.e. for the n-th object returns n

inline static int getNbElements()
Returns the number of objects in the container

static void add( const char *name, X x )
Adds the object X with the name to the container. Is normally not called by the user but from within the constructor.

static void remove( const char *name )
Removes the named object from the list. Is normally not called by the user but from the Dtor.

inline static X begin()
Returns the first object

inline static X end()
Returns the position after the last object (i.e. NULL)

inline static X next()
Returns the next object

char* m_Name
Name of the object

static map < const char*, X, cstring_ordering_t > m_Map
map with all the elements

static map < const char*, X, cstring_ordering_t > ::iterator m_It
iterator that is used internally when looping over all objects


Direct child classes:
rcRun
rcGTM
Swpu
Prst
Par
Granule
FEM
EvbComponent
DataLogger
DCM
Crate
ddFrameReceiver
ddEventServer
ROobject
Pud
EvPool
DCB
Author:
C.Witzig
Date: Mar 2, 99
Version:
Last update May 2, 99

alphabetic index hierarchy of classes


this page has been generated automatically by doc++

(c)opyright by Malte Zöckler, Roland Wunderling
contact: doc++@zib.de