Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

InstanceTracker< FamilyT, ClassNameT, FactoryBaseT, FactoryT > Class Template Reference

Attempts to provide references to all currently instantiated objects of a class (and its subclasses). More...

#include <InstanceTracker.h>

Inheritance diagram for InstanceTracker< FamilyT, ClassNameT, FactoryBaseT, FactoryT >:

Detailed Description

template<class FamilyT, typename ClassNameT = std::string, class FactoryBaseT = Factory1Arg<FamilyT,std::string>, template< class U > class FactoryT = FactoryBaseT::template Factory>
class InstanceTracker< FamilyT, ClassNameT, FactoryBaseT, FactoryT >

Attempts to provide references to all currently instantiated objects of a class (and its subclasses).

The classes being tracked need to register themselves via registerInstance() -- this isn't magic. The easiest way to do this is simply to have the base FamilyT's constructor do the registration, and then all of the subclasses will get it automatically. This only works however, on the assumption that nothing is going to try to immediately access the newly registered entry while subclass construction is still in progress.

Definition at line 16 of file InstanceTracker.h.

List of all members.

Classes

struct  FactoryType
 allows indirect access to create factory classes More...
class  InstanceEntry
 Provides a wrapper for non-plistDictionary entries. More...

Public Types

typedef plist::Dictionary::iterator iterator
 shorthand for iterators to be returned
typedef
plist::Dictionary::const_iterator 
const_iterator
 shorthand for iterators to be returned
typedef FamilyT FamilyType
 allows indirect access to the product family type
typedef ClassNameT ClassNameType
 allows indirect access to the product class name type
typedef FactoryBaseT FactoryBaseType
 allows indirect access to the factory base class

Public Member Functions

 InstanceTracker ()
 constructor
template<class T >
bool registerInstance (const std::string &name, T &inst)
 Register an existing instance via reference, does not assume responsibility for memory deallocation, returns false if name is already in use.
template<class T >
bool registerInstance (const std::string &name, T *inst)
 Register an existing instance via pointer, does assume responsibility for memory deallocation, returns false if name is already in use.
template<class T >
bool registerInstance (const ClassNameT &type, const std::string &name, T &inst)
 Register an existing instance via reference, does not assume responsibility for memory deallocation, returns false if name is already in use.
template<class T >
bool registerInstance (const ClassNameT &type, const std::string &name, T *inst)
 Register an existing instance via pointer, does assume responsibility for memory deallocation, returns false if name is already in use.
FamilyT * create (const ClassNameType &type, const std::string &name)
 create and register an instance in one call
FamilyT * getInstance (const std::string &name)
 looks up a previously registered instance, returning NULL if not found
bool destroy (const std::string &name)
 Removes an instance from the tracker.
void loadXML (xmlNode *node)
 This specialization looks for the SensorInfo::sensorType, then has the factory construct the correct subtype before loading the node into and returning that.

Private Member Functions

 InstanceTracker (const InstanceTracker &)
 copy constructor, don't call
InstanceTrackeroperator= (const InstanceTracker &)
 assignment, don't call

Member Typedef Documentation

template<class FamilyT , typename ClassNameT = std::string, class FactoryBaseT = Factory1Arg<FamilyT,std::string>, template< class U > class FactoryT = FactoryBaseT::template Factory>
typedef ClassNameT InstanceTracker< FamilyT, ClassNameT, FactoryBaseT, FactoryT >::ClassNameType

allows indirect access to the product class name type

Definition at line 16 of file InstanceTracker.h.

template<class FamilyT , typename ClassNameT = std::string, class FactoryBaseT = Factory1Arg<FamilyT,std::string>, template< class U > class FactoryT = FactoryBaseT::template Factory>
typedef plist::Dictionary::const_iterator InstanceTracker< FamilyT, ClassNameT, FactoryBaseT, FactoryT >::const_iterator

shorthand for iterators to be returned

Reimplemented from plist::DictionaryBase.

Definition at line 11 of file InstanceTracker.h.

template<class FamilyT , typename ClassNameT = std::string, class FactoryBaseT = Factory1Arg<FamilyT,std::string>, template< class U > class FactoryT = FactoryBaseT::template Factory>
typedef FactoryBaseT InstanceTracker< FamilyT, ClassNameT, FactoryBaseT, FactoryT >::FactoryBaseType

allows indirect access to the factory base class

Reimplemented from FamilyFactory< FamilyT, ClassNameT, FactoryBaseT, FactoryT >.

Definition at line 18 of file InstanceTracker.h.

template<class FamilyT , typename ClassNameT = std::string, class FactoryBaseT = Factory1Arg<FamilyT,std::string>, template< class U > class FactoryT = FactoryBaseT::template Factory>
typedef FamilyT InstanceTracker< FamilyT, ClassNameT, FactoryBaseT, FactoryT >::FamilyType

allows indirect access to the product family type

Reimplemented from FamilyFactory< FamilyT, ClassNameT, FactoryBaseT, FactoryT >.

Definition at line 14 of file InstanceTracker.h.

template<class FamilyT , typename ClassNameT = std::string, class FactoryBaseT = Factory1Arg<FamilyT,std::string>, template< class U > class FactoryT = FactoryBaseT::template Factory>
typedef plist::Dictionary::iterator InstanceTracker< FamilyT, ClassNameT, FactoryBaseT, FactoryT >::iterator

shorthand for iterators to be returned

Reimplemented from plist::DictionaryBase.

Definition at line 9 of file InstanceTracker.h.


Constructor & Destructor Documentation

template<class FamilyT , typename ClassNameT = std::string, class FactoryBaseT = Factory1Arg<FamilyT,std::string>, template< class U > class FactoryT = FactoryBaseT::template Factory>
InstanceTracker< FamilyT, ClassNameT, FactoryBaseT, FactoryT >::InstanceTracker (  ) 

constructor

Definition at line 23 of file InstanceTracker.h.

template<class FamilyT , typename ClassNameT = std::string, class FactoryBaseT = Factory1Arg<FamilyT,std::string>, template< class U > class FactoryT = FactoryBaseT::template Factory>
InstanceTracker< FamilyT, ClassNameT, FactoryBaseT, FactoryT >::InstanceTracker ( const InstanceTracker< FamilyT, ClassNameT, FactoryBaseT, FactoryT > &   )  [private]

copy constructor, don't call


Member Function Documentation

template<class FamilyT , typename ClassNameT , class FactoryBaseT , template< class U > class FactoryT>
FamilyT * InstanceTracker< FamilyT, ClassNameT, FactoryBaseT, FactoryT >::create ( const ClassNameType type,
const std::string &  name 
)

create and register an instance in one call

Definition at line 149 of file InstanceTracker.h.

Referenced by InstanceTracker< FamilyT, ClassNameT, FactoryBaseT, FactoryT >::loadXML().

template<class FamilyT , typename ClassNameT , class FactoryBaseT , template< class U > class FactoryT>
bool InstanceTracker< FamilyT, ClassNameT, FactoryBaseT, FactoryT >::destroy ( const std::string &  name  ) 

Removes an instance from the tracker.

If the tracker was managing the memory allocation (via create() or the registerInstance() functions which take a pointer instead of a reference), then this will cause the instance to be deallocated.

Definition at line 177 of file InstanceTracker.h.

Referenced by InstanceTracker< FamilyT, ClassNameT, FactoryBaseT, FactoryT >::loadXML().

template<class FamilyT , typename ClassNameT , class FactoryBaseT , template< class U > class FactoryT>
FamilyT * InstanceTracker< FamilyT, ClassNameT, FactoryBaseT, FactoryT >::getInstance ( const std::string &  name  ) 

looks up a previously registered instance, returning NULL if not found

Definition at line 160 of file InstanceTracker.h.

template<class FamilyT , typename ClassNameT , class FactoryBaseT , template< class U > class FactoryT>
void InstanceTracker< FamilyT, ClassNameT, FactoryBaseT, FactoryT >::loadXML ( xmlNode node  )  [virtual]

This specialization looks for the SensorInfo::sensorType, then has the factory construct the correct subtype before loading the node into and returning that.

From the name of node, will instantiate a new ObjectBase subclass to load it.

supports use of plist::ArrayOf<PlannerObstacle> for polymorphic load/save

The mapping from node names to actual instantiated types is:

If successful, returns a pointer to a newly allocated region, which the caller is responsible for freeing. If an error occurs, NULL is returned.

attempts to load a new T instance from the specified xmlNode

Reimplemented from plist::DictionaryBase.

Definition at line 198 of file InstanceTracker.h.

template<class FamilyT , typename ClassNameT = std::string, class FactoryBaseT = Factory1Arg<FamilyT,std::string>, template< class U > class FactoryT = FactoryBaseT::template Factory>
InstanceTracker& InstanceTracker< FamilyT, ClassNameT, FactoryBaseT, FactoryT >::operator= ( const InstanceTracker< FamilyT, ClassNameT, FactoryBaseT, FactoryT > &   )  [private]

assignment, don't call

template<class FamilyT , typename ClassNameT , class FactoryBaseT , template< class U > class FactoryT>
template<class T >
bool InstanceTracker< FamilyT, ClassNameT, FactoryBaseT, FactoryT >::registerInstance ( const ClassNameT type,
const std::string &  name,
T *  inst 
)

Register an existing instance via pointer, does assume responsibility for memory deallocation, returns false if name is already in use.

If type is not an empty string, and inst is a plist::Dictionary, a '.type' entry will be added to store the type. This allows polymorphic loading. Non-dictionaries will be wrapped in a new plist::Dictionary with a '.type'.

Definition at line 136 of file InstanceTracker.h.

template<class FamilyT , typename ClassNameT , class FactoryBaseT , template< class U > class FactoryT>
template<class T >
bool InstanceTracker< FamilyT, ClassNameT, FactoryBaseT, FactoryT >::registerInstance ( const ClassNameT type,
const std::string &  name,
T &  inst 
)

Register an existing instance via reference, does not assume responsibility for memory deallocation, returns false if name is already in use.

If type is not an empty string, and inst is a plist::Dictionary, a '.type' entry will be added to store the type. This allows polymorphic loading. Non-dictionaries will be wrapped in a new plist::Dictionary with a '.type'.

Definition at line 118 of file InstanceTracker.h.

template<class FamilyT , typename ClassNameT , class FactoryBaseT , template< class U > class FactoryT>
template<class T >
bool InstanceTracker< FamilyT, ClassNameT, FactoryBaseT, FactoryT >::registerInstance ( const std::string &  name,
T *  inst 
)

Register an existing instance via pointer, does assume responsibility for memory deallocation, returns false if name is already in use.

Definition at line 107 of file InstanceTracker.h.

template<class FamilyT , typename ClassNameT , class FactoryBaseT , template< class U > class FactoryT>
template<class T >
bool InstanceTracker< FamilyT, ClassNameT, FactoryBaseT, FactoryT >::registerInstance ( const std::string &  name,
T &  inst 
)

Register an existing instance via reference, does not assume responsibility for memory deallocation, returns false if name is already in use.

Definition at line 93 of file InstanceTracker.h.

Referenced by InstanceTracker< FamilyT, ClassNameT, FactoryBaseT, FactoryT >::create().


The documentation for this class was generated from the following file:

Tekkotsu v5.1CVS
Generated Mon May 9 04:59:09 2016 by Doxygen 1.6.3