Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
SingletonRegistry.h
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
2 // OpenMS -- Open-Source Mass Spectrometry
3 // --------------------------------------------------------------------------
4 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
5 // ETH Zurich, and Freie Universitaet Berlin 2002-2017.
6 //
7 // This software is released under a three-clause BSD license:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of any author or any participating institution
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
16 // For a full list of authors, refer to the file AUTHORS.
17 // --------------------------------------------------------------------------
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
22 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // --------------------------------------------------------------------------
31 // $Maintainer: Chris Bielow $
32 // $Authors: $
33 // --------------------------------------------------------------------------
34 
35 #ifndef OPENMS_CONCEPT_SINGLETONREGISTRY_H
36 #define OPENMS_CONCEPT_SINGLETONREGISTRY_H
37 
40 
41 #include <map>
42 
43 namespace OpenMS
44 {
45  class String;
46  class FactoryBase;
47 
55  class OPENMS_DLLAPI SingletonRegistry
56  {
57  friend class singletonsNeedNoFriends; //some versions of gcc would warn otherwise
58 
59 private:
61  typedef std::map<String, FactoryBase *> Map;
62  typedef Map::const_iterator MapIterator;
63 
65  virtual ~SingletonRegistry(){}
66 
69 
72  {
73  if (!singletonRegistryInstance_)
74  {
75  singletonRegistryInstance_ = new SingletonRegistry();
76  }
77  return singletonRegistryInstance_;
78  }
79 
80 public:
81 
83  static FactoryBase * getFactory(const String & name)
84  {
85  MapIterator it = instance_()->inventory_.find(name);
86  if (it != instance_()->inventory_.end())
87  {
88  return it->second;
89  }
90  else
91  {
92  throw Exception::InvalidValue(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, "This Factory is not registered with SingletonRegistry!", name.c_str());
93  }
94  }
95 
102  static void registerFactory(const String & name, FactoryBase * instance)
103  {
104  instance_()->inventory_[name] = instance;
105  }
106 
108  static bool isRegistered(String name)
109  {
110  if (instance_()->inventory_.find(name) != instance_()->inventory_.end())
111  {
112  return true;
113  }
114  return false;
115  }
116 
117 private:
118 
121  };
122 
123 
124 }
125 #endif //OPENMS_CONCEPT_SINGLETONREGISTRY_H
static bool isRegistered(String name)
Returns if a factory is registered.
Definition: SingletonRegistry.h:108
static SingletonRegistry * instance_()
singleton access to SingletonRegistry
Definition: SingletonRegistry.h:71
Map inventory_
Definition: SingletonRegistry.h:119
A more convenient string class.
Definition: String.h:57
std::map< String, FactoryBase * > Map
Function signature of creator function.
Definition: SingletonRegistry.h:61
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
SingletonRegistry()
C&#39;Tor.
Definition: SingletonRegistry.h:68
Base class for Factory<T>
Definition: FactoryBase.h:49
static FactoryBase * getFactory(const String &name)
return DefaultParamHandler according to unique identifier name
Definition: SingletonRegistry.h:83
Invalid value exception.
Definition: Exception.h:336
virtual ~SingletonRegistry()
destructor
Definition: SingletonRegistry.h:65
static SingletonRegistry * singletonRegistryInstance_
Definition: SingletonRegistry.h:120
Holds pointers to unique instance of a singleton factory.
Definition: SingletonRegistry.h:55
Map::const_iterator MapIterator
Definition: SingletonRegistry.h:62
static void registerFactory(const String &name, FactoryBase *instance)
register new concrete Factory
Definition: SingletonRegistry.h:102

OpenMS / TOPP release 2.3.0 Documentation generated on Tue Jan 9 2018 18:22:03 using doxygen 1.8.13