|
LDMX Software
|
A Factory with a warehouse to hold created objects. More...
#include <Factory.h>
Public Types | |
| using | FactoryNoWarehouse |
Public Types inherited from framework::Factory< Prototype, PrototypePtr, PrototypeConstructorArgs... > | |
| using | PrototypeMaker |
| the signature of a function that can be used by this factory to dynamically create a new object. | |
Public Member Functions | |
| std::optional< PrototypePtr > | make (const std::string &full_name, PrototypeConstructorArgs... maker_args) override |
| make a new object by name | |
| template<class UnaryFunction > | |
| void | apply (UnaryFunction f) const |
| Apply the input UnaryFunction to each entry in the warehouse. | |
| FactoryWithWarehouse (FactoryWithWarehouse const &)=delete | |
| delete the copy constructor | |
| void | operator= (FactoryWithWarehouse const &)=delete |
| delete the assignment operator | |
| FactoryWithWarehouse ()=default | |
| default constructor that does nothing | |
Public Member Functions inherited from framework::Factory< Prototype, PrototypePtr, PrototypeConstructorArgs... > | |
| uint64_t | declare (const std::string &derived_type_name) |
| register a new object to be constructible | |
| Factory (Factory const &)=delete | |
| delete the copy constructor | |
| Factory ()=default | |
| default constructor that does nothing | |
| void | operator= (Factory const &)=delete |
| delete the assignment operator | |
| virtual | ~Factory ()=default |
| default destructor that is virtual for Warehouse override | |
Private Attributes | |
| std::vector< PrototypePtr > | warehouse_ |
| warehouse of objects that have already been created | |
A Factory with a warehouse to hold created objects.
This is the same as the Factory above, but it includes a "warehouse" that holds all of the created objects that the factory has made, which is helpful in the case where there isn't a single place where the created objects will be managed after the Factory creates them.
In order to gain access to the "warehouse" storage and the apply function, you just need to change which type of factory is declared within your prototype. Use the DECLARE_FACTORY_WITH_WAREHOUSE macro instead of DECLARE_FACTORY.
| using framework::FactoryWithWarehouse< Prototype, PrototypePtr, PrototypeConstructorArgs >::FactoryNoWarehouse |
|
inline |
Apply the input UnaryFunction to each entry in the warehouse.
UnaryFunction is simply passed dirctly to std::for_each so look there for requirements upon it.
| UnaryFunction | type of function to be applied, its return value is ignored and its only argument are PrototypePtr objects. |
| [in] | f | UnaryFunction to apply to each entry |
Definition at line 344 of file Factory.h.
References framework::FactoryWithWarehouse< Prototype, PrototypePtr, PrototypeConstructorArgs >::warehouse_.
|
inlinenodiscardoverridevirtual |
make a new object by name
We look through the library to find the requested object. If found, we create one, store it in the warehouse, and return it wrapped in a std::optional. If not found, we return std::nullopt.
The arguments to the maker are determined at compiletime using the template parameters of Factory.
| [in] | full_name | name of class to create same name as passed to declare |
| [in] | maker_args | parameter pack of arguments to pass on to maker |
Reimplemented from framework::Factory< Prototype, PrototypePtr, PrototypeConstructorArgs... >.
Definition at line 323 of file Factory.h.
References framework::Factory< Prototype, PrototypePtr, PrototypeConstructorArgs... >::make(), and framework::FactoryWithWarehouse< Prototype, PrototypePtr, PrototypeConstructorArgs >::warehouse_.
|
private |
warehouse of objects that have already been created
Definition at line 359 of file Factory.h.
Referenced by framework::FactoryWithWarehouse< Prototype, PrototypePtr, PrototypeConstructorArgs >::apply(), and framework::FactoryWithWarehouse< Prototype, PrototypePtr, PrototypeConstructorArgs >::make().