#include <NamedItem.h> class CNamedItem { public: CNamedItem(); CNamedItem ( std::string am_sName, UInt_t am_nNumber ); public: std::string getName() const; UInt_t getNumber() const; void ChangeName(const std::string& rNewName); }; class CMatchNamedItemId { public: CMatchNamedItemId(UInt_t id); Bool_t operator()(CNamedItem& item); }; class CMatchNamedItem { public: CMatchNamedItem(const std::string& rName); Bool_t operator()(CNamedItem& item) };
Several SpecTcl objects have names and identifying numbers. The
CNamedItem
class provides a convenient base
class for those classes. In addition to the methods shown, named items
can be copy constructed, assigned and compared for equality. Those
methods have standard signatures and, therefore, are not described.
Often bits of SpecTcl have to search for named items, either by id
or by name in C++ standard library container objects (typically
but not exclusively maps organized by object name). The
CMatchNamedItemId
and
CMatchNamedItem
provide predicates for
C++ algorithms that require matching predicates.
CMatchNamedItemId
matches item(s) that
have the same id as the one it is constructed with, while
CMatchNamedItem
matches those named
the same as the string it is constructed with.
We're only going to document the CNamedItem
classes as the predicates are straightforward to use if you understand
how predicates are used in the C++ standard library algorithms.
CNamedItem();
Parameter-less constructor. This creaets an object with a name that is an empty string and an id of 0. Typically this is used to create an object that will be used as the target of an assignment.
CNamedItem (std::string am_sName, UInt_t am_nNumber);
Fully parameterized constructor. The object will have
the name provided by am_sName
and
the id provided by am_nNumber
.
Note that any attempt to maintain unique naming or id assignement is the responsibility of either the derived class (e.g. through a registry it maintain) or the code that manages the containers used to organize the derived objects.
const std::string getName() ();
Returns the name associated with this object.
const UInt_t getNumber();
Returns the id (integer) associated with this object.
void ChangeName(const std::string& rNewName);
In some cases it's useful to change the name of a named item.
This method provides that capability.
The object's name is changed to rNewName
.