Sierra Toolkit Version of the Day
sierra::Plugin::Registry Class Reference

#include <UserPlugin.hpp>

List of all members.

Classes

struct  less_nocase
 Class hash_nocase implements a hash, case insensitive NamePair hash functor. More...

Public Types

typedef std::pair< const
std::type_info *, std::string > 
NamePair
 Typedef NamePair is the derived class key.
typedef std::map< NamePair,
void *, less_nocase
RegistryMap
 Typedef RegistryMap is the registration map.

Public Member Functions

 Registry ()
 Registry (const NamePair &name_pair)
 Creates a new Registry instance and registers it, and more importantly the derived class factory with the specified name pair.
virtual ~Registry ()
void registerIt (const NamePair &name_pair, void *func_ptr)
 Member function registerIt registers a name pair with a void pointer.
void * getPluginPtr (const NamePair &name_pair) const
 Member function getPluginPtr find the function with the name pair specified.
void * getFunctionPtr (const NamePair &name_pair) const
 Member function getFunctionPtr find the function with the name pair specified.
RegistrygetFactoryPtr (const NamePair &name) const
 Member function getFuncPtr returns the function pointer with the specfied <it>name_pair.
void * getFuncPtr (const NamePair &name_pair) const
 Member function getFuncPtr returns the function pointer with the specfied <it>name_pair.
std::vector< std::string > getDerivedNames (const std::type_info &type) const
 Member function getDerivedNames returns names assocaited with the function pointers of the specified type.
std::ostream & verbose_print (std::ostream &os) const
 Member function dump dumps the registry.
stk::diag::Writerverbose_print (stk::diag::Writer &dout) const
 Member function verbose_print dumps the registry.

Static Public Member Functions

static RegistryMapgetRegistryMap ()
static RegistryrootInstance ()
 Member function rootInstance creates the singleton.
static void registerDL (const char *so_path, const char *function_name=0)
 Member function registerDL opens a dynamic library and optionally executes a "C" registration function.
template<typename T >
static T getsym (const char *sym)
template<class T >
static T & create (const std::string &derived_name)

Detailed Description

Class Registry serves as a singleton for holding templatized createInstance and UserSubroutine function pointers and pointer to class factory objects. The registry is simply a mapping of name pairs to a void pointer. The name pair consists of the base class name and the derived class names. And, since the only legal way to get things into the registry is via the and UserSubroutine classes, there is no signature checking performed at this level

There should never be a need to instantiate this singleton as the UserSubroutine registration process should perform that function when necessary.

Definition at line 55 of file UserPlugin.hpp.


Constructor & Destructor Documentation

sierra::Plugin::Registry::Registry ( ) [inline]

Creates a new Registry instance.

Definition at line 123 of file UserPlugin.hpp.

sierra::Plugin::Registry::Registry ( const NamePair name_pair) [inline, explicit]

Creates a new Registry instance and registers it, and more importantly the derived class factory with the specified name pair.

Parameters:
name_paira NamePair gives the name to the registry entry.

Definition at line 133 of file UserPlugin.hpp.

virtual sierra::Plugin::Registry::~Registry ( ) [inline, virtual]

Destructor ~Registry is virtual to fake polymorphism so that the registry class can utilize additional compiler/runtime checks that the registered class is indeed a class factory.

Definition at line 142 of file UserPlugin.hpp.


Member Function Documentation

Registry & sierra::Plugin::Registry::rootInstance ( ) [static]

Member function rootInstance creates the singleton.

Returns:
a Registry reference to the Registry singleton.

Definition at line 44 of file UserPlugin.cpp.

void sierra::Plugin::Registry::registerDL ( const char *  so_path,
const char *  function_name = 0 
) [static]

Member function registerDL opens a dynamic library and optionally executes a "C" registration function.

If function is specified, and not zero length, the function must exist. If the function name specified with zero length, the function "dl_register" is executed if it exists. If the function name is not found, if platform specific fortran suffix is appended and the function is searched again.

If no function name is specified, no registration function is executed.

NOTE: Loading C++ sharable objects results in static object construction upon load.

Parameters:
so_patha char const pointer to the path of the shareable object file. If the path does not contains a '/' character, the file is searched for through the LD_LIBRARY_PATH envirnment variable.
function_namea char const pointer to the name of a registration function which will be called immediately after loading the sharable object.

Definition at line 151 of file UserPlugin.cpp.

void sierra::Plugin::Registry::registerIt ( const NamePair name_pair,
void *  func_ptr 
)

Member function registerIt registers a name pair with a void pointer.

If the name pair already exists within the registry, a std::invalid_argument exception is thrown with the offending name pair called out.

Parameters:
name_paira NamePair const reference to the name pair to be registered.
func_ptra void pointer to the function to be registered.
Exceptions:
astd::invalid_argument exception is thrown if there is an instance creation function already registered for the derived class.

Definition at line 54 of file UserPlugin.cpp.

void * sierra::Plugin::Registry::getPluginPtr ( const NamePair name_pair) const

Member function getPluginPtr find the function with the name pair specified.

If the name pair does not exist within the registry, a std::invalid_argument exception is thrown with the offending name pair called out.

Parameters:
name_paira NamePair const reference to the name pair to be retrieved.
Exceptions:
astd::invalid_argument exception is thrown if the function is not found.

Definition at line 75 of file UserPlugin.cpp.

void * sierra::Plugin::Registry::getFunctionPtr ( const NamePair name_pair) const

Member function getFunctionPtr find the function with the name pair specified.

If the name pair does not exist within the registry, a std::invalid_argument exception is thrown with the offending name pair called out.

Parameters:
name_paira NamePair const reference to the name pair to be retrieved.
Exceptions:
astd::invalid_argument exception is thrown if the function is not found.

Definition at line 93 of file UserPlugin.cpp.

Registry * sierra::Plugin::Registry::getFactoryPtr ( const NamePair name) const

Member function getFuncPtr returns the function pointer with the specfied <it>name_pair.

Parameters:
name_paira NamePair const reference to the registered name pair.
Returns:
a void function pointer with the specfied <it>name_pair.

Definition at line 110 of file UserPlugin.cpp.

void * sierra::Plugin::Registry::getFuncPtr ( const NamePair name_pair) const

Member function getFuncPtr returns the function pointer with the specfied <it>name_pair.

Parameters:
name_paira NamePair const reference to the registered name pair.
Returns:
a void function pointer with the specfied <it>name_pair.

Definition at line 126 of file UserPlugin.cpp.

std::vector< std::string > sierra::Plugin::Registry::getDerivedNames ( const std::type_info &  type) const

Member function getDerivedNames returns names assocaited with the function pointers of the specified type.

Parameters:
typea std::type_info const reference to typeid to retrieve the derived names.
Returns:
a std::vector<str::string> value of the derived names.

Definition at line 135 of file UserPlugin.cpp.

template<class T >
static T& sierra::Plugin::Registry::create ( const std::string &  derived_name) [inline, static]

Member template function create creates an instance of the desired object by providing the factory responsible for generating that object type. The create factory is retrieved using the base class name specified by the factory base class and the specified derived name.

The derived factory is responsible for implementing the appropriate operator() functions to constuct the derived object.

Parameters:
derived_namea std::string const reference to the derived object's name/
Returns:
a T reference to the creation factory object.

Definition at line 283 of file UserPlugin.hpp.

std::ostream & sierra::Plugin::Registry::verbose_print ( std::ostream &  os) const

Member function dump dumps the registry.

Parameters:
osa std::ostream reference to dump the registry to.
Returns:
a std::ostream reference to <it>os.

Definition at line 212 of file UserPlugin.cpp.

stk::diag::Writer & sierra::Plugin::Registry::verbose_print ( stk::diag::Writer dout) const

Member function verbose_print dumps the registry.

Parameters:
osa std::ostream reference to dump the registry to.
Returns:
a std::ostream reference to <it>os.

Definition at line 222 of file UserPlugin.cpp.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines