GENIEGenerator
Loading...
Searching...
No Matches
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:
[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_tfFunctionMap
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 \at fnal.gov> Fermi National Accelerator Laboratory
Created:\n
License:\n Copyright (c) 2003-2025, 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

◆ GFlavorMixerFactory() [1/2]

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

References fgTheInstance.

Referenced by GFlavorMixerFactory(), Instance(), and operator=().

◆ ~GFlavorMixerFactory()

genie::flux::GFlavorMixerFactory::~GFlavorMixerFactory ( )
privatevirtual

Definition at line 25 of file GFlavorMixerFactory.cxx.

26{
27 fgTheInstance = 0;
28}

References fgTheInstance.

◆ GFlavorMixerFactory() [2/2]

genie::flux::GFlavorMixerFactory::GFlavorMixerFactory ( const GFlavorMixerFactory & )
private

References GFlavorMixerFactory().

Member Function Documentation

◆ AvailableFlavorMixers()

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
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

References fFunctionMap, and listnames.

◆ GetFlavorMixer()

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[]
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
genie::flux::GFlavorMixerI *(* GFlavorMixerICtorFuncPtr_t)()

References fFunctionMap, LOG, and pWARN.

◆ Instance()

GFlavorMixerFactory & genie::flux::GFlavorMixerFactory::Instance ( )
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}

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

◆ IsKnownFlavorMixer()

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;
69 std::map<std::string, GFlavorMixerICtorFuncPtr_t>::iterator itr
70 = fFunctionMap.find(name);
71 if ( fFunctionMap.end() != itr ) res = true;
72 return res;
73}

References fFunctionMap.

◆ operator=()

void genie::flux::GFlavorMixerFactory::operator= ( const GFlavorMixerFactory & )
private

References GFlavorMixerFactory().

◆ RegisterCreator()

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}
std::map< std::string, bool * > fBoolPtrMap

References fBoolPtrMap, and fFunctionMap.

◆ Cleaner

friend struct Cleaner
friend

Definition at line 97 of file GFlavorMixerFactory.h.

Member Data Documentation

◆ fBoolPtrMap

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

Definition at line 69 of file GFlavorMixerFactory.h.

Referenced by RegisterCreator().

◆ fFunctionMap

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

◆ fgTheInstance

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

◆ listnames

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: