GammaLib  2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GRegistry.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GRegistry.cpp - Interface class for registries *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2012-2021 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 GRegistry.cpp
23  * @brief Interface class implementation for registries
24  * @author Juergen Knoedlseder
25  */
26 
27 /* __ Includes ___________________________________________________________ */
28 #ifdef HAVE_CONFIG_H
29 #include <config.h>
30 #endif
31 #include "GRegistry.hpp"
32 #include "GLog.hpp"
33 
34 /* __ Method name definitions ____________________________________________ */
35 
36 /* __ Macros _____________________________________________________________ */
37 
38 /* __ Coding definitions _________________________________________________ */
39 
40 /* __ Debug definitions __________________________________________________ */
41 
42 
43 /*==========================================================================
44 = =
45 = Public methods =
46 = =
47 ==========================================================================*/
48 
49 /***********************************************************************//**
50  * @brief Return list of names in registry
51  *
52  * @return String containing list of names in registry
53  ***************************************************************************/
54 std::string GRegistry::content(void) const
55 {
56  // Initialise names
57  std::string names;
58 
59  // Loop over all entries and append names
60  for (int i = 0; i < size(); ++i) {
61  if (i != 0) {
62  names += ", ";
63  }
64  names += "\""+name(i)+"\"";
65  }
66 
67  // Return names
68  return names;
69 }
70 
71 
72 /*==========================================================================
73  = =
74  = Friends =
75  = =
76  ==========================================================================*/
77 
78 /***********************************************************************//**
79  * @brief Output operator
80  *
81  * @param[in] os Output stream.
82  * @param[in] registry Registry.
83  ***************************************************************************/
84 std::ostream& operator<<(std::ostream& os, const GRegistry& registry)
85 {
86  // Write registry content in output stream
87  os << registry.print();
88 
89  // Return output stream
90  return os;
91 }
92 
93 
94 /***********************************************************************//**
95  * @brief Log operator
96  *
97  * @param[in] log Logger.
98  * @param[in] registry Registry.
99  ***************************************************************************/
100 GLog& operator<<(GLog& log, const GRegistry& registry)
101 {
102  // Write registry content into logger
103  log << registry.print();
104 
105  // Return logger
106  return log;
107 }
Interface class for registries.
Definition: GRegistry.hpp:101
std::string content(void) const
Return list of names in registry.
Definition: GRegistry.cpp:54
Information logger interface definition.
Definition: GLog.hpp:62
GVector log(const GVector &vector)
Computes natural logarithm of vector elements.
Definition: GVector.cpp:1274
std::ostream & operator<<(std::ostream &os, const GBase &base)
Output operator.
Definition: GBase.cpp:57
Information logger class definition.
virtual std::string print(const GChatter &chatter=NORMAL) const =0
Print content of object.
Interface class definition for registries.
virtual int size(void) const =0
Return number of classes in registry.
virtual std::string name(const int &index) const =0
Return name of registered class by index.