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

#include <ArgumentParser.hpp>

Detailed Description

Definition at line 25 of file ArgumentParser.hpp.

Public Member Functions

 ArgumentParser (int argumentCount, char **argumentCharArrays, std::string const inputTag="", std::string const fallbackInputFilename="")
 
std::string fromLiteral (std::string const &argumentName, std::string const defaultReturnString="") const
 
std::string fromTag (std::string const &tagString, std::string const defaultReturnString="")
 
 ~ArgumentParser ()
 

Protected Attributes

std::vector< std::string > argumentStrings
 
AsciiXmlParser inputXmlParser
 

Constructor & Destructor Documentation

◆ ArgumentParser()

BOL::ArgumentParser::ArgumentParser ( int  argumentCount,
char **  argumentCharArrays,
std::string const  inputTag = "",
std::string const  fallbackInputFilename = "" 
)

Definition at line 17 of file ArgumentParser.cpp.

20 :
21 argumentStrings( ( argumentCount - 1 ),
22 "" ),
24 {
26 for( int whichArgument( 1 );
27 argumentCount > whichArgument;
28 ++whichArgument )
29 {
30 argumentStrings[ whichArgument - 1 ].assign(
31 argumentCharArrays[ whichArgument ] );
32 }
33 if( !(inputTag.empty()) )
34 {
35 std::string inputFilename( fromTag( inputTag ) );
36 if( inputFilename.empty() )
37 {
38 inputFilename.assign( fallbackInputFilename );
39 }
40 // at this point, if no input filename was provided either by the command
41 // line arguments or by the constructor, I think that it's obvious that
42 // the user didn't want to look for arguments in an XML file, so the
43 // error message should not be shown for failing to open it.
44 if( !(inputFilename.empty()) )
45 {
46 bool successfullyRead( inputXmlParser.readAllOfRootElementOfFile(
47 inputFilename )
48 &&
51 if( !successfullyRead )
52 {
53 std::cout
54 << std::endl
55 << "BOL::ArgumentParser constructor failed to open root element of"
56 << " \"" << inputFilename << "\"!";
57 std::cout << std::endl;
58 }
59 }
60 }
61 }
AsciiXmlParser inputXmlParser
std::string fromTag(std::string const &tagString, std::string const defaultReturnString="")
std::vector< std::string > argumentStrings
bool loadString(std::string const stringToParse)
std::string const & getCurrentElementContent() const
bool readAllOfRootElementOfFile(std::string const &fileName)

◆ ~ArgumentParser()

BOL::ArgumentParser::~ArgumentParser ( )

Definition at line 63 of file ArgumentParser.cpp.

64 {
65 // does nothing.
66 }

Member Function Documentation

◆ fromLiteral()

std::string BOL::ArgumentParser::fromLiteral ( std::string const &  argumentName,
std::string const  defaultReturnString = "" 
) const
inline

Definition at line 59 of file ArgumentParser.hpp.

64 {
65 for( std::vector< std::string >::const_iterator
66 whichArgument( argumentStrings.begin() );
67 argumentStrings.end() > whichArgument;
68 ++whichArgument )
69 {
70 if( 0 == whichArgument->compare( 0,
71 argumentName.size(),
72 argumentName ) )
73 {
74 return whichArgument->substr( argumentName.size() );
75 }
76 }
77 return defaultReturnString;
78 }

◆ fromTag()

std::string BOL::ArgumentParser::fromTag ( std::string const &  tagString,
std::string const  defaultReturnString = "" 
)
inline

Definition at line 81 of file ArgumentParser.hpp.

87 {
88 std::string argumentString( "--" );
89 argumentString.append( tagString );
90 argumentString.append( "=" );
91 argumentString.assign( fromLiteral( argumentString ) );
92 if( !(argumentString.empty()) )
93 {
94 return argumentString;
95 }
98 {
100 {
104 }
105 }
106 return defaultReturnString;
107 }
std::string fromLiteral(std::string const &argumentName, std::string const defaultReturnString="") const
bool currentElementNameMatches(std::string const &comparisonString) const
static std::string const whitespaceAndNewlineChars
static std::string trimFromFrontAndBack(std::string const &stringToTrim, std::string const &charsToTrim=whitespaceAndNewlineChars)

Member Data Documentation

◆ argumentStrings

std::vector< std::string > BOL::ArgumentParser::argumentStrings
protected

Definition at line 50 of file ArgumentParser.hpp.

◆ inputXmlParser

AsciiXmlParser BOL::ArgumentParser::inputXmlParser
protected

Definition at line 51 of file ArgumentParser.hpp.


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