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