STIR 6.4.0
RegisteredParsingObject.h
Go to the documentation of this file.
1//
2//
3/*
4 Copyright (C) 2000- 2007, Hammersmith Imanet Ltd
5 This file is part of STIR.
6
7 SPDX-License-Identifier: Apache-2.0
8
9 See STIR/LICENSE.txt for details
10*/
20
21#ifndef __stir_RegisteredParsingObject_H__
22#define __stir_RegisteredParsingObject_H__
23
24#include "stir/ParsingObject.h"
25#include <string>
26
27START_NAMESPACE_STIR
76template <typename Derived, typename Base, typename Parent = Base>
77class RegisteredParsingObject : public Parent
78{
79public:
80 // import constructors from Parent
81 // Note: disabled for older SWIG as that generates an error before 4.2, and a warning for 4.2
82#if !defined(SWIG) || (SWIG_VERSION >= 0x040300)
83 using Parent::Parent;
84#endif
85
87
94 inline static Base* read_from_stream(std::istream*);
95
97 inline std::string get_registered_name() const override;
99 inline std::string parameter_info() override;
100
101public:
102#ifndef SWIG
105 {
108 {
109 // std::cerr << "Adding " << Derived::registered_name <<" to registry"<<std::endl;
110 // note: VC 7.0 needs a '&' in front of read_from_stream for some reason
111 Parent::registry().add_to_registry(Derived::registered_name, &read_from_stream);
112 }
113
120 {
121# if 0
122 // does not work yet, as registry might be destructed before this
123 // RegisterIt object. A solution to this problem is coming up.
124 cerr << "In RegisterIt destructor for " << Derived::registered_name<<endl;
125 cerr <<"Current keys: ";
126 Parent::registry().list_keys(cerr);
127 Parent::registry().remove_from_registry(Derived::registered_name);
128# endif
129 }
130 };
131 // RegisterIt needs to be a friend to have access to registry()
132 friend struct RegisterIt;
133#endif
134};
135
136END_NAMESPACE_STIR
137
139
140#endif
Declaration of class stir::ParsingObject.
Inline implementations for class stir::RegisteredParsingObject.
Parent class for all leaves in a RegisteredObject hierarchy that do parsing of parameter files.
Definition RegisteredParsingObject.h:78
static Base * read_from_stream(std::istream *)
Construct a new object (of type Derived) by parsing the istream.
Definition RegisteredParsingObject.inl:32
std::string parameter_info() override
Returns a string with all parameters and their values, in a form suitable for parsing again.
Definition RegisteredParsingObject.inl:51
std::string get_registered_name() const override
Returns Derived::registered_name.
Definition RegisteredParsingObject.inl:25
RegisterIt()
Default constructor adds the type to the registry.
Definition RegisteredParsingObject.h:107
~RegisterIt()
Destructor should remove it from the registry.
Definition RegisteredParsingObject.h:119