CosmoBolognaLib
Free Software C++/Python libraries for cosmological calculations
Table.h
Go to the documentation of this file.
1 /********************************************************************
2  * Copyright (C) 2014 by Federico Marulli and Alfonso Veropalumbo *
3  * federico.marulli3@unibo.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 
33 #ifndef __TABLE__
34 #define __TABLE__
35 
36 #include "Func.h"
37 
38 namespace cbl {
39 
47  namespace data {
48 
50  typedef std::map<std::string, std::vector<double>> table_map;
51 
60  class Table
61  {
62  protected:
63 
66 
76  void m_set (const std::vector<std::string> names, const size_t nrows);
77 
87  void m_set (const std::vector<std::string> names, const std::vector<std::vector<double>> values);
88 
94  std::vector<std::string> m_keys ();
95 
96  public:
97 
103  Table () = default;
104 
118  Table (const std::vector<std::string> names, const std::vector<std::vector<double>> values);
119 
132  Table (const std::vector<std::string> names, const size_t nrows);
133 
151  Table (const std::string input_dir, const std::string input_file, const std::vector<std::string> names, const std::vector<size_t> use_cols={}, const size_t header_lines_to_skip=1);
152 
158  virtual ~Table() = default;
159 
167  std::vector<double> & operator[] (const std::string name);
168 
176  std::vector<std::vector<double>> operator[] (const std::vector<std::string> names);
177 
189  void insert (const std::string name, const std::vector<double> values, const bool replace=false);
190 
202  void insert (const std::vector<std::string> names, const std::vector<std::vector<double>> values, const bool replace=false);
203 
219  void read (const std::string input_dir, const std::string input_file, const std::vector<std::string> names, const std::vector<size_t> use_cols = {}, const size_t header_lines_to_skip=1);
220 
232  void write (const std::string output_dir, const std::string output_file, const std::vector<std::string> names={});
233  };
234  }
235 }
236 
237 #endif
Useful generic functions.
The class Table.
Definition: Table.h:61
table_map m_table
the table in form of std::map
Definition: Table.h:65
std::vector< std::string > m_keys()
get the map keys
Definition: Table.cpp:64
void m_set(const std::vector< std::string > names, const size_t nrows)
function to set internal members
Definition: Table.cpp:45
std::vector< double > & operator[](const std::string name)
function to get a column
Definition: Table.cpp:105
void write(const std::string output_dir, const std::string output_file, const std::vector< std::string > names={})
function to write columns
Definition: Table.cpp:219
void insert(const std::string name, const std::vector< double > values, const bool replace=false)
function to insert a column
Definition: Table.cpp:133
Table()=default
default constructor
virtual ~Table()=default
default destructor
void read(const std::string input_dir, const std::string input_file, const std::vector< std::string > names, const std::vector< size_t > use_cols={}, const size_t header_lines_to_skip=1)
function to read from an ascii file
Definition: Table.cpp:163
std::map< std::string, std::vector< double > > table_map
Map type used in Table class.
Definition: Table.h:50
The global namespace of the CosmoBolognaLib
Definition: CAMB.h:38