BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
ApplicationOptions Class Reference

Handles command line and config file program options. More...

Public Member Functions

 ApplicationOptions (int argc=0, char **argv=0)
 
bool disableHighDPISupport ()
 
bool find (std::string name) const
 Returns true if option with given name has been set. More...
 
bpo::options_description & getOptions ()
 Returns reference to the options description. More...
 
bpo::variables_map & getVariables ()
 Returns reference to the variables container. More...
 
bool isConsistent () const
 Returns true if options are consistent (no conflicts, no –help request) More...
 
QSize mainWindowSize () const
 
const bpo::variable_value & operator[] (const std::string &s) const
 access to variable with given name defined in variables container More...
 
void parseCommandLine (int argc, char **argv)
 Parses command line arguments. More...
 
void printHelpMessage () const
 
void processOptions ()
 

Private Attributes

bpo::options_description m_options
 options description, to be filled with add() from different program modules More...
 
bool m_options_is_consistent
 true if options are consistent (no conflicts, no –help request) More...
 
bpo::positional_options_description m_positional_options
 positional options description, to be filled with addPositional() from main module More...
 
bpo::variables_map m_variables_map
 

Detailed Description

Handles command line and config file program options.

Definition at line 32 of file appoptions.h.

Constructor & Destructor Documentation

◆ ApplicationOptions()

ApplicationOptions::ApplicationOptions ( int  argc = 0,
char **  argv = 0 
)

Definition at line 49 of file appoptions.cpp.

50 {
51  m_options.add_options()("help,h", "print help message");
52  m_options.add_options()("with-debug", "run application with debug printout");
53  m_options.add_options()("no-splash", "do not show splash screen");
54  m_options.add_options()(geometry, bpo::value<std::string>(),
55  "Main window geometry, e.g. 1600x1000");
56  m_options.add_options()(nohighdpi, "Run without high-dpi support");
57 
58  parseCommandLine(argc, argv);
59 
61 }
void parseCommandLine(int argc, char **argv)
Parses command line arguments.
Definition: appoptions.cpp:82
bool m_options_is_consistent
true if options are consistent (no conflicts, no –help request)
Definition: appoptions.h:64
bpo::options_description m_options
options description, to be filled with add() from different program modules
Definition: appoptions.h:66

References m_options, parseCommandLine(), and processOptions().

Here is the call graph for this function:

Member Function Documentation

◆ disableHighDPISupport()

bool ApplicationOptions::disableHighDPISupport ( )

Definition at line 151 of file appoptions.cpp.

152 {
153  return find(nohighdpi);
154 }
bool find(std::string name) const
Returns true if option with given name has been set.
Definition: appoptions.cpp:70

References find().

Referenced by main().

Here is the call graph for this function:

◆ find()

bool ApplicationOptions::find ( std::string  name) const

Returns true if option with given name has been set.

Definition at line 70 of file appoptions.cpp.

71 {
72  return (m_variables_map.count(name.c_str()));
73 }
bpo::variables_map m_variables_map
Definition: appoptions.h:69
QString const & name(EShape k)
Definition: particles.cpp:21

References m_variables_map, and RealSpace::Particles::name().

Referenced by disableHighDPISupport(), and main().

Here is the call graph for this function:

◆ getOptions()

boost::program_options::options_description & ApplicationOptions::getOptions ( )

Returns reference to the options description.

Definition at line 113 of file appoptions.cpp.

114 {
115  return m_options;
116 }

References m_options.

◆ getVariables()

boost::program_options::variables_map & ApplicationOptions::getVariables ( )

Returns reference to the variables container.

Definition at line 108 of file appoptions.cpp.

109 {
110  return m_variables_map;
111 }

References m_variables_map.

◆ isConsistent()

bool ApplicationOptions::isConsistent ( ) const

Returns true if options are consistent (no conflicts, no –help request)

Definition at line 75 of file appoptions.cpp.

76 {
78 }

References m_options_is_consistent.

Referenced by main().

◆ mainWindowSize()

QSize ApplicationOptions::mainWindowSize ( ) const

Definition at line 145 of file appoptions.cpp.

146 {
147  QString size_str = QString::fromStdString(m_variables_map[geometry].as<std::string>());
148  return windowSize(size_str);
149 }

References m_variables_map.

Referenced by main(), and processOptions().

◆ operator[]()

const bpo::variable_value & ApplicationOptions::operator[] ( const std::string &  s) const

access to variable with given name defined in variables container

access variables

Definition at line 65 of file appoptions.cpp.

66 {
67  return m_variables_map[s.c_str()];
68 }

References m_variables_map.

◆ parseCommandLine()

void ApplicationOptions::parseCommandLine ( int  argc,
char **  argv 
)

Parses command line arguments.

parse command line arguments

Definition at line 82 of file appoptions.cpp.

83 {
85  // parsing command line arguments
86  try {
87  // if positional option description is empty, no command line arguments
88  // without '--' or '-' will be accepted
89  // 'store' populates the variable map
90  bpo::store(bpo::command_line_parser(argc, argv)
91  .options(m_options)
92  .positional(m_positional_options)
93  .run(),
95  // bpo::store(bpo::parse_command_line(argc, argv, m_options), m_variables_map);
96 
97  // 'notify' raises any errors encountered
98  bpo::notify(m_variables_map);
99 
101  } catch (std::exception& e) {
102  // we get here if there is unrecognized options
103  std::cout << "main() -> " << e.what() << std::endl;
104  std::cout << m_options << std::endl;
105  }
106 }
bpo::positional_options_description m_positional_options
positional options description, to be filled with addPositional() from main module
Definition: appoptions.h:68

References m_options, m_options_is_consistent, m_positional_options, and m_variables_map.

Referenced by ApplicationOptions().

◆ printHelpMessage()

void ApplicationOptions::printHelpMessage ( ) const

Definition at line 139 of file appoptions.cpp.

140 {
141  std::cout << "BornAgain Graphical User Interface" << std::endl;
142  std::cout << m_options << std::endl;
143 }

References m_options.

Referenced by processOptions().

◆ processOptions()

void ApplicationOptions::processOptions ( )

Definition at line 118 of file appoptions.cpp.

119 {
120  if (m_variables_map.count("help")) {
122  m_options_is_consistent = false;
123  }
124 
125  else if (m_variables_map.count("version")) {
126  std::cout << "BornAgain-" << GUIHelpers::getBornAgainVersionString().toStdString()
127  << std::endl;
128  m_options_is_consistent = false;
129  }
130 
131  else if (m_variables_map.count(geometry)) {
132  if (!isValid(mainWindowSize())) {
133  std::cout << "Wrong window size, try --geometry=1600x900\n";
134  m_options_is_consistent = false;
135  }
136  }
137 }
QSize mainWindowSize() const
Definition: appoptions.cpp:145
void printHelpMessage() const
Definition: appoptions.cpp:139
QString getBornAgainVersionString()
Definition: GUIHelpers.cpp:130

References GUIHelpers::getBornAgainVersionString(), m_options_is_consistent, m_variables_map, mainWindowSize(), and printHelpMessage().

Referenced by ApplicationOptions().

Here is the call graph for this function:

Member Data Documentation

◆ m_options

bpo::options_description ApplicationOptions::m_options
private

options description, to be filled with add() from different program modules

Definition at line 66 of file appoptions.h.

Referenced by ApplicationOptions(), getOptions(), parseCommandLine(), and printHelpMessage().

◆ m_options_is_consistent

bool ApplicationOptions::m_options_is_consistent
private

true if options are consistent (no conflicts, no –help request)

Definition at line 64 of file appoptions.h.

Referenced by isConsistent(), parseCommandLine(), and processOptions().

◆ m_positional_options

bpo::positional_options_description ApplicationOptions::m_positional_options
private

positional options description, to be filled with addPositional() from main module

Definition at line 68 of file appoptions.h.

Referenced by parseCommandLine().

◆ m_variables_map

bpo::variables_map ApplicationOptions::m_variables_map
private

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