Classes | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
genie::flux::GFlavorMixerFactory Class Reference

A class for generating concrete GFlavorMixerI derived classes based on the factory pattern. This code supplies a CPP macro which allows the classes to self-register and thus no modification of this class is needed in order to expand the list of classes it knows about. More...

#include <GFlavorMixerFactory.h>

Classes

struct  Cleaner
 

Public Member Functions

genie::flux::GFlavorMixerIGetFlavorMixer (const std::string &)
 
bool IsKnownFlavorMixer (const std::string &)
 
const std::vector< std::string > & AvailableFlavorMixers () const
 
bool RegisterCreator (std::string name, GFlavorMixerICtorFuncPtr_t ctorptr, bool *ptr)
 

Static Public Member Functions

static GFlavorMixerFactoryInstance ()
 

Private Member Functions

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

Private Attributes

std::map< std::string, GFlavorMixerICtorFuncPtr_tfFunctionMap
 
std::map< std::string, bool * > fBoolPtrMap
 
std::vector< std::stringlistnames
 

Static Private Attributes

static GFlavorMixerFactoryfgTheInstance
 

Friends

struct Cleaner
 

Detailed Description

A class for generating concrete GFlavorMixerI derived classes based on the factory pattern. This code supplies a CPP macro which allows the classes to self-register and thus no modification of this class is needed in order to expand the list of classes it knows about.

Implemented as a singleton holding a map between names and pointers-to-functions (that call a class default constructor). The functions pointers must return GFlavorMixerI*.

Author
Robert Hatcher <rhatcher fnal.gov> Fermi National Accelerator Laboratory

Copyright (c) 2003-2020, The GENIE Collaboration for the full text of the license visit http://copyright.genie-mc.org

Definition at line 43 of file GFlavorMixerFactory.h.

Constructor & Destructor Documentation

genie::flux::GFlavorMixerFactory::GFlavorMixerFactory ( )
private

Definition at line 20 of file GFlavorMixerFactory.cxx.

21 {
22  fgTheInstance = this; // record created self in static pointer
23 }
static GFlavorMixerFactory * fgTheInstance
genie::flux::GFlavorMixerFactory::~GFlavorMixerFactory ( )
privatevirtual

Definition at line 25 of file GFlavorMixerFactory.cxx.

26 {
27  fgTheInstance = 0;
28 }
static GFlavorMixerFactory * fgTheInstance
genie::flux::GFlavorMixerFactory::GFlavorMixerFactory ( const GFlavorMixerFactory )
private

Member Function Documentation

const std::vector< std::string > & genie::flux::GFlavorMixerFactory::AvailableFlavorMixers ( ) const

Definition at line 76 of file GFlavorMixerFactory.cxx.

77 {
78  // list of names might be out of date due to new registrations
79  // rescan the std::map on each call (which won't be frequent)
80  listnames.clear();
81 
82  // scan map for registered names
84  for ( itr = fFunctionMap.begin(); itr != fFunctionMap.end(); ++itr )
85  listnames.push_back(itr->first);
86 
87  return listnames;
88 }
intermediate_table::const_iterator const_iterator
std::vector< std::string > listnames
std::map< std::string, GFlavorMixerICtorFuncPtr_t > fFunctionMap
GFlavorMixerI * genie::flux::GFlavorMixerFactory::GetFlavorMixer ( const std::string name)

Definition at line 45 of file GFlavorMixerFactory.cxx.

46 {
47  GFlavorMixerI* p = 0;
48 
49  // we don't want map creating an entry if it doesn't exist
50  // so use map::find() not map::operator[]
52  = fFunctionMap.find(name);
53  if ( fFunctionMap.end() != itr ) {
54  // found an appropriate entry in the list
55  GFlavorMixerICtorFuncPtr_t foo = itr->second; // this is the function
56  p = (*foo)(); // use function to create the GFlavorMixerI
57  }
58  if ( ! p ) {
59  LOG("Flux",pWARN) << "### GFlavorMixerFactory WARNING: "
60  << "GFlavorMixerI " << name << " is not known";
61  }
62  return p;
63 }
static QCString name
Definition: declinfo.cpp:673
intermediate_table::iterator iterator
genie::flux::GFlavorMixerI *(* GFlavorMixerICtorFuncPtr_t)()
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
p
Definition: test.py:223
#define pWARN
Definition: Messenger.h:60
std::map< std::string, GFlavorMixerICtorFuncPtr_t > fFunctionMap
GFlavorMixerFactory & genie::flux::GFlavorMixerFactory::Instance ( void  )
static

Definition at line 30 of file GFlavorMixerFactory.cxx.

31 {
32  // Cleaner dtor calls GFlavorMixerFactory dtor at job end
33  static Cleaner cleaner;
34 
35  if ( ! fgTheInstance ) {
36  // need to create one
37  cleaner.UseMe(); // dummy call to quiet compiler warnings
39  }
40 
41  return *fgTheInstance;
42 }
static GFlavorMixerFactory * fgTheInstance
bool genie::flux::GFlavorMixerFactory::IsKnownFlavorMixer ( const std::string name)

Definition at line 65 of file GFlavorMixerFactory.cxx.

66 {
67  // check if we know the name
68  bool res = false;
70  = fFunctionMap.find(name);
71  if ( fFunctionMap.end() != itr ) res = true;
72  return res;
73 }
static QCString name
Definition: declinfo.cpp:673
intermediate_table::iterator iterator
std::map< std::string, GFlavorMixerICtorFuncPtr_t > fFunctionMap
void genie::flux::GFlavorMixerFactory::operator= ( const GFlavorMixerFactory )
private
bool genie::flux::GFlavorMixerFactory::RegisterCreator ( std::string  name,
GFlavorMixerICtorFuncPtr_t  ctorptr,
bool ptr 
)

Definition at line 90 of file GFlavorMixerFactory.cxx.

93 {
94  // record new functions for creating processes
95  fFunctionMap[name] = foo;
96  fBoolPtrMap[name] = boolptr;
97  return true;
98 }
static QCString name
Definition: declinfo.cpp:673
std::map< std::string, bool * > fBoolPtrMap
std::map< std::string, GFlavorMixerICtorFuncPtr_t > fFunctionMap

Friends And Related Function Documentation

friend struct Cleaner
friend

Definition at line 97 of file GFlavorMixerFactory.h.

Member Data Documentation

std::map<std::string, bool*> genie::flux::GFlavorMixerFactory::fBoolPtrMap
private

Definition at line 69 of file GFlavorMixerFactory.h.

std::map<std::string, GFlavorMixerICtorFuncPtr_t> genie::flux::GFlavorMixerFactory::fFunctionMap
private

Definition at line 66 of file GFlavorMixerFactory.h.

GFlavorMixerFactory * genie::flux::GFlavorMixerFactory::fgTheInstance
staticprivate

Definition at line 63 of file GFlavorMixerFactory.h.

std::vector<std::string> genie::flux::GFlavorMixerFactory::listnames
mutableprivate

Definition at line 71 of file GFlavorMixerFactory.h.


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