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

Description

Handles command line and config file program options.

Definition at line 31 of file AppOptions.h.

Public Member Functions

 ApplicationOptions (int argc=0, char **argv=0)
 
bool disableHighDPISupport () const
 
bool find (std::string name) const
 Returns true if option with given name has been set. 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...
 

Private Member Functions

bpo::options_description & getOptions ()
 Returns reference to the options description. More...
 
bpo::variables_map & getVariables ()
 Returns reference to the variables container. More...
 
void parseCommandLine (int argc, char **argv)
 Parses command line arguments. More...
 
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
 

Constructor & Destructor Documentation

◆ ApplicationOptions()

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

Definition at line 60 of file AppOptions.cpp.

61 {
62  m_options.add_options()("help,h", "print help message and exit");
63  m_options.add_options()("version,v", "print version and exit");
64  m_options.add_options()("with-debug", "run application with debug printout");
65  m_options.add_options()(geometry, bpo::value<std::string>(),
66  "Main window geometry, e.g. 1600x1000");
67  m_options.add_options()(nohighdpi, "Run without high-dpi support");
68 
69  parseCommandLine(argc, argv);
70 
72 }
void parseCommandLine(int argc, char **argv)
Parses command line arguments.
Definition: AppOptions.cpp:88
bpo::options_description m_options
options description, to be filled with add() from different program modules
Definition: AppOptions.h:60

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

Here is the call graph for this function:

Member Function Documentation

◆ disableHighDPISupport()

bool ApplicationOptions::disableHighDPISupport ( ) const

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:81

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 81 of file AppOptions.cpp.

82 {
83  return m_variables_map.count(name);
84 }
bpo::variables_map m_variables_map
Definition: AppOptions.h:63
QString const & name(EShape k)
Definition: particles.cpp:20

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

Referenced by disableHighDPISupport(), and main().

Here is the call graph for this function:

◆ getOptions()

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

Returns reference to the options description.

Definition at line 120 of file AppOptions.cpp.

121 {
122  return m_options;
123 }

References m_options.

◆ getVariables()

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

Returns reference to the variables container.

Definition at line 115 of file AppOptions.cpp.

116 {
117  return m_variables_map;
118 }

References m_variables_map.

◆ 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 76 of file AppOptions.cpp.

77 {
78  return m_variables_map[s];
79 }

References m_variables_map.

◆ parseCommandLine()

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

Parses command line arguments.

parse command line arguments

Definition at line 88 of file AppOptions.cpp.

89 {
90  // parsing command line arguments
91  try {
92  // if positional option description is empty, no command line arguments
93  // without '--' or '-' will be accepted
94  // 'store' populates the variable map
95  bpo::store(bpo::command_line_parser(argc, argv)
96  .options(m_options)
97  .positional(m_positional_options)
98  .run(),
100  // bpo::store(bpo::parse_command_line(argc, argv, m_options), m_variables_map);
101 
102  // 'notify' raises any errors encountered
103  bpo::notify(m_variables_map);
104 
105  } catch (std::exception& e) {
106  std::stringstream s;
107  s << "BornAgain was launched with invalid command line option.\n"
108  << "Parser error message: " << e.what() << ".\n"
109  << "Available options:\n"
110  << m_options << "\n";
111  exitWithGuiMessage(QString::fromStdString(s.str()));
112  }
113 }
bpo::positional_options_description m_positional_options
positional options description, to be filled with addPositional() from main module
Definition: AppOptions.h:62

References m_options, m_positional_options, and m_variables_map.

Referenced by ApplicationOptions().

◆ processOptions()

void ApplicationOptions::processOptions ( )
private

Definition at line 125 of file AppOptions.cpp.

126 {
127  if (m_variables_map.count("help")) {
128  std::cout << "BornAgain Graphical User Interface" << std::endl;
129  std::cout << m_options << std::endl;
130  exit(0);
131  }
132 
133  else if (m_variables_map.count("version")) {
134  std::cout << "BornAgain-" << GUI::Util::Path::getBornAgainVersionString().toStdString()
135  << std::endl;
136  exit(0);
137  }
138 
139  else if (m_variables_map.count(geometry)) {
140  if (!isValid(mainWindowSize()))
141  exitWithGuiMessage("Wrong window size, try --geometry=1600x900\n");
142  }
143 }
QSize mainWindowSize() const
Definition: AppOptions.cpp:145
QString getBornAgainVersionString()
Definition: Path.cpp:60

References GUI::Util::Path::getBornAgainVersionString(), m_options, m_variables_map, and mainWindowSize().

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 60 of file AppOptions.h.

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

◆ m_options_is_consistent

bool ApplicationOptions::m_options_is_consistent
private

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

Definition at line 58 of file AppOptions.h.

◆ 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 62 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: