GammaLib  2.1.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GModelTemporalRegistry.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GModelTemporalRegistry.hpp - Temporal 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 GModelTemporalRegistry.hpp
23  * @brief Temporal model registry class definition
24  * @author Juergen Knoedlseder
25  */
26 
27 #ifndef GMODELTEMPORALREGISTRY_HPP
28 #define GMODELTEMPORALREGISTRY_HPP
29 
30 /* __ Includes ___________________________________________________________ */
31 #include <string>
32 #include "GRegistry.hpp"
33 
34 /* __ Forward declarations _______________________________________________ */
35 class GXmlElement;
36 class GModelTemporal;
37 
38 
39 /***********************************************************************//**
40  * @class GModelTemporalRegistry
41  *
42  * @brief Interface definition for the temporal model registry class.
43  *
44  * The registry class allows the registration of temporal 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  * temporal models that are available throughout all linked libraries. To
48  * register a temporal model it is sufficient to add
49  *
50  * const GModelTemporalXXX g_temporal_XXX_seed;
51  * const GModelTemporalRegistry g_temporal_XXX_registry(&g_spectral_XXX_seed);
52  *
53  * at the top of the .cpp file of the temporal model. Here, XXX is a unique
54  * name that describes the model.
55  ***************************************************************************/
57 
58 public:
59  // Constructors and destructors
63  virtual ~GModelTemporalRegistry(void);
64 
65  // Operators
67 
68  // Methods
69  std::string classname(void) const;
70  int size(void) const;
71  GModelTemporal* 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 GModelTemporalRegistry& 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 ("GModelTemporalRegistry").
103  ***************************************************************************/
104 inline
105 std::string GModelTemporalRegistry::classname(void) const
106 {
107  return ("GModelTemporalRegistry");
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 /* GMODELTEMPORALREGISTRY_HPP */
GModelTemporalRegistry(void)
Void constructor.
Abstract temporal model base class.
XML element node class.
Definition: GXmlElement.hpp:48
Interface class for registries.
Definition: GRegistry.hpp:101
std::string name(const int &index) const
Returns model name.
std::string print(const GChatter &chatter=NORMAL) const
Print registry information.
Smart pointer for registry classes.
Definition: GRegistry.hpp:43
void init_members(void)
Initialise class members.
std::string classname(void) const
Return class name.
void free_members(void)
Delete class members.
GModelTemporalRegistry & operator=(const GModelTemporalRegistry &registry)
Assignment operator.
GModelTemporal * alloc(const GXmlElement &xml) const
Allocate temporal model that is found in XML element.
int size(void) const
Return number of registered models.
GChatter
Definition: GTypemaps.hpp:33
void copy_members(const GModelTemporalRegistry &registry)
Copy class members.
Interface definition for the temporal model registry class.
virtual ~GModelTemporalRegistry(void)
Destructor.
Interface class definition for registries.
static GRegistryPointer< const GModelTemporal * > & models()