include/GModelSpectralRegistry.hpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *       GModelSpectralRegistry.hpp - Spectral model registry class        *
00003  * ----------------------------------------------------------------------- *
00004  *  copyright (C) 2011-2016 by Juergen Knoedlseder                         *
00005  * ----------------------------------------------------------------------- *
00006  *                                                                         *
00007  *  This program is free software: you can redistribute it and/or modify   *
00008  *  it under the terms of the GNU General Public License as published by   *
00009  *  the Free Software Foundation, either version 3 of the License, or      *
00010  *  (at your option) any later version.                                    *
00011  *                                                                         *
00012  *  This program is distributed in the hope that it will be useful,        *
00013  *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
00014  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
00015  *  GNU General Public License for more details.                           *
00016  *                                                                         *
00017  *  You should have received a copy of the GNU General Public License      *
00018  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.  *
00019  *                                                                         *
00020  ***************************************************************************/
00021 /**
00022  * @file GModelSpectralRegistry.hpp
00023  * @brief Spectral model registry class definition
00024  * @author Juergen Knoedlseder
00025  */
00026 
00027 #ifndef GMODELSPECTRALREGISTRY_HPP
00028 #define GMODELSPECTRALREGISTRY_HPP
00029 
00030 /* __ Includes ___________________________________________________________ */
00031 #include <string>
00032 #include "GRegistry.hpp"
00033 
00034 /* __ Forward declarations _______________________________________________ */
00035 class GXmlElement;
00036 class GModelSpectral;
00037 
00038 
00039 /***********************************************************************//**
00040  * @class GModelSpectralRegistry
00041  *
00042  * @brief Interface definition for the spectral model registry class
00043  *
00044  * The registry class allows the registration of spectral models that are not
00045  * necessarily compiled into the GammaLib. It uses the static members
00046  * m_number and m_models which are allocated globally to keep track of
00047  * spectral models that are available throughout all linked libraries. To
00048  * register a spectral model it is sufficient to add
00049  *
00050  *     const GModelSpectralXXX      g_spectral_XXX_seed;
00051  *     const GModelSpectralRegistry g_spectral_XXX_registry(&g_spectral_XXX_seed);
00052  *
00053  * at the top of the .cpp file of the spectral model. Here, XXX is a unique
00054  * name that describes the model.
00055  ***************************************************************************/
00056 class GModelSpectralRegistry : public GRegistry {
00057 
00058 public:
00059     // Constructors and destructors
00060     GModelSpectralRegistry(void);
00061     GModelSpectralRegistry(const GModelSpectral* model);
00062     GModelSpectralRegistry(const GModelSpectralRegistry& registry);
00063     virtual ~GModelSpectralRegistry(void);
00064 
00065     // Operators
00066     GModelSpectralRegistry& operator=(const GModelSpectralRegistry& registry);
00067 
00068     // Methods
00069     std::string     classname(void) const;
00070     int             size(void) const;
00071     GModelSpectral* alloc(const GXmlElement& xml) const;
00072     std::string     name(const int& index) const;
00073     std::string     print(const GChatter& chatter = NORMAL) const;
00074 
00075 protected:
00076     // Protected methods
00077     void init_members(void);
00078     void copy_members(const GModelSpectralRegistry& registry);
00079     void free_members(void);
00080 
00081 private:
00082     // Private members (the private members have been implement as static
00083     // methods to avoid the static initialization order fiasco of static
00084     // members; using static methods we follow the "construct on first use
00085     // idiom")
00086     // Number of models in registry
00087     static int& number() {
00088         static int m_number = 0;
00089         return m_number;
00090     };
00091     // Pointer to seed models
00092     static GRegistryPointer<const GModelSpectral*>& models() {
00093         static GRegistryPointer<const GModelSpectral*> m_models;
00094         return m_models;
00095     };
00096 };
00097 
00098 
00099 /***********************************************************************//**
00100  * @brief Return class name
00101  *
00102  * @return String containing the class name ("GModelSpectralRegistry").
00103  ***************************************************************************/
00104 inline
00105 std::string GModelSpectralRegistry::classname(void) const
00106 {
00107     return ("GModelSpectralRegistry");
00108 }
00109 
00110 
00111 /***********************************************************************//**
00112  * @brief Return number of registered models
00113  *
00114  * @return Number of registered models.
00115  *
00116  * Returns the number of registered model.
00117  ***************************************************************************/
00118 inline
00119 int GModelSpectralRegistry::size(void) const
00120 {
00121     return number();
00122 }
00123 
00124 #endif /* GMODELSPECTRALREGISTRY_HPP */

Generated on Tue Jan 24 12:37:18 2017 for GammaLib by  doxygen 1.4.7