Anp::Factory< T > Class Template Reference

#include <Factory.h>

List of all members.

Public Types

typedef Handle< T >(* Creator )()

Public Member Functions

bool Register (const std::string &name, Creator creator)
bool Unregister (const std::string &name)
Handle< T > Create (const std::string &name)
const std::vector< std::string > List () const
bool Hold (const std::string &name, Handle< T > ptr)
Handle< T > Get (const std::string &name) const
bool Remove (const std::string &name)
void Clear ()
void Print () const

Static Public Member Functions

static FactoryInstance ()

Private Types

typedef std::map< std::string,
Creator
CallMap
typedef std::map< std::string,
Handle< T > > 
HoldMap

Private Member Functions

 Factory ()
 ~Factory ()
 Factory (const Factory &)
const Factoryoperator= (const Factory &)

Private Attributes

CallMap fCalls
HoldMap fHolds

Static Private Attributes

static FactoryfgInstance = 0

Detailed Description

template<class T>
class Anp::Factory< T >

Definition at line 28 of file Factory.h.


Member Typedef Documentation

template<class T >
typedef std::map<std::string, Creator> Anp::Factory< T >::CallMap [private]

Definition at line 72 of file Factory.h.

template<class T >
typedef Handle<T>(* Anp::Factory< T >::Creator)()

Definition at line 33 of file Factory.h.

template<class T >
typedef std::map<std::string, Handle<T> > Anp::Factory< T >::HoldMap [private]

Definition at line 73 of file Factory.h.


Constructor & Destructor Documentation

template<class T >
Anp::Factory< T >::Factory (  )  [inline, private]

Definitions of template functions

Definition at line 132 of file Factory.h.

00133 {
00134 }

template<class T >
Anp::Factory< T >::~Factory (  )  [inline, private]

Definition at line 137 of file Factory.h.

00138 {
00139 }

template<class T >
Anp::Factory< T >::Factory ( const Factory< T > &   )  [private]

Member Function Documentation

template<class T >
void Anp::Factory< T >::Clear ( void   )  [inline]

Definition at line 236 of file Factory.h.

References Anp::Factory< T >::fHolds.

00237 {
00238    fHolds.clear();
00239 }

template<class T >
Anp::Handle< T > Anp::Factory< T >::Create ( const std::string &  name  )  [inline]

Definition at line 171 of file Factory.h.

References Anp::Factory< T >::fCalls, and it.

00172 {
00173    typename CallMap::const_iterator it = fCalls.find(name);
00174    
00175    // handle unknown algorithm request
00176    if(it == fCalls.end())
00177    {
00178       std::cerr << "Factory<T>::Create - don't know anything about " << name << std::endl;
00179       return Handle<T>(NULL);
00180     }
00181    
00182    return (it->second)();
00183 }

template<class T >
Anp::Handle< T > Anp::Factory< T >::Get ( const std::string &  name  )  const [inline]

Definition at line 206 of file Factory.h.

References Anp::Factory< T >::fHolds, and it.

00207 {
00208    typename HoldMap::const_iterator it = fHolds.find(name);
00209 
00210    // handle unknown algorithm request
00211    if(it == fHolds.end())
00212    {
00213       std::cerr << "Factory<T>::Get - don't know anything about " << name << std::endl;
00214       return Handle<T>(NULL);
00215     }
00216    
00217    return it->second;
00218 }

template<class T >
bool Anp::Factory< T >::Hold ( const std::string &  name,
Handle< T >  ptr 
) [inline]

Definition at line 200 of file Factory.h.

References Anp::Factory< T >::fHolds.

00201 {
00202    return fHolds.insert(typename HoldMap::value_type(name, ptr)).second;
00203 }

template<class T >
Anp::Factory< T > & Anp::Factory< T >::Instance ( void   )  [inline, static]

Definition at line 142 of file Factory.h.

References Anp::Factory< T >::fgInstance.

00143 {
00144    if(!fgInstance)
00145    {
00146       fgInstance = new Anp::Factory<T>();
00147    }
00148 
00149   return *fgInstance;
00150 }

template<class T >
const std::vector< std::string > Anp::Factory< T >::List (  )  const [inline]

Definition at line 186 of file Factory.h.

References Anp::Factory< T >::fCalls, and it.

00187 {
00188    std::vector<std::string> svec;
00189 
00190    typename CallMap::const_iterator it = fCalls.begin();
00191    for(; it != fCalls.end(); ++it)
00192    {
00193       svec.push_back(it -> first);
00194    }
00195 
00196    return svec;
00197 }

template<class T >
const Factory& Anp::Factory< T >::operator= ( const Factory< T > &   )  [private]
template<class T >
void Anp::Factory< T >::Print ( void   )  const [inline]

Definition at line 242 of file Factory.h.

References Anp::Factory< T >::fCalls, and it.

00243 {
00244    std::cout << "Print: Factory<> knows about " << fCalls.size() << " objects" << std::endl;  
00245 
00246    typename CallMap::const_iterator it = fCalls.begin();
00247    for(; it != fCalls.end(); ++it)
00248    {
00249       std::cout << "Registerted object name " << it -> first << std::endl;
00250    }
00251 }

template<class T >
bool Anp::Factory< T >::Register ( const std::string &  name,
Creator  creator 
) [inline]

Definition at line 153 of file Factory.h.

References Anp::Factory< T >::fCalls.

00154 { 
00155    if(!fCalls.insert(typename CallMap::value_type(name, creator)).second)
00156    {
00157       std::cerr << "Factory<T>::Register - " << name << " already exists" << std::endl;
00158       return false;
00159    }
00160 
00161    return true;
00162 }

template<class T >
bool Anp::Factory< T >::Remove ( const std::string &  name  )  [inline]

Definition at line 221 of file Factory.h.

References Anp::Factory< T >::fHolds.

00222 {
00223    //
00224    // Atempt to erase handle with key "name"
00225    //
00226    if(fHolds.erase(name) < 1)
00227    {
00228       std::cerr << "Factory<T>::Remove - don't know anything about " << name << std::endl;
00229       return false;
00230    }
00231 
00232    return true;
00233 }

template<class T >
bool Anp::Factory< T >::Unregister ( const std::string &  name  )  [inline]

Definition at line 165 of file Factory.h.

References Anp::Factory< T >::fCalls.

00166 { 
00167     return fCalls.erase(name) == 1; 
00168 }


Member Data Documentation

template<class T >
CallMap Anp::Factory< T >::fCalls [private]
template<class T >
Factory< T > * Anp::Factory< T >::fgInstance = 0 [inline, static, private]

Initialize static singleton pointer

Definition at line 70 of file Factory.h.

Referenced by Anp::Factory< T >::Instance().

template<class T >
HoldMap Anp::Factory< T >::fHolds [private]

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

Generated on 15 Jul 2018 for loon by  doxygen 1.6.1