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

#include <ParsedParameterLine.h>

Public Member Functions

 ParsedParameterLine (const std::string &line="")
 
 ParsedParameterLine (const ParsedParameterLine &other)
 
virtual ~ParsedParameterLine ()
 
bool isValid () const
 
virtual const std::string & name () const
 
const std::vector< std::string > & parsedStrings () const
 
virtual void print (std::ostream &os=std::cout) const
 
virtual void stringParsingTest (std::ostream &os=std::cout) const
 

Static Public Member Functions

static bool isBlank (char c)
 
static std::string removeLeadingBlanks (const std::string &s)
 
static std::string removeTrailingBlanks (const std::string &s)
 
static std::string removeLeadingAndTrailingBlanks (const std::string &s)
 
static std::string removeComment (const std::string &line)
 
static std::string removeCommentAndLeadingBlanks (const std::string &line)
 

Protected Member Functions

virtual bool makeParsedStrings (const std::string &line)
 

Static Protected Member Functions

static int makeParsedStrings (const std::string &line, std::vector< std::string > &fillThisList)
 

Protected Attributes

std::string _name
 
std::vector< std::string > _parsedStrings
 

Static Protected Attributes

static const std::string _commentStart ="//"
 
static const std::string _testString =" \"para Name\" 78 70 80 90 100 101 10 11 12\\\\ comment "
 
static const std::string _testName ="para Name"
 

Detailed Description

Definition at line 13 of file ParsedParameterLine.h.

Constructor & Destructor Documentation

◆ ParsedParameterLine() [1/2]

MINT::ParsedParameterLine::ParsedParameterLine ( const std::string &  line = "")
inline

Definition at line 37 of file ParsedParameterLine.h.

37  {
38  makeParsedStrings(line);
39  if(_parsedStrings.empty()){
40  _parsedStrings.push_back("");
41  }
42  }
std::vector< std::string > _parsedStrings
static int makeParsedStrings(const std::string &line, std::vector< std::string > &fillThisList)

◆ ParsedParameterLine() [2/2]

MINT::ParsedParameterLine::ParsedParameterLine ( const ParsedParameterLine other)
inline

Definition at line 43 of file ParsedParameterLine.h.

44  : _name(other._name)
45  , _parsedStrings(other._parsedStrings)
46  {}
std::vector< std::string > _parsedStrings

◆ ~ParsedParameterLine()

virtual MINT::ParsedParameterLine::~ParsedParameterLine ( )
inlinevirtual

Definition at line 48 of file ParsedParameterLine.h.

48 {};

Member Function Documentation

◆ isBlank()

bool ParsedParameterLine::isBlank ( char  c)
static

Definition at line 19 of file ParsedParameterLine.cpp.

19  {
20  return c==' ' || c=='\t' || c=='\n';
21 }

◆ isValid()

bool ParsedParameterLine::isValid ( ) const

Definition at line 64 of file ParsedParameterLine.cpp.

64  {
65  return (! _parsedStrings.empty()) && isalpha(name()[0]);
66 }
std::vector< std::string > _parsedStrings
virtual const std::string & name() const

◆ makeParsedStrings() [1/2]

int ParsedParameterLine::makeParsedStrings ( const std::string &  line,
std::vector< std::string > &  fillThisList 
)
staticprotected

Definition at line 68 of file ParsedParameterLine.cpp.

69  {
70 
71  string s = removeLeadingBlanks(
73  removeComment(line
74  )));
75 
76  if(s.empty()) return 0;
77 
78  s.push_back(' '); // makes sure we get last element
79  s = " " + s; // makes things easier when we start with quotes.
80  string::const_iterator prev=s.begin();
81  bool prevBlank=true;
82  bool insideQuotes=false;
83  // quotes are treated like blanks
84  // but blanks are ignored if we
85  // are inside quotes... makes sense?
86 
87  bool ignore=false;
88  // NOT ANYMORE: we ignore things inside sqare brackets []
89  // to be compatible with Mikhail's ASCII file
90  // format.
91 
92  for(string::const_iterator it=s.begin();
93  it != s.end(); it++){
94  //if((! insideQuotes) && *it == '[') ignore=true;
95  if( ((! insideQuotes) && isBlank(*it)) || *it == '"' || ignore){
96  if(! prevBlank){
97  string tmp_s(prev, it);
98  fillThisList.push_back(tmp_s);
99  }
100  prevBlank=true;
101  }else{
102  if(prevBlank) prev=it;
103  prevBlank=false;
104  }
105  //if((!insideQuotes) && *it == ']') ignore=false;
106  if(*it == '"') insideQuotes = ! insideQuotes;
107  }
108  if(insideQuotes){
109  cout << "WARNING in ParsedParameterLine::makeParsedStrings \n"
110  << " unbalanced quotes in string:\n"
111  << line << endl;
112  }
113  return fillThisList.size();
114 }
static std::string removeComment(const std::string &line)
static const double s
static std::string removeTrailingBlanks(const std::string &s)
static std::string removeLeadingBlanks(const std::string &s)

◆ makeParsedStrings() [2/2]

bool ParsedParameterLine::makeParsedStrings ( const std::string &  line)
protectedvirtual

Definition at line 116 of file ParsedParameterLine.cpp.

116  {
118  return ! _parsedStrings.empty();
119 }
std::vector< std::string > _parsedStrings
static int makeParsedStrings(const std::string &line, std::vector< std::string > &fillThisList)

◆ name()

virtual const std::string& MINT::ParsedParameterLine::name ( ) const
inlinevirtual

Definition at line 52 of file ParsedParameterLine.h.

52  {
53  return _parsedStrings[0];
54  }
std::vector< std::string > _parsedStrings

◆ parsedStrings()

const std::vector<std::string>& MINT::ParsedParameterLine::parsedStrings ( ) const
inline

Definition at line 55 of file ParsedParameterLine.h.

55  {
56  return _parsedStrings;
57  }
std::vector< std::string > _parsedStrings

◆ print()

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

Definition at line 121 of file ParsedParameterLine.cpp.

121  {
122  for(unsigned int i=0; i<_parsedStrings.size(); i++){
123  os << _parsedStrings[i];
124  if(i != _parsedStrings.size()-1) os << "; ";
125  }
126 }
std::vector< std::string > _parsedStrings

◆ removeComment()

string ParsedParameterLine::removeComment ( const std::string &  line)
static

Definition at line 49 of file ParsedParameterLine.cpp.

49  {
50  if(s_in.empty()) return s_in;
51  string s = s_in;
52  int commentStart = s.find(_commentStart);
53  //cout << " commentStart " << commentStart << endl;
54  if(commentStart >= 0 && commentStart < (int) s.size()){
55  s.resize(commentStart);
56  }
57  return s;
58 }
static const double s
static const std::string _commentStart

◆ removeCommentAndLeadingBlanks()

string ParsedParameterLine::removeCommentAndLeadingBlanks ( const std::string &  line)
static

Definition at line 60 of file ParsedParameterLine.cpp.

60  {
61  return removeComment(removeLeadingBlanks(s_in));
62 }
static std::string removeComment(const std::string &line)
static std::string removeLeadingBlanks(const std::string &s)

◆ removeLeadingAndTrailingBlanks()

std::string ParsedParameterLine::removeLeadingAndTrailingBlanks ( const std::string &  s)
static

Definition at line 45 of file ParsedParameterLine.cpp.

45  {
47 }
static const double s
static std::string removeTrailingBlanks(const std::string &s)
static std::string removeLeadingBlanks(const std::string &s)

◆ removeLeadingBlanks()

std::string ParsedParameterLine::removeLeadingBlanks ( const std::string &  s)
static

Definition at line 22 of file ParsedParameterLine.cpp.

22  {
23  if(s.empty()) return s;
24  std::string::const_iterator firstNonBlank=s.begin();
25  for(firstNonBlank=s.begin();
26  firstNonBlank != s.end() && (isBlank(*firstNonBlank));
27  firstNonBlank++) ;
28  // cout << "firstNonBlank: " << *firstNonBlank << "." << endl;
29 
30  string new_s(firstNonBlank, s.end());
31  return new_s;
32 }
static const double s

◆ removeTrailingBlanks()

std::string ParsedParameterLine::removeTrailingBlanks ( const std::string &  s)
static

Definition at line 33 of file ParsedParameterLine.cpp.

33  {
34  if(s.empty()) return s;
35  std::string::const_iterator lastNonBlank = s.end();
36  for(string::const_iterator it=s.begin();
37  it != s.end(); it++){
38  if(! isBlank(*it)) lastNonBlank = it;
39  }
40  if(lastNonBlank != s.end()) lastNonBlank++;
41 
42  string new_s(s.begin(), lastNonBlank);
43  return new_s;
44 }
static const double s

◆ stringParsingTest()

void ParsedParameterLine::stringParsingTest ( std::ostream &  os = std::cout) const
virtual

Definition at line 128 of file ParsedParameterLine.cpp.

128  {
129  os << "Testing the String Parsing in ParsedParameterLine:" << endl;
130  os << " test string is (w/o the '>' and '<'):\n"
131  << " >" << _testString << "<" << endl;
132  string noBlanks = removeLeadingBlanks(_testString);
133  os << " ... removing leading blanks gives:\n"
134  << " >" << noBlanks << "<" << endl;
135  os << " ... removing trailing blanks gives:\n"
136  << " >" << removeTrailingBlanks(_testString) << "<" << endl;
137  string noComment = removeComment(_testString);
138  os << " ... string without comment:\n"
139  << " >" << noComment << "<"
140  << endl;
141  os << " ... string without comment run through removeComment again:\n"
142  << " >" << removeComment(noComment) << "<"
143  << endl;
144  os << " ... removeCommentAndLeadingBlanks\n"
145  << " >" << removeCommentAndLeadingBlanks(_testString) << "<"
146  << endl;
147 
148  vector<string> valueStringList;
149  makeParsedStrings(_testString, valueStringList);
150  os << " made value string list:\n";
151  for(unsigned int i=0; i< valueStringList.size(); i++){
152  os << " " << i << ") >" << valueStringList[i] << "< " << endl;
153  }
154  os << "test done." << endl;
155 
156  return;
157 }
static std::string removeCommentAndLeadingBlanks(const std::string &line)
static std::string removeComment(const std::string &line)
static int makeParsedStrings(const std::string &line, std::vector< std::string > &fillThisList)
static std::string removeTrailingBlanks(const std::string &s)
static std::string removeLeadingBlanks(const std::string &s)
static const std::string _testString

Member Data Documentation

◆ _commentStart

const std::string ParsedParameterLine::_commentStart ="//"
staticprotected

Definition at line 16 of file ParsedParameterLine.h.

◆ _name

std::string MINT::ParsedParameterLine::_name
protected

Definition at line 20 of file ParsedParameterLine.h.

◆ _parsedStrings

std::vector<std::string> MINT::ParsedParameterLine::_parsedStrings
protected

Definition at line 21 of file ParsedParameterLine.h.

◆ _testName

const std::string ParsedParameterLine::_testName ="para Name"
staticprotected

Definition at line 18 of file ParsedParameterLine.h.

◆ _testString

const std::string ParsedParameterLine::_testString =" \"para Name\" 78 70 80 90 100 101 10 11 12\\\\ comment "
staticprotected

Definition at line 17 of file ParsedParameterLine.h.


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