GENIEGenerator
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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>

Collaboration diagram for genie::flux::GFlavorMixerFactory:
Collaboration graph
[legend]

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_t
fFunctionMap
 
std::map< std::string, bool * > fBoolPtrMap
 
std::vector< std::string > listnames
 

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
Created:
License:
Copyright (c) 2003-2024, 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.

References fgTheInstance.

Referenced by Instance().

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.

References fgTheInstance.

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.

References fFunctionMap, and listnames.

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
83  std::map<std::string, GFlavorMixerICtorFuncPtr_t>::const_iterator itr;
84  for ( itr = fFunctionMap.begin(); itr != fFunctionMap.end(); ++itr )
85  listnames.push_back(itr->first);
86 
87  return listnames;
88 }
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.

References fFunctionMap, LOG, and pWARN.

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[]
51  std::map<std::string, GFlavorMixerICtorFuncPtr_t>::iterator itr
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 }
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
#define pWARN
Definition: Messenger.h:60
const char * name
std::map< std::string, GFlavorMixerICtorFuncPtr_t > fFunctionMap
genie::flux::GFlavorMixerI *(* GFlavorMixerICtorFuncPtr_t)()
GFlavorMixerFactory & genie::flux::GFlavorMixerFactory::Instance ( void  )
static

Definition at line 30 of file GFlavorMixerFactory.cxx.

References fgTheInstance, GFlavorMixerFactory(), and genie::flux::GFlavorMixerFactory::Cleaner::UseMe().

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.

References fFunctionMap.

66 {
67  // check if we know the name
68  bool res = false;
69  std::map<std::string, GFlavorMixerICtorFuncPtr_t>::iterator itr
70  = fFunctionMap.find(name);
71  if ( fFunctionMap.end() != itr ) res = true;
72  return res;
73 }
const char * name
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.

References fBoolPtrMap, and fFunctionMap.

93 {
94  // record new functions for creating processes
95  fFunctionMap[name] = foo;
96  fBoolPtrMap[name] = boolptr;
97  return true;
98 }
std::map< std::string, bool * > fBoolPtrMap
const char * name
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.

Referenced by RegisterCreator().

std::map<std::string, GFlavorMixerICtorFuncPtr_t> genie::flux::GFlavorMixerFactory::fFunctionMap
private
GFlavorMixerFactory * genie::flux::GFlavorMixerFactory::fgTheInstance
staticprivate
std::vector<std::string> genie::flux::GFlavorMixerFactory::listnames
mutableprivate

Definition at line 71 of file GFlavorMixerFactory.h.

Referenced by AvailableFlavorMixers().


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