LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
g4b::UserActionFactory Class Reference

#include "UserActionFactory.h"

Classes

struct  Cleaner
 

Public Member Functions

g4b::UserActionGetUserAction (const std::string &)
 
bool IsKnownUserAction (const std::string &)
 
const std::vector< std::string > & AvailableUserActions () const
 
bool RegisterCreator (std::string name, UserActionCtorFuncPtr_t ctorptr, bool *ptr)
 

Static Public Member Functions

static UserActionFactoryInstance ()
 

Private Member Functions

 UserActionFactory ()
 
virtual ~UserActionFactory ()
 
 UserActionFactory (const UserActionFactory &)
 
void operator= (const UserActionFactory &)
 

Private Attributes

std::map< std::string, UserActionCtorFuncPtr_tfFunctionMap
 
std::map< std::string, bool * > fBoolPtrMap
 
std::vector< std::string > listnames
 

Static Private Attributes

static UserActionFactoryfgTheInstance
 

Friends

struct Cleaner
 

Detailed Description

Definition at line 34 of file UserActionFactory.h.

Constructor & Destructor Documentation

g4b::UserActionFactory::UserActionFactory ( )
private

Definition at line 21 of file UserActionFactory.cxx.

References fgTheInstance.

Referenced by Instance().

22 {
23  fgTheInstance = this; // record created self in static pointer
24 }
static UserActionFactory * fgTheInstance
g4b::UserActionFactory::~UserActionFactory ( )
privatevirtual

Definition at line 26 of file UserActionFactory.cxx.

References fgTheInstance.

27 {
28  fgTheInstance = 0;
29 }
static UserActionFactory * fgTheInstance
g4b::UserActionFactory::UserActionFactory ( const UserActionFactory )
private

Member Function Documentation

const std::vector< std::string > & g4b::UserActionFactory::AvailableUserActions ( ) const

Definition at line 78 of file UserActionFactory.cxx.

References fFunctionMap, and listnames.

79 {
80  // list of names might be out of date due to new registrations
81  // rescan the std::map on each call (which won't be frequent)
82  listnames.clear();
83 
84  // scan map for registered names
86  for ( itr = fFunctionMap.begin(); itr != fFunctionMap.end(); ++itr )
87  listnames.push_back(itr->first);
88 
89  return listnames;
90 }
std::vector< std::string > listnames
std::map< std::string, UserActionCtorFuncPtr_t > fFunctionMap
intermediate_table::const_iterator const_iterator
UserAction * g4b::UserActionFactory::GetUserAction ( const std::string &  name)

Definition at line 46 of file UserActionFactory.cxx.

References fFunctionMap, and g4b::UserAction::SetName().

47 {
48  UserAction* p = 0;
49 
50  // we don't want map creating an entry if it doesn't exist
51  // so use map::find() not map::operator[]
53  = fFunctionMap.find(name);
54  if ( fFunctionMap.end() != itr ) {
55  // found an appropriate entry in the list
56  UserActionCtorFuncPtr_t foo = itr->second; // this is the function
57  p = (*foo)(); // use function to create the UserAction
58  p->SetName(name); // let object know its name
59  }
60  if ( ! p ) {
61  mf::LogWarning("UserAction") << "### UserActionFactory WARNING: "
62  << "UserAction " << name << " is not known";
63  }
64  return p;
65 }
intermediate_table::iterator iterator
std::map< std::string, UserActionCtorFuncPtr_t > fFunctionMap
g4b::UserAction *(* UserActionCtorFuncPtr_t)()
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
UserActionFactory & g4b::UserActionFactory::Instance ( )
static

Definition at line 31 of file UserActionFactory.cxx.

References fgTheInstance, g4b::UserActionFactory::Cleaner::UseMe(), and UserActionFactory().

32 {
33  // Cleaner dtor calls UserActionFactory dtor at job end
34  static Cleaner cleaner;
35 
36  if ( ! fgTheInstance ) {
37  // need to create one
38  cleaner.UseMe(); // dummy call to quiet compiler warnings
40  }
41 
42  return *fgTheInstance;
43 }
static UserActionFactory * fgTheInstance
bool g4b::UserActionFactory::IsKnownUserAction ( const std::string &  name)

Definition at line 67 of file UserActionFactory.cxx.

References fFunctionMap.

68 {
69  // check if we know the name
70  bool res = false;
72  = fFunctionMap.find(name);
73  if ( fFunctionMap.end() != itr ) res = true;
74  return res;
75 }
intermediate_table::iterator iterator
std::map< std::string, UserActionCtorFuncPtr_t > fFunctionMap
void g4b::UserActionFactory::operator= ( const UserActionFactory )
private
bool g4b::UserActionFactory::RegisterCreator ( std::string  name,
UserActionCtorFuncPtr_t  ctorptr,
bool *  ptr 
)

Definition at line 92 of file UserActionFactory.cxx.

References fBoolPtrMap, and fFunctionMap.

95 {
96  // record new functions for creating processes
97  fFunctionMap[name] = foo;
98  fBoolPtrMap[name] = boolptr;
99  return true;
100 }
std::map< std::string, UserActionCtorFuncPtr_t > fFunctionMap
std::map< std::string, bool * > fBoolPtrMap

Friends And Related Function Documentation

friend struct Cleaner
friend

Definition at line 88 of file UserActionFactory.h.

Member Data Documentation

std::map<std::string, bool*> g4b::UserActionFactory::fBoolPtrMap
private

Definition at line 60 of file UserActionFactory.h.

Referenced by RegisterCreator().

std::map<std::string, UserActionCtorFuncPtr_t> g4b::UserActionFactory::fFunctionMap
private
UserActionFactory * g4b::UserActionFactory::fgTheInstance
staticprivate
std::vector<std::string> g4b::UserActionFactory::listnames
mutableprivate

Definition at line 62 of file UserActionFactory.h.

Referenced by AvailableUserActions().


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