a Code for the Combination of Indirect and Direct Constraints on High Energy Physics Models Logo
ArgumentParser.cpp
Go to the documentation of this file.
1/*
2 * ArgumentParser.cpp
3 *
4 * Created on: Sep 13, 2012
5 * Author: Ben O'Leary (benjamin.oleary@gmail.com)
6 *
7 * This file is part of BOLlib, released under the
8 * GNU General Public License. Please see the accompanying
9 * README.BOLlib.txt file for a full list of files, brief documentation
10 * on how to use these classes, and further details on the license.
11 */
12
13#include "ArgumentParser.hpp"
14
15namespace BOL
16{
18 char** argumentCharArrays,
19 std::string const inputTag,
20 std::string const fallbackInputFilename ) :
21 argumentStrings( ( argumentCount - 1 ),
22 "" ),
23 inputXmlParser()
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 }
62
64 {
65 // does nothing.
66 }
67
68} /* namespace BOL */
AsciiXmlParser inputXmlParser
std::string fromTag(std::string const &tagString, std::string const defaultReturnString="")
ArgumentParser(int argumentCount, char **argumentCharArrays, std::string const inputTag="", std::string const fallbackInputFilename="")
std::vector< std::string > argumentStrings
bool loadString(std::string const stringToParse)
std::string const & getCurrentElementContent() const
bool readAllOfRootElementOfFile(std::string const &fileName)