Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

ers::IssueFactory Class Reference

Factory for all Issues. More...

#include <IssueFactory.h>

List of all members.

Public Types

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

Public Member Functions

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

Static Public Member Functions

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

Protected Member Functions

 IssueFactory ()
 IssueFactory ()

Protected Attributes

CallbackMap m_factory_map

Static Protected Attributes

IssueFactorys_factory
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


Member Typedef Documentation

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

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

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

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


Constructor & Destructor Documentation

ers::IssueFactory::IssueFactory  )  [protected]
 

00021 {} ; 

ers::IssueFactory::IssueFactory  )  [protected]
 


Member Function Documentation

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

build a clone of an issue

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

build a issue out of name and set values

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

build an empty issue out of a name

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:
original the Issue to be cloned
Returns:
a new cloned Issued
Note:
The problem of cause exception is not handled yet.
00091                                                       {
00092     ERS_PRE_CHECK_PTR(original); 
00093     const std::string name = original->get_class_name() ; 
00094     const ers::string_map_type *values = original->get_value_table();
00095     ERS_ASSERT(values!=0,"null value table for original"); 
00096     ers::Issue *clone_issue = build(name,values);
00097     return clone_issue ; 
00098 }// build

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:
name the name used to indentify the class
values the value-table containing the state for the Issue
Returns:
an newly allocated instance of this type or null if the name is not registered
00076                                                                                               {
00077     Issue *i = build(name);
00078     if (i) {
00079         i->set_values(*values); 
00080     } // if i
00081     return i ; 
00082 } // build

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:
name the 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
00057                                                             {
00058     CallbackMap::const_iterator i = m_factory_map.find(name); 
00059     if (i == m_factory_map.end()) {
00060         // throw ERS_ISSUE_FACTORY_ERROR(name,"issue not registred") ; 
00061         return new DefaultIssue(name); 
00062     } // Not found
00063     ers::Issue *issue = (i->second)() ; 
00064     if (0==issue) {
00065         throw ERS_ISSUE_FACTORY_ERROR(name,"factory function returned null"); 
00066     } // issue null 
00067     return issue ; 
00068 } // build

IssueFactory* ers::IssueFactory::instance  )  [static]
 

method to access singleton

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
00028                                             {
00029     if (0==s_factory) {
00030         s_factory = new IssueFactory();
00031     } // creation needed
00032     return s_factory ; 
00033 } // instance

void ers::IssueFactory::print_registered  )  [static]
 

prints all registered issue types

void ers::IssueFactory::print_registered  )  [static]
 

prints all registered issue types

00035                                        {
00036     IssueFactory *factory = instance() ; 
00037     std::cerr << *factory; 
00038 } //print_registered_issues

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

register an issue factory

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

register an issue factory

Register an issue type with the factory

Parameters:
name the name that will be used to lookup new instances
creator a 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
00047                                                                                        {
00048     return m_factory_map.insert(CallbackMap::value_type(name,creator)).second; 
00049 } // register_Issue

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

writes description to stream

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

writes description to stream

00100                                                        {
00101     stream << "Issue factory - registered issues\n" ; 
00102     stream << "---------------------------------\n" ; 
00103     int i = 0 ; 
00104     for(CallbackMap::const_iterator pos=m_factory_map.begin();pos!=m_factory_map.end();++pos) {
00105         std::string name = pos->first; 
00106         stream << i << ")\t" << name << std::endl; 
00107         i++ ; 
00108     } // for
00109     stream << "---------------------------------\n" ; 
00110 } // 


Member Data Documentation

CallbackMap ers::IssueFactory::m_factory_map [protected]
 

IssueFactory* ers::IssueFactory::s_factory [static, protected]
 

ers::IssueFactory * ers::IssueFactory::s_factory = 0 [static, protected]
 


The documentation for this class was generated from the following files:
Generated on Wed Feb 2 19:19:51 2011 for BOSS6.5.5 by  doxygen 1.3.9.1