gambit is hosted by Hepforge, IPPP Durham
GAMBIT  v1.5.0-252-gf9a3f78
a Global And Modular Bsm Inference Tool
Gambit::ASCIIdictReader Class Reference

#include <ascii_dict_reader.hpp>

Collaboration diagram for Gambit::ASCIIdictReader:

Public Member Functions

 ASCIIdictReader (std::string filename)
 
 ASCIIdictReader ()
 
 ~ASCIIdictReader ()
 
int read (std::string filename)
 
const std::vector< std::string > & get_keys () const
 
const std::map< std::string, std::vector< double > > & get_dict () const
 
bool duplicated_keys () const
 
int nrow () const
 

Private Attributes

std::map< std::string, std::vector< double > > dict
 
std::vector< std::string > keys
 
bool duplicate
 

Detailed Description

Definition at line 40 of file ascii_dict_reader.hpp.

Constructor & Destructor Documentation

◆ ASCIIdictReader() [1/2]

Gambit::ASCIIdictReader::ASCIIdictReader ( std::string  filename)
inline

Definition at line 43 of file ascii_dict_reader.hpp.

References duplicate, and read().

44  {
45  duplicate = false;
46  read(filename);
47  };
int read(std::string filename)
Here is the call graph for this function:

◆ ASCIIdictReader() [2/2]

Gambit::ASCIIdictReader::ASCIIdictReader ( )
inline

Definition at line 48 of file ascii_dict_reader.hpp.

48 {}; // Dummy initializer

◆ ~ASCIIdictReader()

Gambit::ASCIIdictReader::~ASCIIdictReader ( )
inline

Definition at line 49 of file ascii_dict_reader.hpp.

References read().

49 {}
Here is the call graph for this function:

Member Function Documentation

◆ duplicated_keys()

bool Gambit::ASCIIdictReader::duplicated_keys ( ) const
inline

Definition at line 54 of file ascii_dict_reader.hpp.

References duplicate.

◆ get_dict()

const std::map<std::string,std::vector<double> >& Gambit::ASCIIdictReader::get_dict ( ) const
inline

Definition at line 53 of file ascii_dict_reader.hpp.

References dict.

53 {return dict;}
std::map< std::string, std::vector< double > > dict

◆ get_keys()

const std::vector<std::string>& Gambit::ASCIIdictReader::get_keys ( ) const
inline

Definition at line 52 of file ascii_dict_reader.hpp.

References keys.

52 {return keys;}
std::vector< std::string > keys

◆ nrow()

int Gambit::ASCIIdictReader::nrow ( ) const
inline

Definition at line 55 of file ascii_dict_reader.hpp.

References keys.

55 {return keys.size();}
std::vector< std::string > keys

◆ read()

int Gambit::ASCIIdictReader::read ( std::string  filename)

Definition at line 23 of file ascii_dict_reader.cpp.

References dict, duplicate, keys, LOCAL_INFO, and Gambit::utils_error().

Referenced by ASCIIdictReader(), and ~ASCIIdictReader().

24  {
25  std::ifstream in(filename.c_str(), std::ios::binary);
26  if (in.fail())
27  {
28  std::ostringstream errmsg;
29  errmsg << "Failed to read file '"<< filename <<"'. Check if file exists.";
30  utils_error().raise(LOCAL_INFO, errmsg.str());
31  }
32 
33  std::string line;
34  while(std::getline(in, line))
35  {
36  if (line[0] == '#' || line.empty() ) continue; // Ignore comments lines, starting with "#" and empty lines
37  std::stringstream ss(line);
38 
39  double tmp;
40  std::string key;
41  std::vector<double> data_tmp;
42 
43  ss >> key;
44  while(ss >> tmp)
45  {
46  data_tmp.push_back(tmp);
47  }
48 
49 
50  if (std::find(keys.begin(), keys.end(), key) != keys.end())
51  {
52  duplicate = true;
53  }
54 
55  dict[key] = data_tmp;
56  keys.push_back(key);
57 
58  }
59  in.close();
60  return 0;
61  }
EXPORT_SYMBOLS error & utils_error()
Utility errors.
#define LOCAL_INFO
Definition: local_info.hpp:34
std::vector< std::string > keys
std::map< std::string, std::vector< double > > dict
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ dict

std::map<std::string,std::vector<double> > Gambit::ASCIIdictReader::dict
private

Definition at line 58 of file ascii_dict_reader.hpp.

Referenced by get_dict(), and read().

◆ duplicate

bool Gambit::ASCIIdictReader::duplicate
private

Definition at line 60 of file ascii_dict_reader.hpp.

Referenced by ASCIIdictReader(), duplicated_keys(), and read().

◆ keys

std::vector<std::string> Gambit::ASCIIdictReader::keys
private

Definition at line 59 of file ascii_dict_reader.hpp.

Referenced by get_keys(), nrow(), and read().


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