All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Private Types | Private Attributes | List of all members
SurgSim::Framework::ObjectFactory1< Base, Parameter1 > Class Template Reference

An object factory, once a class is registered with the factory it can be used to create instances of registered classes. More...

#include <SurgSim/Framework/ObjectFactory.h>

Collaboration diagram for SurgSim::Framework::ObjectFactory1< Base, Parameter1 >:
Collaboration graph
[legend]

Public Member Functions

template<typename Derived >
bool registerClass (const std::string &className)
 Register a class with the factory. More...
 
std::shared_ptr< Base > create (const std::string &className, const Parameter1 &val)
 Create an instance of a class based on the specific class name, whose constructor takes 1 parameter. More...
 
bool isRegistered (const std::string &className) const
 Check whether the class is registered in the factory. More...
 

Private Types

typedef boost::function
< std::shared_ptr< Base >
Parameter1)> 
Constructor
 

Private Attributes

std::map< std::string,
Constructor
m_constructors
 All the constructors. More...
 
boost::mutex m_mutex
 Threadsafety for registration. More...
 

Detailed Description

template<typename Base, typename Parameter1>
class SurgSim::Framework::ObjectFactory1< Base, Parameter1 >

An object factory, once a class is registered with the factory it can be used to create instances of registered classes.

All the classes registered need to have a one parameter constructor, the type for that parameter can be passed as a template parameter.

Note
The names used for registration and the actual c++ class names are independent the className parameter here is just an identifier for the class.
Template Parameters
BaseThe base class for all classes that can be registered with the factory.
Parameter1The class for the constructor parameter.

Member Typedef Documentation

template<typename Base, typename Parameter1>
typedef boost::function<std::shared_ptr<Base>Parameter1)> SurgSim::Framework::ObjectFactory1< Base, Parameter1 >::Constructor
private

Member Function Documentation

template<typename Base , typename Parameter1>
std::shared_ptr< Base > SurgSim::Framework::ObjectFactory1< Base, Parameter1 >::create ( const std::string &  className,
const Parameter1 &  val 
)

Create an instance of a class based on the specific class name, whose constructor takes 1 parameter.

Parameters
classNameThe class name.
valThe value of the parameter.
Returns
a shared pointer to the object of type className instantiated with the given parameter, fails with an assertion otherwise.
template<typename Base , typename Parameter1 >
bool SurgSim::Framework::ObjectFactory1< Base, Parameter1 >::isRegistered ( const std::string &  className) const

Check whether the class is registered in the factory.

Parameters
classNameName of the class to check.
Returns
true if the factory has a constructor for this class
template<typename Base , typename Parameter1 >
template<typename Derived >
bool SurgSim::Framework::ObjectFactory1< Base, Parameter1 >::registerClass ( const std::string &  className)

Register a class with the factory.

Template Parameters
TThe specific type of the class to be registered.
Parameters
classNameThe name of this class.
Returns
true if the class was added, false if it already existed in the registry.

Member Data Documentation

template<typename Base, typename Parameter1>
std::map<std::string, Constructor> SurgSim::Framework::ObjectFactory1< Base, Parameter1 >::m_constructors
private

All the constructors.

template<typename Base, typename Parameter1>
boost::mutex SurgSim::Framework::ObjectFactory1< Base, Parameter1 >::m_mutex
mutableprivate

Threadsafety for registration.


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