a Code for the Combination of Indirect and Direct Constraints on High Energy Physics Models Logo
BOL::CommentedTextParser Class Reference

#include <CommentedTextParser.hpp>

Detailed Description

Definition at line 27 of file CommentedTextParser.hpp.

Public Member Functions

bool atEndOfFile ()
 
CommentedTextParsercloseFile ()
 
 CommentedTextParser (std::string const &commentMarker, bool const isVerbose)
 
 CommentedTextParser (VectorlikeArray< std::string > const &commentMarkerSet, bool const isVerbose)
 
bool openFile (std::string const &fileName)
 
bool parseNextLineOfFile (std::string &stringForData, std::string &stringForComment)
 
VectorlikeArray< std::pair< std::string, std::string > > const & parseString (std::string const &textToParse)
 
bool readJustNextValidLine (std::string &stringToFill)
 
bool readNextNonEmptyLineOfFileWithoutComment (std::string &stringToFill)
 
virtual ~CommentedTextParser ()
 

Protected Member Functions

bool readInNextLine ()
 
void reportStateOfFile ()
 

Protected Attributes

VectorlikeArray< std::string > commentMarkerSet
 
std::ifstream inputFile
 
bool const isVerbose
 
std::string lineBeingRead
 
bool linesOfFileRemain
 
std::pair< std::string, std::string > parsedLine
 
VectorlikeArray< std::pair< std::string, std::string > > parsedText
 
VectorlikeArray< std::string > textAsLines
 

Static Protected Attributes

static std::string const trimmingChars
 

Constructor & Destructor Documentation

◆ CommentedTextParser() [1/2]

BOL::CommentedTextParser::CommentedTextParser ( std::string const &  commentMarker,
bool const  isVerbose 
)

Definition at line 19 of file CommentedTextParser.cpp.

20 :
23 parsedText(),
24 parsedLine( "",
25 "" ),
27 lineBeingRead( "" ),
28 linesOfFileRemain( false ),
29 inputFile()
30 {
31 commentMarkerSet.getFront().assign( commentMarker );
32 }
VectorlikeArray< std::string > commentMarkerSet
VectorlikeArray< std::string > textAsLines
std::pair< std::string, std::string > parsedLine
VectorlikeArray< std::pair< std::string, std::string > > parsedText

◆ CommentedTextParser() [2/2]

BOL::CommentedTextParser::CommentedTextParser ( VectorlikeArray< std::string > const &  commentMarkerSet,
bool const  isVerbose 
)

Definition at line 34 of file CommentedTextParser.cpp.

36 :
39 parsedText(),
40 parsedLine( "",
41 "" ),
43 lineBeingRead( "" ),
44 linesOfFileRemain( false ),
45 inputFile()
46 {
47 // just an initialization list.
48 }

◆ ~CommentedTextParser()

BOL::CommentedTextParser::~CommentedTextParser ( )
virtual

Definition at line 50 of file CommentedTextParser.cpp.

51 {
52 if( inputFile.is_open() )
53 {
54 inputFile.close();
55 }
56 }

Member Function Documentation

◆ atEndOfFile()

bool BOL::CommentedTextParser::atEndOfFile ( )
inline

Definition at line 175 of file CommentedTextParser.hpp.

178 {
179 return !linesOfFileRemain;
180 }

◆ closeFile()

CommentedTextParser & BOL::CommentedTextParser::closeFile ( )
inline

Definition at line 183 of file CommentedTextParser.hpp.

184 {
185 linesOfFileRemain = false;
186 if( inputFile.is_open() )
187 {
188 inputFile.close();
189 }
190 return *this;
191 }

◆ openFile()

bool BOL::CommentedTextParser::openFile ( std::string const &  fileName)
inline

Definition at line 146 of file CommentedTextParser.hpp.

151 {
152 closeFile();
153 // this sets notYetAtEndOfFile to false & also closes inputFile if it was
154 // open.
155 inputFile.open( fileName.c_str() );
156 if( inputFile.is_open()
157 &&
158 !(inputFile.eof()) )
159 {
160 linesOfFileRemain = true;
161 }
162 else
163 {
164 std::cout
165 << std::endl
166 << "BOL::error! CommentedTextParser tried to open "
167 << fileName << " but could not (or " << fileName << " is empty)!";
168 std::cout << std::endl;
169 linesOfFileRemain = false;
170 }
171 return linesOfFileRemain;
172 }
CommentedTextParser & closeFile()

◆ parseNextLineOfFile()

bool BOL::CommentedTextParser::parseNextLineOfFile ( std::string &  stringForData,
std::string &  stringForComment 
)
inline

Definition at line 194 of file CommentedTextParser.hpp.

202 {
203 if( readInNextLine() )
204 {
205 stringForData.assign( BOL::StringParser::substringToFirst(
209 &stringForComment ) );
210 /* this puts all of the line just read before the comment marker into
211 * stringForData & the remainder into stringForComment (including the
212 * comment characters).
213 */
214 BOL::StringParser::trimFromBack( stringForData,
216 return true;
217 }
218 else
219 {
220 return false;
221 }
222 }
static std::string trimFromBack(std::string const &stringToTrim, std::string const &charsToTrim)
static std::string const newlineChars
static std::string substringToFirst(std::string const &stringToParse, VectorlikeArray< std::string > const &delimitersOfSubstring, std::string *const remainderString=NULL)

◆ parseString()

VectorlikeArray< std::pair< std::string, std::string > > const & BOL::CommentedTextParser::parseString ( std::string const &  textToParse)
inline

Definition at line 115 of file CommentedTextParser.hpp.

122 {
126 // now textAsLines is textToParse broken up into strings corresponding to
127 // each line of textToParse. parsedText has to fit all of textAsLines:
128 parsedText.setSize( textAsLines.getSize() );
129 for( int lineIndex( textAsLines.getLastIndex() );
130 0 <= lineIndex;
131 --lineIndex )
132 {
133 parsedText[ lineIndex ].first.assign(
136 &(parsedText[ lineIndex ].second) ) );
137 /* this puts all of textAsLines[ lineIndex ] before the comment marker
138 * into parsedText[ lineIndex ].first & the remainder into
139 * parsedText[ lineIndex ].second (including the comment characters).
140 */
141 }
142 return parsedText;
143 }
static void parseByChar(std::string const &stringToParse, VectorlikeArray< std::string > &destinationArray, std::string const &divisionCharSet=whitespaceChars)

◆ readInNextLine()

bool BOL::CommentedTextParser::readInNextLine ( )
inlineprotected

Definition at line 257 of file CommentedTextParser.hpp.

264 {
266 {
267 std::getline( inputFile,
271 &&
272 isVerbose )
273 {
275 }
276 return true;
277 }
278 else
279 {
280 return false;
281 }
282 }

◆ readJustNextValidLine()

bool BOL::CommentedTextParser::readJustNextValidLine ( std::string &  stringToFill)
inline

Definition at line 77 of file CommentedTextParser.hpp.

78 { return readNextNonEmptyLineOfFileWithoutComment( stringToFill ); }
bool readNextNonEmptyLineOfFileWithoutComment(std::string &stringToFill)

◆ readNextNonEmptyLineOfFileWithoutComment()

bool BOL::CommentedTextParser::readNextNonEmptyLineOfFileWithoutComment ( std::string &  stringToFill)
inline

Definition at line 225 of file CommentedTextParser.hpp.

234 {
235 stringToFill.clear();
236 while( stringToFill.empty()
237 &&
239 // the order of these conditionals is important: it has to check if it
240 // needs to read in the next line before it tries to read it in!
241 {
244 /* this puts all of the line just read before the comment marker into
245 * stringToFill & throws away the remainder. now all trimmingChars chars
246 * are trimmed from the front & back of stringToFill:
247 */
248 stringToFill.assign( BOL::StringParser::trimFromFrontAndBack(
249 stringToFill,
250 trimmingChars ) );
251 }
252 // now either stringToFill is not empty, or inputFile ran out of lines.
253 return !(stringToFill.empty());
254 }
static std::string const trimmingChars
static std::string trimFromFrontAndBack(std::string const &stringToTrim, std::string const &charsToTrim=whitespaceAndNewlineChars)

◆ reportStateOfFile()

void BOL::CommentedTextParser::reportStateOfFile ( )
inlineprotected

Definition at line 285 of file CommentedTextParser.hpp.

288 {
289 if( inputFile.eof() )
290 // if reading in this line brought inputFile to its end, note that.
291 {
292 std::cout
293 << std::endl
294 << "BOL::CommentedTextParser reached the end of the file.";
295 std::cout << std::endl;
296 }
297 else
298 {
299 std::cout
300 << std::endl
301 << "BOL::CommentedTextParser cannot read in any more of the file after"
302 << " a bad reading operation.";
303 std::cout << std::endl;
304 }
305 }

Member Data Documentation

◆ commentMarkerSet

VectorlikeArray< std::string > BOL::CommentedTextParser::commentMarkerSet
protected

Definition at line 87 of file CommentedTextParser.hpp.

◆ inputFile

std::ifstream BOL::CommentedTextParser::inputFile
protected

Definition at line 95 of file CommentedTextParser.hpp.

◆ isVerbose

bool const BOL::CommentedTextParser::isVerbose
protected

Definition at line 86 of file CommentedTextParser.hpp.

◆ lineBeingRead

std::string BOL::CommentedTextParser::lineBeingRead
protected

Definition at line 91 of file CommentedTextParser.hpp.

◆ linesOfFileRemain

bool BOL::CommentedTextParser::linesOfFileRemain
protected

Definition at line 92 of file CommentedTextParser.hpp.

◆ parsedLine

std::pair< std::string, std::string > BOL::CommentedTextParser::parsedLine
protected

Definition at line 89 of file CommentedTextParser.hpp.

◆ parsedText

VectorlikeArray< std::pair< std::string, std::string > > BOL::CommentedTextParser::parsedText
protected

Definition at line 88 of file CommentedTextParser.hpp.

◆ textAsLines

VectorlikeArray< std::string > BOL::CommentedTextParser::textAsLines
protected

Definition at line 90 of file CommentedTextParser.hpp.

◆ trimmingChars

std::string const BOL::CommentedTextParser::trimmingChars
staticprotected

Definition at line 84 of file CommentedTextParser.hpp.


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