LDMX Software
framework::FactoryWithWarehouse< Prototype, PrototypePtr, PrototypeConstructorArgs > Class Template Reference

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
 

Detailed Description

template<typename Prototype, typename PrototypePtr, typename... PrototypeConstructorArgs>
class framework::FactoryWithWarehouse< Prototype, PrototypePtr, PrototypeConstructorArgs >

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.

Definition at line 299 of file Factory.h.

Member Typedef Documentation

◆ FactoryNoWarehouse

template<typename Prototype , typename PrototypePtr , typename... PrototypeConstructorArgs>
using framework::FactoryWithWarehouse< Prototype, PrototypePtr, PrototypeConstructorArgs >::FactoryNoWarehouse
Initial value:
Factory<Prototype, PrototypePtr, PrototypeConstructorArgs...>

Definition at line 302 of file Factory.h.

Member Function Documentation

◆ apply()

template<typename Prototype , typename PrototypePtr , typename... PrototypeConstructorArgs>
template<class UnaryFunction >
void framework::FactoryWithWarehouse< Prototype, PrototypePtr, PrototypeConstructorArgs >::apply ( UnaryFunction f) const
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.

Template Parameters
UnaryFunctiontype of function to be applied, its return value is ignored and its only argument are PrototypePtr objects.
Parameters
[in]fUnaryFunction to apply to each entry

Definition at line 344 of file Factory.h.

344 {
345 std::for_each(warehouse_.begin(), warehouse_.end(), f);
346 }
std::vector< PrototypePtr > warehouse_
warehouse of objects that have already been created
Definition Factory.h:359

References framework::FactoryWithWarehouse< Prototype, PrototypePtr, PrototypeConstructorArgs >::warehouse_.

◆ make()

template<typename Prototype , typename PrototypePtr , typename... PrototypeConstructorArgs>
std::optional< PrototypePtr > framework::FactoryWithWarehouse< Prototype, PrototypePtr, PrototypeConstructorArgs >::make ( const std::string & full_name,
PrototypeConstructorArgs... maker_args )
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.

Parameters
[in]full_namename of class to create same name as passed to declare
[in]maker_argsparameter pack of arguments to pass on to maker
Returns
a pointer to the parent class that the objects derive from (or null)

Reimplemented from framework::Factory< Prototype, PrototypePtr, PrototypeConstructorArgs... >.

Definition at line 323 of file Factory.h.

325 {
326 auto obj{FactoryNoWarehouse::make(full_name, maker_args...)};
327 if (obj) {
328 warehouse_.emplace_back(obj.value());
329 }
330 return obj;
331 }
virtual std::optional< PrototypePtr > make(const std::string &full_name, PrototypeConstructorArgs... maker_args)
Definition Factory.h:233

References framework::Factory< Prototype, PrototypePtr, PrototypeConstructorArgs... >::make(), and framework::FactoryWithWarehouse< Prototype, PrototypePtr, PrototypeConstructorArgs >::warehouse_.

Member Data Documentation

◆ warehouse_

template<typename Prototype , typename PrototypePtr , typename... PrototypeConstructorArgs>
std::vector<PrototypePtr> framework::FactoryWithWarehouse< Prototype, PrototypePtr, PrototypeConstructorArgs >::warehouse_
private

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