CosmoBolognaLib
Free Software C++/Python libraries for cosmological calculations
cbl::data::Table Class Reference

The class Table. More...

#include <Table.h>

Public Member Functions

 Table ()=default
 default constructor
 
 Table (const std::vector< std::string > names, const std::vector< std::vector< double >> values)
 Constructor of object Table. More...
 
 Table (const std::vector< std::string > names, const size_t nrows)
 Constructor of object Table. More...
 
 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)
 Constructor of object Table. More...
 
virtual ~Table ()=default
 default destructor
 
std::vector< double > & operator[] (const std::string name)
 function to get a column More...
 
std::vector< std::vector< double > > operator[] (const std::vector< std::string > names)
 function to get some columns More...
 
void insert (const std::string name, const std::vector< double > values, const bool replace=false)
 function to insert a column More...
 
void insert (const std::vector< std::string > names, const std::vector< std::vector< double >> values, const bool replace=false)
 function to insert some columns More...
 
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 More...
 
void write (const std::string output_dir, const std::string output_file, const std::vector< std::string > names={})
 function to write columns More...
 

Protected Member Functions

void m_set (const std::vector< std::string > names, const size_t nrows)
 function to set internal members More...
 
void m_set (const std::vector< std::string > names, const std::vector< std::vector< double >> values)
 function to set internal members More...
 
std::vector< std::string > m_keys ()
 get the map keys More...
 

Protected Attributes

table_map m_table
 the table in form of std::map
 

Detailed Description

The class Table.

"Headers/Table.h"

This is the base class used generalize datasets

Definition at line 60 of file Table.h.

Constructor & Destructor Documentation

◆ Table() [1/3]

cbl::data::Table::Table ( const std::vector< std::string >  names,
const std::vector< std::vector< double >>  values 
)

Constructor of object Table.

This constructor initializes the table, taking in input the name of the columns and the values. The size of the two arrays must be tha same.

Parameters
namesthe column names
valuesthe table values

Definition at line 78 of file Table.cpp.

◆ Table() [2/3]

cbl::data::Table::Table ( const std::vector< std::string >  names,
const size_t  nrows 
)

Constructor of object Table.

This constructor initializes the table, creating empty columns of size nrows

Parameters
namesthe column names
nrowsthe columns lenght

Definition at line 87 of file Table.cpp.

◆ Table() [3/3]

cbl::data::Table::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 
)

Constructor of object Table.

This constructor reads the table from an ASCII file

Parameters
input_dirdirectory of input file
input_fileinput file name
namesthe column names
use_colsthe index of the columns to be read
header_lines_to_skipnumber of header lines

Definition at line 96 of file Table.cpp.

Member Function Documentation

◆ insert() [1/2]

void cbl::data::Table::insert ( const std::string  name,
const std::vector< double >  values,
const bool  replace = false 
)

function to insert a column

Parameters
namethe column name
valuesthe column values
replace

Definition at line 133 of file Table.cpp.

◆ insert() [2/2]

void cbl::data::Table::insert ( const std::vector< std::string >  names,
const std::vector< std::vector< double >>  values,
const bool  replace = false 
)

function to insert some columns

Parameters
namesthe column names
valuesthe columns
replace

Definition at line 153 of file Table.cpp.

◆ m_keys()

vector< string > cbl::data::Table::m_keys ( )
protected

get the map keys

Returns
vector of string

Definition at line 64 of file Table.cpp.

◆ m_set() [1/2]

void cbl::data::Table::m_set ( const std::vector< std::string >  names,
const size_t  nrows 
)
protected

function to set internal members

Parameters
namesthe column names
nrowsthe columns lenght

Definition at line 45 of file Table.cpp.

◆ m_set() [2/2]

void cbl::data::Table::m_set ( const std::vector< std::string >  names,
const std::vector< std::vector< double >>  values 
)
protected

function to set internal members

Parameters
namesthe column names
valuesthe table values

Definition at line 55 of file Table.cpp.

◆ operator[]() [1/2]

vector< double > & cbl::data::Table::operator[] ( const std::string  name)

function to get a column

Parameters
namethe column name
Returns
vector containing the column values

Definition at line 105 of file Table.cpp.

◆ operator[]() [2/2]

vector< vector< double > > cbl::data::Table::operator[] ( const std::vector< std::string >  names)

function to get some columns

Parameters
namesthe column names
Returns
vector containing the columns

Definition at line 119 of file Table.cpp.

◆ read()

void cbl::data::Table::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

Parameters
input_dirdirectory of input file
input_fileinput file name
namesthe column names
use_colsthe index of the columns to be read
header_lines_to_skipnumber of header lines

Definition at line 163 of file Table.cpp.

◆ write()

void cbl::data::Table::write ( const std::string  output_dir,
const std::string  output_file,
const std::vector< std::string >  names = {} 
)

function to write columns

Parameters
output_dirdirectory of output file
output_fileoutput file name
namesnames of the colums to be wrote

Definition at line 219 of file Table.cpp.


The documentation for this class was generated from the following files: