GammaLib  2.1.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GCTAModelRadialRegistry.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GCTAModelRadialRegistry.hpp - CTA Radial model registry class *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2011-2014 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 GCTAModelRadialRegistry.hpp
23  * @brief CTA radial model registry class definition
24  * @author Juergen Knoedlseder
25  */
26 
27 #ifndef GCTAMODELRADIALREGISTRY_HPP
28 #define GCTAMODELRADIALREGISTRY_HPP
29 
30 /* __ Includes ___________________________________________________________ */
31 #include <string>
32 #include "GRegistry.hpp"
33 #include "GCTAModelRadial.hpp"
34 
35 
36 /***********************************************************************//**
37  * @class GCTAModelRadialRegistry
38  *
39  * @brief Interface definition for the CTA radial model registry class
40  *
41  * The registry class allows the registration of radial models for CTA that
42  * are not necessarily compiled into the GammaLib. It uses the static members
43  * m_number, m_names, and m_models which are allocated globally to keep track
44  * of radial models that are available throughout all linked libraries. To
45  * register a radial model it is sufficient to add
46  *
47  * const GCTAModelRadialXXX g_cta_radial_XXX_seed;
48  * const GCTAModelRadialRegistry g_cta_radial_XXX_registry(&g_cta_radial_XXX_seed);
49  *
50  * at the top of the .cpp file of the radial model. Here, XXX is a unique
51  * name that describes the model.
52  ***************************************************************************/
54 
55 public:
56  // Constructors and destructors
60  virtual ~GCTAModelRadialRegistry(void);
61 
62  // Operators
64 
65  // Methods
66  std::string classname(void) const;
67  int size(void) const;
68  GCTAModelRadial* alloc(const std::string& name) const;
69  std::string name(const int& index) const;
70  std::string print(const GChatter& chatter = NORMAL) const;
71 
72 protected:
73  // Protected methods
74  void init_members(void);
75  void copy_members(const GCTAModelRadialRegistry& registry);
76  void free_members(void);
77 
78 private:
79  // Private members (the private members have been implement as static
80  // methods to avoid the static initialization order fiasco of static
81  // members; using static methods we follow the "construct on first use
82  // idiom")
83  // Number of models in registry
84  static int& number() {
85  static int m_number = 0;
86  return m_number;
87  }
88  // Model names
90  static GRegistryPointer<std::string> m_names;
91  return m_names;
92  }
93  // Pointer to seed models
96  return m_models;
97  }
98 };
99 
100 
101 /***********************************************************************//**
102  * @brief Return class name
103  *
104  * @return String containing the class name ("GCTAModelRadialRegistry").
105  ***************************************************************************/
106 inline
107 std::string GCTAModelRadialRegistry::classname(void) const
108 {
109  return ("GCTAModelRadialRegistry");
110 }
111 
112 
113 /***********************************************************************//**
114  * @brief Return number of registered models
115  *
116  * @return Number of registered models.
117  *
118  * Returns the number of registered model.
119  ***************************************************************************/
120 inline
122 {
123  return number();
124 }
125 
126 #endif /* GCTAMODELRADIALREGISTRY_HPP */
static GRegistryPointer< const GCTAModelRadial * > & models()
Interface class for registries.
Definition: GRegistry.hpp:101
virtual ~GCTAModelRadialRegistry(void)
Destructor.
void init_members(void)
Initialise class members.
Smart pointer for registry classes.
Definition: GRegistry.hpp:43
GCTAModelRadialRegistry(void)
Void constructor.
std::string name(const int &index) const
Returns model name.
Abstract radial acceptance model class interface definition.
GChatter
Definition: GTypemaps.hpp:33
std::string classname(void) const
Return class name.
int size(void) const
Return number of registered models.
GCTAModelRadial * alloc(const std::string &name) const
Allocate radial model of given name.
GCTAModelRadialRegistry & operator=(const GCTAModelRadialRegistry &registry)
Assignment operator.
Interface definition for the CTA radial model registry class.
Abstract radial acceptance model class.
void free_members(void)
Delete class members.
Interface class definition for registries.
std::string print(const GChatter &chatter=NORMAL) const
Print registry information.
void copy_members(const GCTAModelRadialRegistry &registry)
Copy class members.
static GRegistryPointer< std::string > & names()