queso-0.53.0
Public Member Functions | Protected Attributes | Private Attributes | Friends | List of all members
QUESO::BoostInputOptionsParser Class Reference

#include <BoostInputOptionsParser.h>

Inheritance diagram for QUESO::BoostInputOptionsParser:
Inheritance graph
[legend]
Collaboration diagram for QUESO::BoostInputOptionsParser:
Collaboration graph
[legend]

Public Member Functions

 BoostInputOptionsParser (const std::string &filename)
 Constructor that parses file filename. More...
 
 BoostInputOptionsParser ()
 Default constructor that sets m_filename to "". More...
 
virtual ~BoostInputOptionsParser ()
 Destructor. More...
 
void scanInputFile ()
 This is the method that parses the input file. More...
 
template<class T >
void registerOption (std::string name, T defaultValue, std::string description)
 Call this to register an option with the parser. More...
 
void registerOption (std::string name, std::string description)
 For flags without values. Like a help message, for example. More...
 
template<class T >
void getOption (std::string &name, T &value)
 Get option name from the parser and set value to the parsed value. More...
 
template<>
void getOption (std::string &name, std::set< unsigned int, std::less< unsigned int >, std::allocator< unsigned int > > &value)
 
- Public Member Functions inherited from QUESO::BaseInputOptionsParser
 BaseInputOptionsParser ()
 Default constructor. More...
 
virtual ~BaseInputOptionsParser ()
 Destructor. More...
 

Protected Attributes

const std::string & m_filename
 
ScopedPtr
< boost::program_options::options_description >
::Type 
m_optionsDescription
 
ScopedPtr
< boost::program_options::variables_map >
::Type 
m_optionsMap
 

Private Attributes

bool m_scannedInputFile
 

Friends

std::ostream & operator<< (std::ostream &os, const BoostInputOptionsParser &parser)
 Helpful stream operator for printing the parser state. More...
 

Detailed Description

Definition at line 43 of file BoostInputOptionsParser.h.

Constructor & Destructor Documentation

QUESO::BoostInputOptionsParser::BoostInputOptionsParser ( const std::string &  filename)

Constructor that parses file filename.

Definition at line 32 of file BoostInputOptionsParser.C.

33  :
34  m_filename(filename),
35  m_optionsDescription(new boost::program_options::options_description("Input options")),
36  m_optionsMap(new boost::program_options::variables_map()),
37  m_scannedInputFile(false)
38 {
39 }
ScopedPtr< boost::program_options::variables_map >::Type m_optionsMap
ScopedPtr< boost::program_options::options_description >::Type m_optionsDescription
QUESO::BoostInputOptionsParser::BoostInputOptionsParser ( )

Default constructor that sets m_filename to "".

The use-case that options are not read in from a file but are instead wholly provided by the user.

Definition at line 41 of file BoostInputOptionsParser.C.

42  :
43  m_filename(""),
44  m_optionsDescription(new boost::program_options::options_description("Input options")),
45  m_optionsMap(new boost::program_options::variables_map()),
46  m_scannedInputFile(false)
47 {
48 }
ScopedPtr< boost::program_options::variables_map >::Type m_optionsMap
ScopedPtr< boost::program_options::options_description >::Type m_optionsDescription
QUESO::BoostInputOptionsParser::~BoostInputOptionsParser ( )
virtual

Destructor.

Deletes m_optionsDescription

Definition at line 50 of file BoostInputOptionsParser.C.

51 {
52  // Do nothing
53 }

Member Function Documentation

template<typename T >
void QUESO::BoostInputOptionsParser::getOption ( std::string &  name,
T &  value 
)
template<>
template void QUESO::BoostInputOptionsParser::getOption< std::set< unsigned int, std::less< unsigned int >, std::allocator< unsigned int > > > ( std::string &  name,
std::set< unsigned int, std::less< unsigned int >, std::allocator< unsigned int > > &  value 
)

Definition at line 107 of file BoostInputOptionsParser.C.

References m_scannedInputFile, and QUESO::MiscReadDoublesFromString().

108 {
109  if (m_scannedInputFile) {
110  // Clear before putting things in it
111  value.clear();
112 
113  // Get the option as a string
114  // DM: Why do it this way? Doesn't boost support vectors as input
115  // options?
116  std::vector<double> tmpVec(0, 0.0);
117  std::string optionValue;
118  this->getOption<std::string>(name, optionValue);
119  MiscReadDoublesFromString(optionValue, tmpVec);
120 
121  for (unsigned int i = 0; i < tmpVec.size(); i++) {
122  value.insert((unsigned int) tmpVec[i]); // Why cast?!
123  }
124  }
125 }
void MiscReadDoublesFromString(const std::string &inputString, std::vector< double > &outputDoubles)
Definition: Miscellaneous.C:40
template<typename T >
void QUESO::BoostInputOptionsParser::registerOption ( std::string  name,
defaultValue,
std::string  description 
)

Call this to register an option with the parser.

The name of the option to look for in the input file is given by name is given by. If no option is present in the input file, then use defaultValue is used for the default value for the option. Describe the option with a helpful message using description.

Definition at line 79 of file BoostInputOptionsParser.C.

References m_optionsDescription.

Referenced by QUESO::MLSamplingLevelOptions::defineAllOptions(), QUESO::EmOptionsValues::EmOptionsValues(), QUESO::EnvOptionsValues::EnvOptionsValues(), QUESO::GcmOptionsValues::GcmOptionsValues(), QUESO::GPMSAOptions::GPMSAOptions(), QUESO::InfiniteDimensionalMCMCSamplerOptions::InfiniteDimensionalMCMCSamplerOptions(), QUESO::McOptionsValues::McOptionsValues(), QUESO::MhOptionsValues::MhOptionsValues(), QUESO::MLSamplingOptions::MLSamplingOptions(), QUESO::SfpOptionsValues::SfpOptionsValues(), QUESO::SipOptionsValues::SipOptionsValues(), and QUESO::SmOptionsValues::SmOptionsValues().

81 {
82  m_optionsDescription->add_options()
83  (name.c_str(),
84  boost::program_options::value<T>()->default_value(defaultValue),
85  description.c_str());
86 }
ScopedPtr< boost::program_options::options_description >::Type m_optionsDescription
void QUESO::BoostInputOptionsParser::registerOption ( std::string  name,
std::string  description 
)

For flags without values. Like a help message, for example.

Definition at line 89 of file BoostInputOptionsParser.C.

References m_optionsDescription.

90 {
91  m_optionsDescription->add_options()
92  (name.c_str(),
93  description.c_str());
94 }
ScopedPtr< boost::program_options::options_description >::Type m_optionsDescription
void QUESO::BoostInputOptionsParser::scanInputFile ( )

This is the method that parses the input file.

It parses the input file and sets the m_optionsMap member.

Definition at line 56 of file BoostInputOptionsParser.C.

References m_filename, m_optionsDescription, m_optionsMap, m_scannedInputFile, and queso_require_msg.

Referenced by QUESO::EmOptionsValues::EmOptionsValues(), QUESO::EnvOptionsValues::EnvOptionsValues(), QUESO::GcmOptionsValues::GcmOptionsValues(), QUESO::GPMSAOptions::GPMSAOptions(), QUESO::InfiniteDimensionalMCMCSamplerOptions::InfiniteDimensionalMCMCSamplerOptions(), QUESO::McOptionsValues::McOptionsValues(), QUESO::MhOptionsValues::MhOptionsValues(), QUESO::MLSamplingLevelOptions::MLSamplingLevelOptions(), QUESO::MLSamplingOptions::MLSamplingOptions(), QUESO::MLSamplingLevelOptions::scanOptionsValues(), QUESO::SfpOptionsValues::SfpOptionsValues(), QUESO::SipOptionsValues::SipOptionsValues(), and QUESO::SmOptionsValues::SmOptionsValues().

57 {
58  queso_require_msg(m_optionsDescription, "m_optionsDescription variable is NULL");
59 
60  // If it's the empty string then the defaults are used
61  if (m_filename != "") {
62  std::ifstream ifs;
63  ifs.open(m_filename.c_str());
64 
65  queso_require_msg(m_optionsMap, "m_allOptionsMap variable is NULL");
66  boost::program_options::store(
67  boost::program_options::parse_config_file(
68  ifs, *m_optionsDescription, true), *m_optionsMap);
69  boost::program_options::notify(*m_optionsMap);
70 
71  ifs.close();
72 
73  m_scannedInputFile = true;
74  }
75 }
ScopedPtr< boost::program_options::variables_map >::Type m_optionsMap
#define queso_require_msg(asserted, msg)
Definition: asserts.h:69
ScopedPtr< boost::program_options::options_description >::Type m_optionsDescription

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  os,
const BoostInputOptionsParser parser 
)
friend

Helpful stream operator for printing the parser state.

Definition at line 143 of file BoostInputOptionsParser.C.

144 {
145  os << *(parser.m_optionsDescription);
146  return os;
147 }

Member Data Documentation

const std::string& QUESO::BoostInputOptionsParser::m_filename
protected

Definition at line 90 of file BoostInputOptionsParser.h.

Referenced by scanInputFile().

ScopedPtr<boost::program_options::options_description>::Type QUESO::BoostInputOptionsParser::m_optionsDescription
protected

Definition at line 91 of file BoostInputOptionsParser.h.

Referenced by QUESO::operator<<(), registerOption(), and scanInputFile().

ScopedPtr<boost::program_options::variables_map>::Type QUESO::BoostInputOptionsParser::m_optionsMap
protected

Definition at line 92 of file BoostInputOptionsParser.h.

Referenced by scanInputFile().

bool QUESO::BoostInputOptionsParser::m_scannedInputFile
private

Definition at line 95 of file BoostInputOptionsParser.h.

Referenced by getOption(), and scanInputFile().


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

Generated on Thu Jun 11 2015 13:52:34 for queso-0.53.0 by  doxygen 1.8.5