GammaLib 2.0.0
Loading...
Searching...
No Matches
GCTAModelSpatialRegistry.hpp
Go to the documentation of this file.
1/***************************************************************************
2 * GCTAModelSpatialRegistry.hpp - Spatial model registry class *
3 * ----------------------------------------------------------------------- *
4 * copyright (C) 2018 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 GCTAModelSpatialRegistry.hpp
23 * @brief Spatial model registry class definition
24 * @author Juergen Knoedlseder
25 */
26
27#ifndef GCTAMODELSPATIALREGISTRY_HPP
28#define GCTAMODELSPATIALREGISTRY_HPP
29
30/* __ Includes ___________________________________________________________ */
31#include <string>
32#include "GRegistry.hpp"
33
34/* __ Forward declarations _______________________________________________ */
35class GXmlElement;
37
38
39/***********************************************************************//**
40 * @class GCTAModelSpatialRegistry
41 *
42 * @brief Interface definition for the spatial model registry class
43 *
44 * The registry class allows the registration of spatial 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 * spatial models that are available throughout all linked libraries. To
48 * register a spatial model it is sufficient to add
49 *
50 * const GCTAModelSpatialXXX g_spatial_XXX_seed;
51 * const GCTAModelSpatialRegistry g_spatial_XXX_registry(&g_spatial_XXX_seed);
52 *
53 * at the top of the .cpp file of the spatial model. Here, XXX is a unique
54 * name that describes the model.
55 ***************************************************************************/
57
58public:
59 // Constructors and destructors
63 virtual ~GCTAModelSpatialRegistry(void);
64
65 // Operators
67
68 // Methods
69 std::string classname(void) const;
70 int size(void) const;
71 GCTAModelSpatial* alloc(const GXmlElement& xml) const;
72 std::string name(const int& index) const;
73 std::string print(const GChatter& chatter = NORMAL) const;
74
75protected:
76 // Protected methods
77 void init_members(void);
78 void copy_members(const GCTAModelSpatialRegistry& registry);
79 void free_members(void);
80
81private:
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 ("GCTAModelSpatialRegistry").
103 ***************************************************************************/
104inline
106{
107 return ("GCTAModelSpatialRegistry");
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 ***************************************************************************/
118inline
120{
121 return number();
122}
123
124#endif /* GCTAMODELSPATIALREGISTRY_HPP */
Interface class definition for registries.
GChatter
Definition GTypemaps.hpp:33
@ NORMAL
Definition GTypemaps.hpp:36
Interface definition for the spatial model registry class.
void copy_members(const GCTAModelSpatialRegistry &registry)
Copy class members.
void init_members(void)
Initialise class members.
std::string name(const int &index) const
Returns model name.
GCTAModelSpatialRegistry(void)
Void constructor.
virtual ~GCTAModelSpatialRegistry(void)
Destructor.
std::string print(const GChatter &chatter=NORMAL) const
Print registry information.
void free_members(void)
Delete class members.
int size(void) const
Return number of registered models.
GCTAModelSpatial * alloc(const GXmlElement &xml) const
Allocate spatial model that is found in XML element.
static GRegistryPointer< const GCTAModelSpatial * > & models()
std::string classname(void) const
Return class name.
GCTAModelSpatialRegistry & operator=(const GCTAModelSpatialRegistry &registry)
Assignment operator.
Abstract spatial model class.
Smart pointer for registry classes.
Definition GRegistry.hpp:43
Interface class for registries.
XML element node class.