STIR
6.2.0
|
Helper class to provide registry mechanisms to a Base
classSuppose you have a hierarchy of classes with (nearly) all public functionality provided by virtual functions of the Base
(here called Root
) class. The aim is then to be able to select at run-time which of the nodes will be used.
More...
#include "stir/RegisteredObject.h"
Static Public Member Functions | |
static Root * | read_registered_object (std::istream *in, const std::string ®istered_name) |
Construct a new object (of a type derived from Root, its actual type determined by the registered_name parameter) by parsing the istream. More... | |
static Root * | ask_type_and_parameters () |
ask the user for the type, and then calls read_registered_object(0, type) More... | |
static void | list_registered_names (std::ostream &stream) |
List all possible registered names to the stream. More... | |
Protected Types | |
typedef Root *(* | RootFactory) (std::istream *) |
The type of a root factory is a function, taking an istream* as argument, and returning a Root*. | |
typedef FactoryRegistry< std::string, RootFactory, interfile_less > | RegistryType |
The type of the registry. | |
Static Protected Member Functions | |
static RegistryType & | registry () |
Static function returning the registry. More... | |
Additional Inherited Members | |
Public Member Functions inherited from stir::RegisteredObjectBase | |
virtual std::string | get_registered_name () const =0 |
Returns the name of the type of the object. More... | |
Public Member Functions inherited from stir::ParsingObject | |
ParsingObject (const ParsingObject &) | |
ParsingObject & | operator= (const ParsingObject &) |
void | ask_parameters () |
virtual std::string | parameter_info () |
bool | parse (std::istream &f) |
bool | parse (const char *const filename) |
Protected Member Functions inherited from stir::ParsingObject | |
virtual void | set_defaults () |
Set defaults before parsing. | |
virtual void | initialise_keymap () |
Initialise all keywords. | |
virtual bool | post_processing () |
This will be called at the end of the parsing. More... | |
virtual void | set_key_values () |
This will be called before parsing or parameter_info is called. More... | |
Protected Attributes inherited from stir::ParsingObject | |
KeyParser | parser |
Helper class to provide registry mechanisms to a Base
class
Suppose you have a hierarchy of classes with (nearly) all public functionality provided by virtual functions of the Base
(here called Root
) class. The aim is then to be able to select at run-time which of the nodes will be used.
To do this, one needs to enter all node classes in a registry. This registry contains a key and a "Root factory" for every node-class. The factory for the node-class returns (a pointer to) a new node-class object, which of course is also a Root object.
In STIR, FactoryRegistry provides the type for the registry.
In many cases, the factory constructs the new object from a stream. The current class provides the basic mechanisms for this, i.e. a registry, and a function that looks up the relevant factory in the registry and uses it to construct the object from a stream. In addition, there is an interactive function for asking the type and its parameters. This makes only sense if the object construction can be interactive as well (see ask_type_and_parameters()).
We currently assume that the construction of the object is done by using ParsingObject. Nearly all of the necessary functionality can be provided to the hierarchy by using RegisteredParsingObject in the hierarchy. The hierarchy looks normally as follows:
When there is no intermediate class in hierarchy, this is simplified to:
In the previous (including STIR 4.x) version of this hierarchy, ParsingObject wasn't at the root of everything. However, the current hierarchy is simpler to use, and you can still override relevant members such that ParsingObject is effectively not used.
|
inlinestatic |
Construct a new object (of a type derived from Root, its actual type determined by the registered_name parameter) by parsing the istream.
This works by finding the 'root factory' object in a registry that corresponds to registered_name, and calling the factory on this istream*.
|
inlinestatic |
ask the user for the type, and then calls read_registered_object(0, type)
Sadly, this function cannot be called ask_parameters() because of conflicts with ParsingObject::ask_parameters() in the derived classes.
|
inlinestatic |
List all possible registered names to the stream.
Names are separated with newlines.
|
inlinestaticprotected |
Static function returning the registry.