BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
MinimizerOptions Class Reference
Inheritance diagram for MinimizerOptions:
Collaboration diagram for MinimizerOptions:

Public Types

using option_t = std::shared_ptr< MultiOption >
 
using container_t = std::vector< option_t >
 
using iterator = container_t::iterator
 
using const_iterator = container_t::const_iterator
 

Public Member Functions

std::string toOptionString () const
 
void setOptionString (const std::string &options)
 
template<class T >
option_t addOption (const std::string &optionName, T value, const std::string &description="")
 
option_t option (const std::string &optionName)
 
const option_t option (const std::string &optionName) const
 
template<class T >
optionValue (const std::string &optionName) const
 
template<class T >
void setOptionValue (const std::string &optionName, T value)
 
iterator begin ()
 
const_iterator begin () const
 
iterator end ()
 
const_iterator end () const
 
size_t size () const
 
bool empty () const
 

Protected Member Functions

bool exists (const std::string &name)
 
void swapContent (OptionContainer &other)
 

Protected Attributes

container_t m_options
 

Private Member Functions

void processCommand (const std::string &command)
 

Detailed Description

Collection of internal minimizer settings.

Definition at line 23 of file MinimizerOptions.h.

Member Typedef Documentation

◆ option_t

using OptionContainer::option_t = std::shared_ptr<MultiOption>
inherited

Definition at line 30 of file OptionContainer.h.

◆ container_t

using OptionContainer::container_t = std::vector<option_t>
inherited

Definition at line 31 of file OptionContainer.h.

◆ iterator

using OptionContainer::iterator = container_t::iterator
inherited

Definition at line 32 of file OptionContainer.h.

◆ const_iterator

using OptionContainer::const_iterator = container_t::const_iterator
inherited

Definition at line 33 of file OptionContainer.h.

Member Function Documentation

◆ toOptionString()

std::string MinimizerOptions::toOptionString ( ) const

Returns string with all options (i.e. "Strategy=1;Tolerance=0.01;")

Definition at line 26 of file MinimizerOptions.cpp.

27 {
28  std::ostringstream result;
29  for (auto option : m_options) {
30  result << option->name() << "=" << option->value() << delimeter;
31  }
32  return result.str();
33 }
container_t m_options
option_t option(const std::string &optionName)

References anonymous_namespace{MinimizerOptions.cpp}::delimeter, OptionContainer::m_options, and OptionContainer::option().

Referenced by anonymous_namespace{MinimizerResultUtils.cpp}::reportOption().

Here is the call graph for this function:

◆ setOptionString()

void MinimizerOptions::setOptionString ( const std::string &  options)

Set options from their string representation.

Definition at line 35 of file MinimizerOptions.cpp.

36 {
37  // splits multiple option string "Strategy=1;Tolerance=0.01;"
38  std::vector<std::string> tokens = StringUtils::split(options, delimeter);
39  try {
40  for (std::string opt : tokens)
41  if (!opt.empty())
42  processCommand(opt);
43  } catch (std::exception& ex) {
44  std::ostringstream ostr;
45  ostr << "MinimizerOptions::setOptions() -> Error. Can't parse option string '" << options
46  << "'.\n, error message '" << ex.what() << "'";
47  throw std::runtime_error(ostr.str());
48  }
49 }
void processCommand(const std::string &command)
Process single option string 'Tolerance=0.01' and sets the value to corresponding MultiOption.
std::vector< std::string > split(const std::string &text, const std::string &delimeter)
Split string into vector of string using delimeter.
Definition: StringUtils.cpp:57

References anonymous_namespace{MinimizerOptions.cpp}::delimeter, processCommand(), and StringUtils::split().

Referenced by RootMinimizerAdapter::setOptions().

Here is the call graph for this function:

◆ processCommand()

void MinimizerOptions::processCommand ( const std::string &  command)
private

Process single option string 'Tolerance=0.01' and sets the value to corresponding MultiOption.

Definition at line 54 of file MinimizerOptions.cpp.

55 {
56  std::vector<std::string> tokens = StringUtils::split(command, "=");
57  if (tokens.size() != 2)
58  throw std::runtime_error("MinimizerOptions::processOption() -> Can't parse option '"
59  + command + "'");
60 
61  std::string name = tokens[0];
62  std::string value = tokens[1];
63 
65  opt->setFromString(value);
66 }
std::shared_ptr< MultiOption > option_t

References OptionContainer::option(), and StringUtils::split().

Referenced by setOptionString().

Here is the call graph for this function:

◆ addOption()

template<class T >
OptionContainer::option_t OptionContainer::addOption ( const std::string &  optionName,
value,
const std::string &  description = "" 
)
inherited

Definition at line 66 of file OptionContainer.h.

68 {
69  if (exists(optionName))
70  throw std::runtime_error("OptionContainer::addOption() -> Error. Option '" + optionName
71  + "' exists.");
72 
73  option_t result(new MultiOption(optionName, value, description));
74  m_options.push_back(result);
75  return result;
76 }
Stores a single option for minimization algorithm.
Definition: MultiOption.h:26
bool exists(const std::string &name)

References OptionContainer::exists(), and OptionContainer::m_options.

Referenced by RootMinimizerAdapter::addOption().

Here is the call graph for this function:

◆ option() [1/2]

OptionContainer::option_t OptionContainer::option ( const std::string &  optionName)
inherited

Definition at line 34 of file OptionContainer.cpp.

35 {
36  for (const auto& option : m_options) {
37  if (option->name() == optionName)
38  return option;
39  }
40 
41  throw std::runtime_error("Configurable::getOption() -> Error. No option with name '"
42  + optionName + "'.");
43 }

References OptionContainer::m_options.

Referenced by OptionContainer::exists(), OptionContainer::option(), OptionContainer::OptionContainer(), OptionContainer::optionValue(), processCommand(), OptionContainer::setOptionValue(), and toOptionString().

◆ option() [2/2]

const OptionContainer::option_t OptionContainer::option ( const std::string &  optionName) const
inherited

Definition at line 45 of file OptionContainer.cpp.

46 {
47  for (const auto& option : m_options) {
48  if (option->name() == optionName)
49  return option;
50  }
51 
52  throw std::runtime_error("Configurable::getOption() -> Error. No option with name '"
53  + optionName + "'.");
54 }

References OptionContainer::m_options, and OptionContainer::option().

Here is the call graph for this function:

◆ optionValue()

template<class T >
T OptionContainer::optionValue ( const std::string &  optionName) const
inherited

Definition at line 78 of file OptionContainer.h.

79 {
80  return option(optionName)->get<T>();
81 }

References OptionContainer::option().

Referenced by RootMinimizerAdapter::optionValue().

Here is the call graph for this function:

◆ setOptionValue()

template<class T >
void OptionContainer::setOptionValue ( const std::string &  optionName,
value 
)
inherited

Sets the value of option. Option should hold same value type already.

Definition at line 83 of file OptionContainer.h.

84 {
85  option(optionName)->value() = value;
86  if (option(optionName)->value().which() != option(optionName)->defaultValue().which())
87  throw std::runtime_error(
88  "OptionContainer::setOptionValue() -> Error. Attempt to set different"
89  "type to option '"
90  + optionName + "'");
91 }

References OptionContainer::option().

Referenced by RootMinimizerAdapter::setOptionValue().

Here is the call graph for this function:

◆ begin() [1/2]

iterator OptionContainer::begin ( )
inlineinherited

Definition at line 50 of file OptionContainer.h.

50 { return m_options.begin(); }

References OptionContainer::m_options.

◆ begin() [2/2]

const_iterator OptionContainer::begin ( ) const
inlineinherited

Definition at line 51 of file OptionContainer.h.

51 { return m_options.begin(); }

References OptionContainer::m_options.

◆ end() [1/2]

iterator OptionContainer::end ( )
inlineinherited

Definition at line 53 of file OptionContainer.h.

53 { return m_options.end(); }

References OptionContainer::m_options.

◆ end() [2/2]

const_iterator OptionContainer::end ( ) const
inlineinherited

Definition at line 54 of file OptionContainer.h.

54 { return m_options.end(); }

References OptionContainer::m_options.

◆ size()

size_t OptionContainer::size ( ) const
inlineinherited

Definition at line 56 of file OptionContainer.h.

56 { return m_options.size(); }

References OptionContainer::m_options.

Referenced by OptionContainer::empty().

◆ empty()

bool OptionContainer::empty ( ) const
inlineinherited

Definition at line 57 of file OptionContainer.h.

57 { return size() == 0; }
size_t size() const

References OptionContainer::size().

Referenced by anonymous_namespace{MinimizerResultUtils.cpp}::reportOption().

Here is the call graph for this function:

◆ exists()

bool OptionContainer::exists ( const std::string &  name)
protectedinherited

Definition at line 56 of file OptionContainer.cpp.

57 {
58  for (const auto& option : m_options) {
59  if (option->name() == name)
60  return true;
61  }
62  return false;
63 }

References OptionContainer::m_options, and OptionContainer::option().

Referenced by OptionContainer::addOption().

Here is the call graph for this function:

◆ swapContent()

void OptionContainer::swapContent ( OptionContainer other)
protectedinherited

Definition at line 65 of file OptionContainer.cpp.

66 {
68 }
void swap(OutputDataIterator< TValue, TContainer > &left, OutputDataIterator< TValue, TContainer > &right)
make Swappable

References OptionContainer::m_options, and swap().

Referenced by OptionContainer::operator=().

Here is the call graph for this function:

Member Data Documentation

◆ m_options


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