STIR  6.2.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 */
21 #ifndef __stir_RegisteredParsingObject_H__
22 #define __stir_RegisteredParsingObject_H__
23 
24 #include "stir/ParsingObject.h"
25 #include <string>
26 
27 START_NAMESPACE_STIR
76 template <typename Derived, typename Base, typename Parent = Base>
77 class RegisteredParsingObject : public Parent
78 {
79 public:
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 
101 public:
102 #ifndef SWIG
103  struct RegisterIt
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 
136 END_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:77
~RegisterIt()
Destructor should remove it from the registry.
Definition: RegisteredParsingObject.h:119
RegisterIt()
Default constructor adds the type to the registry.
Definition: RegisteredParsingObject.h:107
A helper class to allow automatic registration.
Definition: RegisteredParsingObject.h:104