SurgSim::Framework::ObjectFactory< Base > 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>`

## 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)
| Create an instance of a class based on the specific class name. 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 >)> | 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>
class SurgSim::Framework::ObjectFactory< Base >

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 default constructor.

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

  Base | the base class for all classes that can be registered with the factory.

## Member Typedef Documentation

## Constructor

template<typename Base >

typedef boost::function<std::shared_ptr<Base>)> SurgSim::Framework::ObjectFactory< Base >::Constructor

private

## Member Function Documentation

## create()

template<class Base >

std::shared_ptr< Base > SurgSim::Framework::ObjectFactory< Base >::create | ( | const std::string & | className | ) |

Create an instance of a class based on the specific class name.

Parameters

  className | The class name that was used to register the class.

Returns
  a shared pointer to the object of type className, fails with an assertion otherwise.

## isRegistered()

template<typename Base >

bool SurgSim::Framework::ObjectFactory< Base >::isRegistered | ( | const std::string & | className | ) | const

Check whether the class is registered in the factory.

Parameters

  className | Name of the class to check.

Returns
  true if the factory has a constructor for this class.

## registerClass()

template<class Base >
template<class Derived >

bool SurgSim::Framework::ObjectFactory< Base >::registerClass | ( | const std::string & | className | ) |

Register a class with the factory.

Template Parameters

  T | The specific type of the class to be registered.

Parameters

  className | The name of this class.

Returns
  true if the class was added, false if it already existed in the registry.

## Member Data Documentation

## m_constructors

template<typename Base >

std::map<std::string, Constructor> SurgSim::Framework::ObjectFactory< Base >::m_constructors

private

All the constructors.

## m_mutex

template<typename Base >

boost::mutex SurgSim::Framework::ObjectFactory< Base >::m_mutex

mutable private

Threadsafety for registration.

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

- SurgSim/Framework/ObjectFactory.h
- SurgSim/Framework/ObjectFactory-inl.h