24.1 Overview
Managers are auxiliary objects that store extra information about a RoseObject . Your applications can define subclasses of RoseManager to store temporary information. The information in managers will never be written to a Part 21 file, but can be useful for storing translation results, reverse-pointers, and other cached values. The following RoseObject functions are used with managers:
RoseManager * RoseObject::managers();
RoseManager * RoseObject::find_manager (RoseManagerType typ);
void RoseObject::add_manager (RoseManager * mgr);
void RoseObject::remove_manager (RoseManagerType typ);
The ROSE_DECLARE/IMPLEMENT_MANAGER_COMMON() macros make sure that each manager class has a unique RoseManagerType identifier. The RoseObject::find_manager() function accepts a manager type and searches the list for a manager of that type. Similarly, the RoseObject::remove_manager() function searches for a manager of a particular type, removes it from the list, and then deletes it. Section 24.2 has an example showing how to define a new manager class and Section 24.6 shows how to use the class.
The ROSE library may occasionally adds managers to hold database information such as overflow attributes and external references. Both persistent and non-persistent objects can have managers.
24.2 ROSE_DECLARE_MANAGER_COMMON()
ROSE_DECLARE_MANAGER_COMMON();
The ROSE_DECLARE_MANAGER_COMMON() macro is used within the class declaration of a new RoseManager subclass. It declares a local version of the manager_type() virtual function and a static function called type() on the class:
virtual RoseManagerType manager_type();
static RoseManagerType type();
The manager_type() function returns the RoseManagerType type code identifying the class of an instance. The type() function is used to find type code for a particular class, to pass to RoseObject::find_manager() or RoseObject::remove_manager() .
Example
The code below defines the CountManager class to associate a count variable with STEP objects. The ROSE_DECLARE_MANAGER_COMMON() macro is used within the class declaration and the ROSE_IMPLEMENT_MANAGER_COMMON() macro is used somewhere in the ".cxx" file.
/* in your header file */
class CountManager : public RoseManager
{
public:
unsigned long m_count;
CountManager() { m_count=0; }
ROSE_DECLARE_MANAGER_COMMON();
};
/* In your cxx file */
ROSE_IMPLEMENT_MANAGER_COMMON (CountManager)
See Also
Manager Objects; ROSE_IMPLEMENT_MANAGER_COMMON(); manager_type(); type() (RoseManager subclass static fn)
24.3 ROSE_IMPLEMENT_MANAGER_COMMON()
ROSE_IMPLEMENT_MANAGER_COMMON(<classname>);
The manager_type() function returns the RoseManagerType value identifying the manager class. This virtual function must be redefined by subclasses to return an the identifier allocated by a call to new_manager_type() . See Manager Objects for detailed examples of how these functions are used.
See Also
24.4 manager_type()
virtual RoseManagerType manager_type();
The manager_type() function is used to identify the type of a manager instance. It returns the value of the type() static function for the class.
Applications should rarely need to call manager_type() directly. This is called internally by find_manager() and remove_manager() when scanning the list of managers associated with an object.
This function is defined for each subclass by the ROSE_DECLARE/IMPLEMENT_MANAGER_COMMON() macros.
24.5 new_manager_type() (RoseManager static fn)
static RoseManagerType new_manager_type();
The new_manager_type() function is a static function on the RoseManager base class that allocates a new RoseManagerType code. This is used by the type() static functions on the manager subclasses to allocate an identifier for the class at runtime. This lets an application add new managers without conflicting with existing ones.
Applications should never need to call new_manager_type() directly.
Example
This function is used by the ROSE_IMPLEMENT_MANAGER_COMMON() macro to implement the type() static function as shown below.
RoseManagerType cls::type() {
static RoseManagerType mt = 0;
if (!mt) mt = RoseManager::new_manager_type();
return mt;
}
24.6 type() (RoseManager subclass static fn)
static RoseManagerType type();
Every manager subclass has a static type() function that returns a RoseManagerType value identifying the subclass. The type() function is used as input to the RoseObject::find_manager() or RoseObject::remove_manager() functions.
The ROSE_DECLARE/IMPLEMENT_MANAGER_COMMON() macros create this function for each subclass. It usually returns an identifier allocated by a call to RoseManager::new_manager_type() .
Example
Consider a manager subtype named CountManager defined in Section 24.2 above. One can add a manager and find it again using the type() function as in the following code:
cartesian_point * pt;
CountManager * mgr;
// find a previously added manager on the point. If none
// is present, then add a new one */
mgr = (CountManager*) pt-> find_manager (CountManager::type());
if (!mgr) {
mgr = new CountMagager;
pt-> add_manager (mgr);
}
// use or change a count value on the manager
mgr-> m_count++;
When the cartesian point is deleted, any associated managers will be deleted as well, but we can remove managers explicitly as shown below:
/* remove any CountManager on the object */
pt-> remove_manager (CountManager::type());
See Also
Manager Objects; RoseObject::add_manager(); RoseObject::find_manager(); RoseObject::remove_manager()