MINT2
Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
MINT::ParsedParameterFile Class Reference

#include <ParsedParameterFile.h>

Public Member Functions

 ParsedParameterFile (std::istream &inputStream=std::cin)
 
 ParsedParameterFile (const std::string &fname)
 
 ParsedParameterFile (const ParsedParameterFile &other)
 
unsigned int numLines () const
 
bool OK () const
 
const ParsedParameterLinefind (const std::string &name) const
 
void print (std::ostream &os=std::cout) const
 

Protected Member Functions

void readStream (std::istream &is)
 

Static Protected Member Functions

static bool ignoreThisLine (const std::string &line)
 

Protected Attributes

std::map< std::string, ParsedParameterLine_lines
 
bool _statusOK
 

Static Protected Attributes

static const ParsedParameterLine dummyLine
 
static const char _ignoreLinesStartingWith [] = {'*', '#', '\0'}
 

Detailed Description

Definition at line 15 of file ParsedParameterFile.h.

Constructor & Destructor Documentation

◆ ParsedParameterFile() [1/3]

MINT::ParsedParameterFile::ParsedParameterFile ( std::istream &  inputStream = std::cin)

◆ ParsedParameterFile() [2/3]

ParsedParameterFile::ParsedParameterFile ( const std::string &  fname)

Definition at line 28 of file ParsedParameterFile.cpp.

29  : _statusOK(false)
30 {
31  std::ifstream is(fname.c_str());
32  if(is.bad()){
33  cout << "ERROR in ParsedParameterFile constructor from filename:"
34  << "\n > status of input stream is bad - file might not exist"
35  << "\n > or be otherwise corrupt."
36  << "\n > The file name you passes was: \"" << fname << "\"."
37  << endl;
38  }else{
39  readStream(is);
40  _statusOK=false;
41  }
42  is.close();
43 }
void readStream(std::istream &is)

◆ ParsedParameterFile() [3/3]

ParsedParameterFile::ParsedParameterFile ( const ParsedParameterFile other)

Definition at line 45 of file ParsedParameterFile.cpp.

46  : _lines(other._lines)
47  , _statusOK(other._statusOK)
48 {
49 
50 }
std::map< std::string, ParsedParameterLine > _lines

Member Function Documentation

◆ find()

const ParsedParameterLine & ParsedParameterFile::find ( const std::string &  name) const

Definition at line 81 of file ParsedParameterFile.cpp.

81  {
82  return keyFinder(name, _lines, dummyLine);
83 }
static const ParsedParameterLine dummyLine
const Val & keyFinder(const Key &k, const std::map< Key, Val > &m, const Val &dummy, bool &successFlag)
Definition: Utils.h:20
std::map< std::string, ParsedParameterLine > _lines

◆ ignoreThisLine()

bool ParsedParameterFile::ignoreThisLine ( const std::string &  line)
staticprotected

Definition at line 58 of file ParsedParameterFile.cpp.

58  {
59  if(line.empty())return true;
60  for(int i=0; _ignoreLinesStartingWith[i] != '\0'; i++){
61  if(line[0] == _ignoreLinesStartingWith[i]) return true;
62  }
63  return false;
64 }
static const char _ignoreLinesStartingWith[]

◆ numLines()

unsigned int ParsedParameterFile::numLines ( ) const

Definition at line 52 of file ParsedParameterFile.cpp.

52  {
53  return _lines.size();
54 }
std::map< std::string, ParsedParameterLine > _lines

◆ OK()

bool ParsedParameterFile::OK ( ) const

Definition at line 55 of file ParsedParameterFile.cpp.

55  {
56  return _statusOK;
57 }

◆ print()

void ParsedParameterFile::print ( std::ostream &  os = std::cout) const

Definition at line 85 of file ParsedParameterFile.cpp.

85  {
86  int i=0;
87  for(map<string, ParsedParameterLine>::const_iterator it = _lines.begin();
88  it != _lines.end();
89  it++, i++){
90  os << " " << i << ") " << it->second << endl;
91  }
92 }
std::map< std::string, ParsedParameterLine > _lines

◆ readStream()

void ParsedParameterFile::readStream ( std::istream &  is)
protected

Definition at line 67 of file ParsedParameterFile.cpp.

67  {
68  const int slmax=1000;
69  char line[slmax]={'\0'};
70  while( is.getline(line, slmax)){
71  // std::cout << " just read: " << line << "." << std::endl;
72  if(this->ignoreThisLine(line)) continue;
73  ParsedParameterLine pl(line);
74  if(pl.isValid()){
75  _lines[pl.name()]=pl;
76  }
77  }
78 }
std::map< std::string, ParsedParameterLine > _lines
static bool ignoreThisLine(const std::string &line)

Member Data Documentation

◆ _ignoreLinesStartingWith

const char ParsedParameterFile::_ignoreLinesStartingWith = {'*', '#', '\0'}
staticprotected

Definition at line 18 of file ParsedParameterFile.h.

◆ _lines

std::map<std::string, ParsedParameterLine> MINT::ParsedParameterFile::_lines
protected

Definition at line 20 of file ParsedParameterFile.h.

◆ _statusOK

bool MINT::ParsedParameterFile::_statusOK
protected

Definition at line 21 of file ParsedParameterFile.h.

◆ dummyLine

const ParsedParameterLine ParsedParameterFile::dummyLine
staticprotected

Definition at line 17 of file ParsedParameterFile.h.


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