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