BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
ers::IssueFactory Class Reference

Factory for all Issues. More...

#include <IssueFactory.h>

Public Types

typedef Issue *(* CreateIssueCallback) ()
typedef std::map< std::string, CreateIssueCallbackCallbackMap
typedef Issue *(* CreateIssueCallback) ()
typedef std::map< std::string, CreateIssueCallbackCallbackMap
typedef Issue *(* CreateIssueCallback) ()
typedef std::map< std::string, CreateIssueCallbackCallbackMap

Public Member Functions

bool register_issue (const std::string &name, CreateIssueCallback creator)
 register an issue factory
Issuebuild (const std::string &name) const
 build an empty issue out of a name
Issuebuild (const std::string &name, const string_map_type *values) const
 build a issue out of name and set values
Issuebuild (const Issue *original)
 build a clone of an issue
void write_to (std::ostream &stream) const
 writes description to stream
bool register_issue (const std::string &name, CreateIssueCallback creator)
 register an issue factory
Issuebuild (const std::string &name) const
 build an empty issue out of a name
Issuebuild (const std::string &name, const string_map_type *values) const
 build a issue out of name and set values
Issuebuild (const Issue *original)
 build a clone of an issue
void write_to (std::ostream &stream) const
 writes description to stream
bool register_issue (const std::string &name, CreateIssueCallback creator)
 register an issue factory
Issuebuild (const std::string &name) const
 build an empty issue out of a name
Issuebuild (const std::string &name, const string_map_type *values) const
 build a issue out of name and set values
Issuebuild (const Issue *original)
 build a clone of an issue
void write_to (std::ostream &stream) const
 writes description to stream

Static Public Member Functions

static IssueFactoryinstance ()
 method to access singleton
static void print_registered ()
 prints all registered issue types
static IssueFactoryinstance ()
 method to access singleton
static void print_registered ()
 prints all registered issue types
static IssueFactoryinstance ()
 method to access singleton
static void print_registered ()
 prints all registered issue types

Protected Member Functions

 IssueFactory ()
 IssueFactory ()
 IssueFactory ()

Protected Attributes

CallbackMap m_factory_map

Static Protected Attributes

static IssueFactorys_factory = 0

Detailed Description

Factory for all Issues.

This class implements the factory pattern for Issues. The main responsability of this class is to keep track of the existing types of Issues Each issue should register one factory method for instances of this class. This is needed for deserializing of Issues.

Author
Matthias Wiesmann
Version
1.0

Definition at line 31 of file Event/ers/include/ers/IssueFactory.h.

Member Typedef Documentation

◆ CallbackMap [1/3]

typedef std::map<std::string, CreateIssueCallback> ers::IssueFactory::CallbackMap

Definition at line 34 of file Event/ers/include/ers/IssueFactory.h.

◆ CallbackMap [2/3]

◆ CallbackMap [3/3]

◆ CreateIssueCallback [1/3]

typedef Issue *(* ers::IssueFactory::CreateIssueCallback) ()

Definition at line 33 of file Event/ers/include/ers/IssueFactory.h.

◆ CreateIssueCallback [2/3]

typedef Issue *(* ers::IssueFactory::CreateIssueCallback) ()

◆ CreateIssueCallback [3/3]

typedef Issue *(* ers::IssueFactory::CreateIssueCallback) ()

Constructor & Destructor Documentation

◆ IssueFactory() [1/3]

ers::IssueFactory::IssueFactory ( )
protected

Definition at line 21 of file IssueFactory.cxx.

21{}

Referenced by instance(), IssueFactory(), and print_registered().

◆ IssueFactory() [2/3]

ers::IssueFactory::IssueFactory ( )
protected

◆ IssueFactory() [3/3]

ers::IssueFactory::IssueFactory ( )
protected

Member Function Documentation

◆ build() [1/9]

ers::Issue * ers::IssueFactory::build ( const Issue * original)

build a clone of an issue

Clones an Issue. This method creates (using the other build methods) an new Issue with the same value table

Parameters
originalthe Issue to be cloned
Returns
a new cloned Issued
Note
The problem of cause exception is not handled yet.

Definition at line 88 of file IssueFactory.cxx.

88 {
89 ERS_PRE_CHECK_PTR( original );
90 const std::string name = original->get_class_name();
91 const ers::string_map_type* values = original->get_value_table();
92 ERS_ASSERT( values != 0, "null value table for original" );
93 ers::Issue* clone_issue = build( name, values );
94 return clone_issue;
95} // build
#define ERS_ASSERT(expr,...)
Issue * build(const std::string &name) const
build an empty issue out of a name
std::map< std::string, std::string > string_map_type

◆ build() [2/9]

Issue * ers::IssueFactory::build ( const Issue * original)

build a clone of an issue

◆ build() [3/9]

Issue * ers::IssueFactory::build ( const Issue * original)

build a clone of an issue

◆ build() [4/9]

ers::Issue * ers::IssueFactory::build ( const std::string & name) const

build an empty issue out of a name

Builds an issue out of the name it was registered with

Parameters
namethe name used to indentify the class
Returns
an newly allocated instance of type name or DefaultIssue
Note
If the requested type cannot be resolved an instance of type DefaultIssue

Definition at line 55 of file IssueFactory.cxx.

55 {
56 CallbackMap::const_iterator i = m_factory_map.find( name );
57 if ( i == m_factory_map.end() )
58 {
59 // throw ERS_ISSUE_FACTORY_ERROR(name,"issue not registred") ;
60 return new DefaultIssue( name );
61 } // Not found
62 ers::Issue* issue = ( i->second )();
63 if ( 0 == issue )
64 { throw ERS_ISSUE_FACTORY_ERROR( name, "factory function returned null" ); } // issue null
65 return issue;
66} // build
#define ERS_ISSUE_FACTORY_ERROR(name, message)

Referenced by build(), build(), and ers::Issue::clone().

◆ build() [5/9]

Issue * ers::IssueFactory::build ( const std::string & name) const

build an empty issue out of a name

◆ build() [6/9]

Issue * ers::IssueFactory::build ( const std::string & name) const

build an empty issue out of a name

◆ build() [7/9]

ers::Issue * ers::IssueFactory::build ( const std::string & name,
const string_map_type * values ) const

build a issue out of name and set values

Builds an issue out of a name and a value table

Parameters
namethe name used to indentify the class
valuesthe value-table containing the state for the Issue
Returns
an newly allocated instance of this type or null if the name is not registered

Definition at line 74 of file IssueFactory.cxx.

75 {
76 Issue* i = build( name );
77 if ( i ) { i->set_values( *values ); } // if i
78 return i;
79} // build

◆ build() [8/9]

Issue * ers::IssueFactory::build ( const std::string & name,
const string_map_type * values ) const

build a issue out of name and set values

◆ build() [9/9]

Issue * ers::IssueFactory::build ( const std::string & name,
const string_map_type * values ) const

build a issue out of name and set values

◆ instance() [1/3]

ers::IssueFactory * ers::IssueFactory::instance ( )
static

method to access singleton

Finds the singleton instance of the factory. If the instance is not allocated yet, it is.

Returns
a pointer to the singleton instance

Definition at line 28 of file IssueFactory.cxx.

28 {
29 if ( 0 == s_factory ) { s_factory = new IssueFactory(); } // creation needed
30 return s_factory;
31} // instance

Referenced by ers::Issue::clone(), and print_registered().

◆ instance() [2/3]

IssueFactory * ers::IssueFactory::instance ( )
static

method to access singleton

◆ instance() [3/3]

IssueFactory * ers::IssueFactory::instance ( )
static

method to access singleton

◆ print_registered() [1/3]

void ers::IssueFactory::print_registered ( )
static

prints all registered issue types

Definition at line 33 of file IssueFactory.cxx.

33 {
35 std::cerr << *factory;
36} // print_registered_issues
static IssueFactory * instance()
method to access singleton
efhlt::Interface * factory(void)
Definition factory.cxx:15

◆ print_registered() [2/3]

void ers::IssueFactory::print_registered ( )
static

prints all registered issue types

◆ print_registered() [3/3]

void ers::IssueFactory::print_registered ( )
static

prints all registered issue types

◆ register_issue() [1/3]

bool ers::IssueFactory::register_issue ( const std::string & name,
CreateIssueCallback creator )

register an issue factory

Register an issue type with the factory

Parameters
namethe name that will be used to lookup new instances
creatora pointer to the function used to create new instance for that particular type of function
Returns
true if the name was already present in the table

Definition at line 44 of file IssueFactory.cxx.

45 {
46 return m_factory_map.insert( CallbackMap::value_type( name, creator ) ).second;
47} // register_Issue

◆ register_issue() [2/3]

bool ers::IssueFactory::register_issue ( const std::string & name,
CreateIssueCallback creator )

register an issue factory

◆ register_issue() [3/3]

bool ers::IssueFactory::register_issue ( const std::string & name,
CreateIssueCallback creator )

register an issue factory

◆ write_to() [1/3]

void ers::IssueFactory::write_to ( std::ostream & stream) const

writes description to stream

Definition at line 97 of file IssueFactory.cxx.

97 {
98 stream << "Issue factory - registered issues\n";
99 stream << "---------------------------------\n";
100 int i = 0;
101 for ( CallbackMap::const_iterator pos = m_factory_map.begin(); pos != m_factory_map.end();
102 ++pos )
103 {
104 std::string name = pos->first;
105 stream << i << ")\t" << name << std::endl;
106 i++;
107 } // for
108 stream << "---------------------------------\n";
109} //

◆ write_to() [2/3]

void ers::IssueFactory::write_to ( std::ostream & stream) const

writes description to stream

◆ write_to() [3/3]

void ers::IssueFactory::write_to ( std::ostream & stream) const

writes description to stream

Member Data Documentation

◆ m_factory_map

CallbackMap ers::IssueFactory::m_factory_map
protected

Definition at line 38 of file Event/ers/include/ers/IssueFactory.h.

Referenced by build(), IssueFactory(), register_issue(), and write_to().

◆ s_factory

IssueFactory * ers::IssueFactory::s_factory = 0
staticprotected

Definition at line 39 of file Event/ers/include/ers/IssueFactory.h.

Referenced by instance(), and IssueFactory().


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