GammaLib  1.7.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GModelSpectralRegistry.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GModelSpectralRegistry.hpp - Spectral model registry class *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2011-2016 by Juergen Knoedlseder *
5  * ----------------------------------------------------------------------- *
6  * *
7  * This program is free software: you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation, either version 3 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * This program is distributed in the hope that it will be useful, *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15  * GNU General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU General Public License *
18  * along with this program. If not, see <http://www.gnu.org/licenses/>. *
19  * *
20  ***************************************************************************/
21 /**
22  * @file GModelSpectralRegistry.hpp
23  * @brief Spectral model registry class definition
24  * @author Juergen Knoedlseder
25  */
26 
27 #ifndef GMODELSPECTRALREGISTRY_HPP
28 #define GMODELSPECTRALREGISTRY_HPP
29 
30 /* __ Includes ___________________________________________________________ */
31 #include <string>
32 #include "GRegistry.hpp"
33 
34 /* __ Forward declarations _______________________________________________ */
35 class GXmlElement;
36 class GModelSpectral;
37 
38 
39 /***********************************************************************//**
40  * @class GModelSpectralRegistry
41  *
42  * @brief Interface definition for the spectral model registry class
43  *
44  * The registry class allows the registration of spectral models that are not
45  * necessarily compiled into the GammaLib. It uses the static members
46  * m_number and m_models which are allocated globally to keep track of
47  * spectral models that are available throughout all linked libraries. To
48  * register a spectral model it is sufficient to add
49  *
50  * const GModelSpectralXXX g_spectral_XXX_seed;
51  * const GModelSpectralRegistry g_spectral_XXX_registry(&g_spectral_XXX_seed);
52  *
53  * at the top of the .cpp file of the spectral model. Here, XXX is a unique
54  * name that describes the model.
55  ***************************************************************************/
57 
58 public:
59  // Constructors and destructors
63  virtual ~GModelSpectralRegistry(void);
64 
65  // Operators
67 
68  // Methods
69  std::string classname(void) const;
70  int size(void) const;
71  GModelSpectral* alloc(const GXmlElement& xml) const;
72  std::string name(const int& index) const;
73  std::string print(const GChatter& chatter = NORMAL) const;
74 
75 protected:
76  // Protected methods
77  void init_members(void);
78  void copy_members(const GModelSpectralRegistry& registry);
79  void free_members(void);
80 
81 private:
82  // Private members (the private members have been implement as static
83  // methods to avoid the static initialization order fiasco of static
84  // members; using static methods we follow the "construct on first use
85  // idiom")
86  // Number of models in registry
87  static int& number() {
88  static int m_number = 0;
89  return m_number;
90  };
91  // Pointer to seed models
94  return m_models;
95  };
96 };
97 
98 
99 /***********************************************************************//**
100  * @brief Return class name
101  *
102  * @return String containing the class name ("GModelSpectralRegistry").
103  ***************************************************************************/
104 inline
105 std::string GModelSpectralRegistry::classname(void) const
106 {
107  return ("GModelSpectralRegistry");
108 }
109 
110 
111 /***********************************************************************//**
112  * @brief Return number of registered models
113  *
114  * @return Number of registered models.
115  *
116  * Returns the number of registered model.
117  ***************************************************************************/
118 inline
120 {
121  return number();
122 }
123 
124 #endif /* GMODELSPECTRALREGISTRY_HPP */
void free_members(void)
Delete class members.
Abstract spectral model base class.
void init_members(void)
Initialise class members.
XML element node class.
Definition: GXmlElement.hpp:47
Interface class for registries.
Definition: GRegistry.hpp:101
Smart pointer for registry classes.
Definition: GRegistry.hpp:43
static GRegistryPointer< const GModelSpectral * > & models()
GModelSpectralRegistry(void)
Void constructor.
std::string name(const int &index) const
Returns model name.
std::string print(const GChatter &chatter=NORMAL) const
Print registry information.
GModelSpectral * alloc(const GXmlElement &xml) const
Allocate spectral model that is found in XML element.
GChatter
Definition: GTypemaps.hpp:33
Interface definition for the spectral model registry class.
virtual ~GModelSpectralRegistry(void)
Destructor.
GModelSpectralRegistry & operator=(const GModelSpectralRegistry &registry)
Assignment operator.
int size(void) const
Return number of registered models.
Interface class definition for registries.
void copy_members(const GModelSpectralRegistry &registry)
Copy class members.
std::string classname(void) const
Return class name.