STIR 6.4.0
stir::RegisteredObject< Root > Class Template Reference

Helper class to provide registry mechanisms to a Base class. More...

#include "stir/RegisteredObject.h"

Inheritance diagram for stir::RegisteredObject< Root >:

Static Public Member Functions

static Root * read_registered_object (std::istream *in, const std::string &registered_name)
 Construct a new object (of a type derived from Root, its actual type determined by the registered_name parameter) by parsing the istream.
 
static Root * ask_type_and_parameters ()
 ask the user for the type, and then calls read_registered_object(0, type)
 
static void list_registered_names (std::ostream &stream)
 List all possible registered names to the stream.
 

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_lessRegistryType
 The type of the registry.
 

Static Protected Member Functions

static RegistryTyperegistry ()
 Static function returning the registry.
 

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.
 
- Public Member Functions inherited from stir::ParsingObject
 ParsingObject (const ParsingObject &)
 
ParsingObjectoperator= (const ParsingObject &)
 
bool parse (std::istream &f)
 
bool parse (const char *const filename)
 
void ask_parameters ()
 
virtual std::string parameter_info ()
 
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.
 
virtual void set_key_values ()
 This will be called before parsing or parameter_info is called.
 
KeyParser parser
 

Detailed Description

template<typename Root>
class stir::RegisteredObject< Root >

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:

RegisteredObject<Root>
Root
...
Parent
Derived
A base class for objects that want to be able to parse parameter files.
Definition ParsingObject.h:45
Base class for all classes that can parse .par files (and more?)The only reason that this class exist...
Definition RegisteredObjectBase.h:41
Parent class for all leaves in a RegisteredObject hierarchy that do parsing of parameter files.
Definition RegisteredParsingObject.h:78

When there is no intermediate class in hierarchy, this is simplified to:

See also
RegisteredParsingObject
Todo
Currently there is a hard-wired value of "None" for the default key (with a 0 factory). This is inappropriate in some cases.
Limitation:

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.

Member Function Documentation

◆ read_registered_object()

template<class Root>
Root * stir::RegisteredObject< Root >::read_registered_object ( std::istream * in,
const std::string & registered_name )
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*.

References read_registered_object(), and registry().

Referenced by ask_type_and_parameters(), read_registered_object(), and distributed::receive_and_initialize_projectors().

◆ ask_type_and_parameters()

template<class Root>
Root * stir::RegisteredObject< Root >::ask_type_and_parameters ( )
inlinestatic

ask the user for the type, and then calls read_registered_object(0, type)

Warning
Relies on read_registered_object to be interactive when its first argument is 0.

Sadly, this function cannot be called ask_parameters() because of conflicts with ParsingObject::ask_parameters() in the derived classes.

References stir::ask_string(), ask_type_and_parameters(), list_registered_names(), and read_registered_object().

Referenced by ask_type_and_parameters().

◆ list_registered_names()

template<class Root>
void stir::RegisteredObject< Root >::list_registered_names ( std::ostream & stream)
inlinestatic

List all possible registered names to the stream.

Names are separated with newlines.

References list_registered_names(), and registry().

Referenced by ask_type_and_parameters(), and list_registered_names().

◆ registry()

template<class Root>
RegisteredObject< Root >::RegistryType & stir::RegisteredObject< Root >::registry ( )
inlinestaticprotected

Static function returning the registry.

Warning
This function is non inline when using Visual C++ 6.0 because of a compiler limitation. This means that when using this compiler, RegisteredObject will need explicit instantiations for all derived classes.

References registry().

Referenced by list_registered_names(), read_registered_object(), and registry().


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