Public Types | Public Member Functions | Private Attributes | List of all members
WireCell::NamedFactory< Type > Class Template Reference

#include <NamedFactory.h>

Inheritance diagram for WireCell::NamedFactory< Type >:
WireCell::INamedFactory WireCell::IFactory WireCell::IComponent< IFactory > WireCell::Interface

Public Types

typedef Type type
 Remember the underlying type. More...
 
typedef std::shared_ptr< Typepointer_type
 The exposed pointer type. More...
 
- Public Types inherited from WireCell::INamedFactory
typedef std::shared_ptr< INamedFactorypointer
 
- Public Types inherited from WireCell::IComponent< IFactory >
typedef std::shared_ptr< IFactorypointer
 Access subclass facet by pointer. More...
 
typedef std::vector< pointervector
 Vector of shared pointers. More...
 
- Public Types inherited from WireCell::Interface
typedef std::shared_ptr< Interfacepointer
 

Public Member Functions

 NamedFactory ()
 
Interface::pointer find (const std::string &name)
 Return existing instance of given name or nullptr if not found. More...
 
Interface::pointer create ()
 Return an instance associated with the given name. More...
 
Interface::pointer create (const std::string &name)
 Create an instance by name. More...
 
virtual void set_classname (const std::string &name)
 Set name of class this factory can make. More...
 
virtual const std::stringclassname ()
 Access name of class this factory can make. More...
 
- Public Member Functions inherited from WireCell::INamedFactory
virtual ~INamedFactory ()
 
- Public Member Functions inherited from WireCell::IFactory
virtual ~IFactory ()
 
- Public Member Functions inherited from WireCell::IComponent< IFactory >
virtual ~IComponent ()
 
- Public Member Functions inherited from WireCell::Interface
virtual ~Interface ()
 

Private Attributes

std::unordered_map< std::string, pointer_typem_objects
 
std::string m_classname
 

Detailed Description

template<class Type>
class WireCell::NamedFactory< Type >

A templated factory of objects of type Type that associates a name to an object, returning a preexisting one if it exists.

Definition at line 27 of file NamedFactory.h.

Member Typedef Documentation

template<class Type>
typedef std::shared_ptr<Type> WireCell::NamedFactory< Type >::pointer_type

The exposed pointer type.

Definition at line 33 of file NamedFactory.h.

template<class Type>
typedef Type WireCell::NamedFactory< Type >::type

Remember the underlying type.

Definition at line 30 of file NamedFactory.h.

Constructor & Destructor Documentation

template<class Type>
WireCell::NamedFactory< Type >::NamedFactory ( )
inline

Definition at line 35 of file NamedFactory.h.

35 : m_classname("") {}
std::string m_classname
Definition: NamedFactory.h:63

Member Function Documentation

template<class Type>
virtual const std::string& WireCell::NamedFactory< Type >::classname ( )
inlinevirtual

Access name of class this factory can make.

Implements WireCell::INamedFactory.

Definition at line 59 of file NamedFactory.h.

59 { return m_classname; }
std::string m_classname
Definition: NamedFactory.h:63
template<class Type>
Interface::pointer WireCell::NamedFactory< Type >::create ( )
inlinevirtual

Return an instance associated with the given name.

Implements WireCell::IFactory.

Definition at line 47 of file NamedFactory.h.

47 { return create(""); }
Interface::pointer create()
Return an instance associated with the given name.
Definition: NamedFactory.h:47
template<class Type>
Interface::pointer WireCell::NamedFactory< Type >::create ( const std::string name)
inlinevirtual

Create an instance by name.

Implements WireCell::INamedFactory.

Definition at line 48 of file NamedFactory.h.

48  {
49  auto it = m_objects.find(name);
50  if (it == m_objects.end()) {
51  pointer_type p(new Type);
52  m_objects[name] = p;
53  return p;
54  }
55  return it->second;
56  }
static QCString name
Definition: declinfo.cpp:673
std::shared_ptr< Type > pointer_type
The exposed pointer type.
Definition: NamedFactory.h:33
std::unordered_map< std::string, pointer_type > m_objects
Definition: NamedFactory.h:62
p
Definition: test.py:223
Type
Type of JSON value.
Definition: rapidjson.h:618
template<class Type>
Interface::pointer WireCell::NamedFactory< Type >::find ( const std::string name)
inlinevirtual

Return existing instance of given name or nullptr if not found.

Implements WireCell::INamedFactory.

Definition at line 38 of file NamedFactory.h.

38  {
39  auto it = m_objects.find(name);
40  if (it == m_objects.end()) {
41  return nullptr;
42  }
43  return it->second;
44  }
static QCString name
Definition: declinfo.cpp:673
std::unordered_map< std::string, pointer_type > m_objects
Definition: NamedFactory.h:62
template<class Type>
virtual void WireCell::NamedFactory< Type >::set_classname ( const std::string name)
inlinevirtual

Set name of class this factory can make.

Implements WireCell::INamedFactory.

Definition at line 58 of file NamedFactory.h.

58 { m_classname=name; }
static QCString name
Definition: declinfo.cpp:673
std::string m_classname
Definition: NamedFactory.h:63

Member Data Documentation

template<class Type>
std::string WireCell::NamedFactory< Type >::m_classname
private

Definition at line 63 of file NamedFactory.h.

template<class Type>
std::unordered_map<std::string, pointer_type> WireCell::NamedFactory< Type >::m_objects
private

Definition at line 62 of file NamedFactory.h.


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