STIR 6.4.0
RegisteredObject.inl
Go to the documentation of this file.
1//
2//
13/*
14 Copyright (C) 2000-2009, Hammersmith Imanet Ltd
15 This file is part of STIR.
16
17 SPDX-License-Identifier: Apache-2.0
18
19 See STIR/LICENSE.txt for details
20*/
21
22#include "stir/utilities.h"
23#include <iostream>
24
25START_NAMESPACE_STIR
26
27template <class Root>
28RegisteredObject<Root>::RegisteredObject()
29{}
30
31template <class Root>
32typename RegisteredObject<Root>::RegistryType&
34{
35 static RegistryType the_registry("None", 0);
36 return the_registry;
37}
38
39template <class Root>
40Root*
41RegisteredObject<Root>::read_registered_object(std::istream* in, const std::string& registered_name)
42{
43 RootFactory factory = registry().find_factory(registered_name);
44 return factory == 0 ? 0 : (*factory)(in);
45}
46
47template <class Root>
48Root*
50{
51 std::cout << "Which type do you want? Possible values are:\n";
52 list_registered_names(std::cout);
53 const std::string registered_name = ask_string("Enter type", "None");
54 return read_registered_object(0, registered_name);
55}
56
57template <class Root>
58void
60{
61 registry().list_keys(stream);
62}
63
64END_NAMESPACE_STIR
static Root * ask_type_and_parameters()
ask the user for the type, and then calls read_registered_object(0, type)
Definition RegisteredObject.inl:49
static RegistryType & registry()
Static function returning the registry.
Definition RegisteredObject.inl:33
static void list_registered_names(std::ostream &stream)
List all possible registered names to the stream.
Definition RegisteredObject.inl:59
Root *(* RootFactory)(std::istream *)
The type of a root factory is a function, taking an istream* as argument, and returning a Root*.
Definition RegisteredObject.h:124
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_nam...
Definition RegisteredObject.inl:41
FactoryRegistry< std::string, RootFactory, interfile_less > RegistryType
The type of the registry.
Definition RegisteredObject.h:126
string ask_string(const string &str, const string &default_value)
A function to ask a string from the user.
Definition utilities.cxx:67
This file declares various utility functions.