Functions
WireCell::Factory Namespace Reference

Singleton interface. More...

Functions

template<class IType >
bool associate (const std::string &classname, WireCell::INamedFactory *factory)
 Associate a factory with the type it makes. More...
 
template<class IType >
WireCell::INamedFactorylookup_factory (const std::string &classname)
 Lookup up a factory for the given type. More...
 
template<class IType >
std::shared_ptr< IType > lookup (const std::string &classname, const std::string &instname="", bool create=true, bool nullok=false)
 
template<class IType >
std::shared_ptr< IType > find (const std::string &classname, const std::string &instname="")
 
template<class IType >
std::shared_ptr< IType > find_maybe (const std::string &classname, const std::string &instname="")
 As above but quietly returns nullptr on failure. More...
 
template<class IType >
std::shared_ptr< IType > lookup_tn (const std::string &tn, bool create=true, bool nullok=false)
 Lookup an interface by a type:name pair. More...
 
template<class IType >
std::shared_ptr< IType > find_tn (const std::string &tn)
 Like lookup_tn but with create false. More...
 
template<class IType >
std::shared_ptr< IType > find_maybe_tn (const std::string &tn)
 Like find_tn but with nullok true. More...
 
template<class IType >
std::vector< std::stringknown_classes ()
 Return a vector of all known classes of given interface. More...
 
template<class IType >
std::vector< std::stringknown_types ()
 

Detailed Description

Singleton interface.

Function Documentation

template<class IType >
bool WireCell::Factory::associate ( const std::string classname,
WireCell::INamedFactory factory 
)

Associate a factory with the type it makes.

Definition at line 210 of file NamedFactory.h.

210  {
211  NamedFactoryRegistry<IType>&
213  bool ok = nfr.associate(classname, factory);
214  if (ok) { return ok; }
215  THROW(FactoryException() << errmsg{"Failed to associate class " + classname});
216  }
boost::error_info< struct tag_errmsg, std::string > errmsg
Definition: Exceptions.h:54
#define THROW(e)
Definition: Exceptions.h:25
template<class IType >
std::shared_ptr<IType> WireCell::Factory::find ( const std::string classname,
const std::string instname = "" 
)

Return existing instance of given classname with instname Throws on failure.

Definition at line 247 of file NamedFactory.h.

247  {
248  std::shared_ptr<IType> ret = lookup<IType>(classname, instname, false, false);
249  return ret;
250  }
template<class IType >
std::shared_ptr<IType> WireCell::Factory::find_maybe ( const std::string classname,
const std::string instname = "" 
)

As above but quietly returns nullptr on failure.

Definition at line 253 of file NamedFactory.h.

253  {
254  std::shared_ptr<IType> ret = lookup<IType>(classname, instname, false, true);
255  return ret;
256  }
template<class IType >
std::shared_ptr<IType> WireCell::Factory::find_maybe_tn ( const std::string tn)

Like find_tn but with nullok true.

Definition at line 281 of file NamedFactory.h.

281  {
282  std::shared_ptr<IType> ret = lookup_tn<IType>(tn, false, true);
283  return ret;
284  }
template<class IType >
std::shared_ptr<IType> WireCell::Factory::find_tn ( const std::string tn)

Like lookup_tn but with create false.

Definition at line 275 of file NamedFactory.h.

275  {
276  std::shared_ptr<IType> ret = lookup_tn<IType>(tn, false, false);
277  return ret;
278  }
template<class IType >
std::vector<std::string> WireCell::Factory::known_classes ( )

Return a vector of all known classes of given interface.

Definition at line 288 of file NamedFactory.h.

288  {
289  NamedFactoryRegistry<IType>&
291  return nfr.known_classes();
292  }
template<class IType >
std::vector<std::string> WireCell::Factory::known_types ( )

Definition at line 294 of file NamedFactory.h.

294  {
295  NamedFactoryRegistry<IType>&
297  auto ktset = nfr.known_types();
298  std::vector<std::string> ret(ktset.begin(), ktset.end());
299  return ret;
300  }
template<class IType >
std::shared_ptr<IType> WireCell::Factory::lookup ( const std::string classname,
const std::string instname = "",
bool  create = true,
bool  nullok = false 
)

Lookup an interface by a type and optional name. If create is true, create instance if missing. if nullok is true return nullptr if can not create. See also find<IType>().

Definition at line 233 of file NamedFactory.h.

235  {
236  NamedFactoryRegistry<IType>&
238  std::shared_ptr<IType> ret = nfr.instance(classname, instname, create, nullok);
239  if (ret) { return ret; }
240  if (nullok) { return nullptr; }
241  THROW(FactoryException() << errmsg{"Failed to lookup instance for " + classname + " " + instname});
242  }
boost::error_info< struct tag_errmsg, std::string > errmsg
Definition: Exceptions.h:54
#define THROW(e)
Definition: Exceptions.h:25
std::shared_ptr< spdlog::logger > create(std::string logger_name, SinkArgs &&...sink_args)
Definition: spdlog.h:45
template<class IType >
WireCell::INamedFactory* WireCell::Factory::lookup_factory ( const std::string classname)

Lookup up a factory for the given type.

Definition at line 220 of file NamedFactory.h.

220  {
221  NamedFactoryRegistry<IType>&
223  WireCell::INamedFactory* ret = nfr.lookup_factory(classname);
224  if (ret) { return ret; }
225  THROW(FactoryException() << errmsg{"Failed to lookup factory for " + classname});
226  }
boost::error_info< struct tag_errmsg, std::string > errmsg
Definition: Exceptions.h:54
#define THROW(e)
Definition: Exceptions.h:25
template<class IType >
std::shared_ptr<IType> WireCell::Factory::lookup_tn ( const std::string tn,
bool  create = true,
bool  nullok = false 
)

Lookup an interface by a type:name pair.

Definition at line 260 of file NamedFactory.h.

260  {
261  if (tn.empty()) {
262  if (nullok) {
263  return nullptr;
264  }
265  THROW(FactoryException() << errmsg{"Empty type:name string"});
266  }
267 
268  std::string t, n;
269  std::tie(t,n) = String::parse_pair(tn);
270  return lookup<IType>(t, n, create, nullok);
271  }
std::string string
Definition: nybbler.cc:12
boost::error_info< struct tag_errmsg, std::string > errmsg
Definition: Exceptions.h:54
std::pair< std::string, std::string > parse_pair(const std::string &in, const std::string &delim=":")
Definition: String.cxx:15
#define THROW(e)
Definition: Exceptions.h:25
std::shared_ptr< spdlog::logger > create(std::string logger_name, SinkArgs &&...sink_args)
Definition: spdlog.h:45
std::size_t n
Definition: format.h:3399