STIR 6.4.0
FactoryRegistry.h
Go to the documentation of this file.
1//
2//
12/*
13 Copyright (C) 2001- 2009, Hammersmith Imanet Ltd
14 This file is part of STIR.
15
16 SPDX-License-Identifier: Apache-2.0
17
18 See STIR/LICENSE.txt for details
19*/
20
21#ifndef __stir_FactoryRegistry_H__
22#define __stir_FactoryRegistry_H__
23
24#include "stir/common.h"
25#include <iostream>
26#include <map>
27#include <functional>
28
29START_NAMESPACE_STIR
30
51template <typename Key, typename Factory, typename Compare = std::less<Key>>
53{
54
55public:
56 // sadly, all of these have to be inline to prevent problems
57 // with instantiation
58
65 inline FactoryRegistry(const Key& default_key, const Factory& default_factory);
66
67 inline ~FactoryRegistry();
68
74 inline void add_to_registry(const Key& key, Factory const& factory);
75
77 inline void remove_from_registry(const Key& key);
78
80 inline void list_keys(std::ostream& s) const;
81
83
89 inline Factory const& find_factory(const Key& key) const;
90
91private:
92 typedef std::map<Key, Factory, Compare> FactoryMap;
93 FactoryMap m;
94 const bool has_defaults;
95 const Key default_key;
96 const Factory default_factory;
97};
98
99END_NAMESPACE_STIR
100
102
103#endif
Inline implementations for stir::FactoryRegistry.
FactoryRegistry()
Default constructor without defaults (see find_factory())
Definition FactoryRegistry.inl:29
FactoryRegistry(const Key &default_key, const Factory &default_factory)
constructor with default values which will be returned when no match is found (see find_factory())
Definition FactoryRegistry.inl:34
Factory const & find_factory(const Key &key) const
Find a factory corresponding to a key.
Definition FactoryRegistry.inl:99
void remove_from_registry(const Key &key)
Remove a pair from the registry.
Definition FactoryRegistry.inl:72
void list_keys(std::ostream &s) const
List all keys to an ostream, separated by newlines.
Definition FactoryRegistry.inl:91
void add_to_registry(const Key &key, Factory const &factory)
Add a pair to the registry.
Definition FactoryRegistry.inl:54
basic configuration include file