Overview
Managers are auxiliary objects that hold extra information about a RoseObject. Your application can define RoseManager subclasses to store temporary translation results, reverse-pointers, and other cached values. Information in managers is never written to a part 21 file.
The ROSE library uses managers to hold extra database information such as overflow attributes and external references. Both persistent and non-persistent objects can have managers.
The RoseObject::find_manager(), add_manager(), and remove_manager() functions find, attach, and delete managers from RoseObjects. In addition, the DECLARE/IMPLEMENT macros below can provide simplified find and make functions. There is also additional discussion in Manager Objects.
DECLARE/IMPLEMENT Macros
ROSE_DECLARE_MANAGER_COMMON(); ROSE_DECLARE_MANAGER_FIND(<classname>); ROSE_DECLARE_MANAGER_MAKE(<classname>); ROSE_IMPLEMENT_MANAGER_COMMON(<classname>); ROSE_IMPLEMENT_MANAGER_FIND(<classname>); ROSE_IMPLEMENT_MANAGER_MAKE(<classname>);
These DECLARE and IMPLEMENT macros provide identification and search functions needed by manager objects. Use the DECLARE macros within the class declaration of a manager subclass, and place the IMPLEMENT macro with the other function definitions for the class. The COMMON macro is required, the FIND and MAKE are optional.
The COMMON macro declares a virtual manager_type() function that returns the RoseManagerType type code identifying the class of an instance. It also declares a static type() function that provides the type code for that particular class, which is used by to RoseObject::find_manager() and RoseObject::remove_manager().
ROSE_DECLARE_MANAGER_COMMON() expands to: virtual RoseManagerType manager_type(); static RoseManagerType type();
The FIND macro declares a static find() function that calls RoseObject::find_manager() to search a RoseObject for that type of manager, and returns it, cast as the appropriate type, if found.
ROSE_DECLARE_MANAGER_FIND(MySpecialManager) expands to: static MySpecialManager * find (RoseObject * obj);
The MAKE macro declares a static make() function that searches a RoseObject for that type of manager as above, but creates a new manager and adds it to the RoseObject, if one is not already present. The IMPLEMENT macro uses the default constructor for the manager.
ROSE_DECLARE_MANAGER_MAKE(MySpecialManager) expands to: static MySpecialManager * make (RoseObject * obj);
The Example below defines the CountManager class to associate a count variable with STEP objects. It also defines static find() and make() functions for it.
/* in your header file */ class CountManager : public RoseManager { public: unsigned long m_count; CountManager() { m_count=0; } ROSE_DECLARE_MANAGER_COMMON(); ROSE_DECLARE_MANAGER_FIND(CountManager); ROSE_DECLARE_MANAGER_MAKE(CountManager); }; /* In your cxx file */ ROSE_IMPLEMENT_MANAGER_COMMON (CountManager) ROSE_IMPLEMENT_MANAGER_FIND (CountManager) ROSE_IMPLEMENT_MANAGER_MAKE (CountManager)
manager_type()
virtual RoseManagerType manager_type();
The manager_type() function identifies the type of a manager instance. It returns the value of the type() static function for the class. This function is defined for each subclass by the COMMON macros.
This is used by find_manager() and remove_manager() when scanning the managers associated with a RoseObject.
type() (subclass static fn)
static RoseManagerType type();
Every subclass has a static type() function that returns a unique RoseManagerType value. This value is used to search the managers by the RoseObject::find_manager() or RoseObject::remove_manager() functions.
The COMMON macros create this function for each subclass.
Consider a CountManager subtype. The following code adds a manager and finds it again using the type()
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++;
The find() and make() functions declared by the FIND and MAKE macros make this process even simpler:
cartesian_point * pt; CountManager * mgr = CountManager::make(pt); // use or change a count value on the manager mgr-> m_count++;
When the cartesian point is deleted, any associated managers are deleted as well. We can remove managers explicitly as shown below:
/* remove any CountManager on the object */ pt-> remove_manager (CountManager::type());