STIR  6.2.0
Classes | Public Member Functions | Static Public Member Functions | Friends | List of all members
stir::RegisteredParsingObject< Derived, Base, Parent > Class Template Reference

Parent class for all leaves in a RegisteredObject hierarchy that do parsing of parameter files. More...

#include "stir/RegisteredParsingObject.h"

Inherits Parent.

Classes

struct  RegisterIt
 A helper class to allow automatic registration. More...
 

Public Member Functions

std::string get_registered_name () const override
 Returns Derived::registered_name.
 
std::string parameter_info () override
 Returns a string with all parameters and their values, in a form suitable for parsing again.
 

Static Public Member Functions

static Base * read_from_stream (std::istream *)
 Construct a new object (of type Derived) by parsing the istream. More...
 

Friends

struct RegisterIt
 

Detailed Description

template<typename Derived, typename Base, typename Parent = Base>
class stir::RegisteredParsingObject< Derived, Base, Parent >

Parent class for all leaves in a RegisteredObject hierarchy that do parsing of parameter files.

See also
RegisteredObject for an explanation why you would use this class.

RegisteredParsingObject::read_from_stream is implemented in terms of ParsingObject::parse.

Requirements on the class Base:

Requirements on the class Derived:

Requirements on the class Parent:

Use the 2 parameter form if there is no ParsingObject anywhere in the hierarchy yet. However, we recommend to immediately derive Base from ParsingObject.

How to add a leaf to the registry at run-time.
Constructing the hierarchy as above makes sure that everything is ready. However, the registry needs to be filled at run-time. This could be done with user selection of the desired leaves (based on their registered_name), or just by entering all leaves in the registry.

A leaf will be entered in the hierarchy by declaring a variable as follows:

Derived::RegisterIt dummy;

As soon as the variable is destructed, the leaf will be taken out of the registry (but see todo). If you want to add it as long as the program runs, use a static variable.

Currently, STIR has static variables in files for each module (for instance, buildblock_registries.cxx). Note that these files have to be linked explicitly into your program, as opposed to sticking it in a library. This is because the linker will think that the variables in that file are never referenced, so would not include it in the final executable (to try to remove redundant object files).

Member Function Documentation

◆ read_from_stream()

template<typename Derived , typename Base , typename Parent >
Base * stir::RegisteredParsingObject< Derived, Base, Parent >::read_from_stream ( std::istream *  in)
inlinestatic

Construct a new object (of type Derived) by parsing the istream.

When the istream * is 0, questions are asked interactively.

Todo:
Currently, the return value is a Base*. Preferably, it should be a Derived*, but it seems the registration machinery would need extra (unsafe) reinterpret_casts to get that to work. (TODO find a remedy).

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