CosmoBolognaLib
Free Software C++/Python libraries for cosmological calculations
ParameterFile.h
Go to the documentation of this file.
1 /********************************************************************
2  * Copyright (C) 2010 by Federico Marulli and Alfonso Veropalumbo *
3  * federico.marulli3@unibo.it, alfonso.veropalumbo@uniroma3.it *
4  * *
5  * This program is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU General Public License as *
7  * published by the Free Software Foundation; either version 2 of *
8  * the License, or (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public *
16  * License along with this program; if not, write to the Free *
17  * Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ********************************************************************/
20 
34 #ifndef __PARAM__
35 #define __PARAM__
36 
37 #include "Kernel.h"
38 
39 
40 // ============================================================================
41 
42 
43 namespace cbl {
44 
45  namespace glob {
46 
48  typedef std::unordered_map<std::string, std::vector<std::string>> parameter_map;
49 
58  {
59 
60  private:
61 
64 
66  std::vector<std::string> m_keys;
67 
76  std::string m_trim (const std::string inStr);
77 
87  std::vector<std::string> m_trim_vect (const std::string inStr);
88 
89  public:
90 
95 
100  ParameterFile () = default;
101 
108  ParameterFile (const std::string parameter_file);
109 
114  ~ParameterFile () = default;
115 
117 
122 
131  void read(const std::string parameter_file);
132 
141  void write(const std::string parameter_file);
142 
144 
149 
162  std::vector<std::string> & operator[] (const std::string key);
163 
179  void set_key (const std::string key, std::string value, const size_t pos=0);
180 
193  void set_key (const std::string key, const std::vector<std::string> values);
194 
208  std::string get_key (const std::string key, const std::string default_value, const size_t pos=0) const;
209 
221  std::vector<std::string> get_key (const std::string key, const std::vector<std::string> default_values) const;
222 
224 
225  }; // class ParameterFile
226 
227  } // namespace glob
228 } // namespace cbl
229 
230 
231 #endif //__PARAM__
Useful generic functions.
The class ParameterFile.
Definition: ParameterFile.h:58
std::string m_trim(const std::string inStr)
Remove white spaces treading and leading each std::string (private function)
void write(const std::string parameter_file)
member to write a parameter file
std::vector< std::string > & operator[](const std::string key)
Method to set/get entries of the parameter file.
parameter_map m_parameters
map with all the vector type parameter name/value couples
Definition: ParameterFile.h:63
~ParameterFile()=default
Default destructor.
void read(const std::string parameter_file)
member to read a parameter file
ParameterFile()=default
Default empty constructor.
void set_key(const std::string key, std::string value, const size_t pos=0)
Method to set entries of the parameter file.
std::vector< std::string > m_trim_vect(const std::string inStr)
Stores values contained in between curly brackets in a vector of std::string (private function)
std::string get_key(const std::string key, const std::string default_value, const size_t pos=0) const
Method to get one value for a specific parameter.
std::vector< std::string > m_keys
list of keys in order of insertion
Definition: ParameterFile.h:66
std::unordered_map< std::string, std::vector< std::string > > parameter_map
Map type used in ParameterFile class.
Definition: ParameterFile.h:48
The global namespace of the CosmoBolognaLib
Definition: CAMB.h:38