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

Stores multi option (int,double,string) in a container. More...

Inheritance diagram for OptionContainer:
[legend]

Public Types

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

Public Member Functions

 OptionContainer ()
 
 OptionContainer (const OptionContainer &other)
 Returns true if option with such name already exists. More...
 
template<class T >
option_t addOption (const std::string &optionName, T value, const std::string &description="")
 
iterator begin ()
 
const_iterator begin () const
 
bool empty () const
 
iterator end ()
 
const_iterator end () const
 
OptionContaineroperator= (const OptionContainer &other)
 
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)
 Sets the value of option. Option should hold same value type already. More...
 
size_t size () const
 

Protected Member Functions

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

Protected Attributes

container_t m_options
 

Detailed Description

Stores multi option (int,double,string) in a container.

Definition at line 32 of file OptionContainer.h.

Member Typedef Documentation

◆ const_iterator

using OptionContainer::const_iterator = container_t::const_iterator

Definition at line 37 of file OptionContainer.h.

◆ container_t

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

Definition at line 35 of file OptionContainer.h.

◆ iterator

using OptionContainer::iterator = container_t::iterator

Definition at line 36 of file OptionContainer.h.

◆ option_t

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

Definition at line 34 of file OptionContainer.h.

Constructor & Destructor Documentation

◆ OptionContainer() [1/2]

OptionContainer::OptionContainer ( )
inline

Definition at line 39 of file OptionContainer.h.

39 {}

◆ OptionContainer() [2/2]

OptionContainer::OptionContainer ( const OptionContainer other)

Returns true if option with such name already exists.

Definition at line 19 of file OptionContainer.cpp.

20 {
21  for (const auto& option : other.m_options)
22  m_options.push_back(option_t(new MultiOption(*option)));
23 }
Stores a single option for minimization algorithm.
Definition: MultiOption.h:30
std::shared_ptr< MultiOption > option_t
container_t m_options
option_t option(const std::string &optionName)

References m_options, and option().

Here is the call graph for this function:

Member Function Documentation

◆ addOption()

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

Definition at line 70 of file OptionContainer.h.

72 {
73  if (exists(optionName))
74  throw std::runtime_error("OptionContainer::addOption() -> Error. Option '" + optionName
75  + "' exists.");
76 
77  option_t result(new MultiOption(optionName, value, description));
78  m_options.push_back(result);
79  return result;
80 }
bool exists(const std::string &name)

References exists(), and m_options.

Referenced by MinimizerAdapter::addOption().

Here is the call graph for this function:

◆ begin() [1/2]

iterator OptionContainer::begin ( )
inline

Definition at line 54 of file OptionContainer.h.

54 { return m_options.begin(); }

References m_options.

◆ begin() [2/2]

const_iterator OptionContainer::begin ( ) const
inline

Definition at line 55 of file OptionContainer.h.

55 { return m_options.begin(); }

References m_options.

◆ empty()

bool OptionContainer::empty ( ) const
inline

Definition at line 61 of file OptionContainer.h.

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

References size().

Here is the call graph for this function:

◆ end() [1/2]

iterator OptionContainer::end ( )
inline

Definition at line 57 of file OptionContainer.h.

57 { return m_options.end(); }

References m_options.

◆ end() [2/2]

const_iterator OptionContainer::end ( ) const
inline

Definition at line 58 of file OptionContainer.h.

58 { return m_options.end(); }

References m_options.

◆ exists()

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

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 }
QString const & name(EShape k)
Definition: particles.cpp:21

References m_options, RealSpace::Particles::name(), and option().

Referenced by addOption().

Here is the call graph for this function:

◆ operator=()

OptionContainer & OptionContainer::operator= ( const OptionContainer other)

Definition at line 25 of file OptionContainer.cpp.

26 {
27  if (this != &other) {
28  OptionContainer tmp(other);
29  tmp.swapContent(*this);
30  }
31  return *this;
32 }
Stores multi option (int,double,string) in a container.

References swapContent().

Here is the call graph for this function:

◆ option() [1/2]

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

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 m_options.

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

◆ option() [2/2]

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

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 m_options, and option().

Here is the call graph for this function:

◆ optionValue()

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

Definition at line 82 of file OptionContainer.h.

83 {
84  return option(optionName)->get<T>();
85 }

References option().

Referenced by MinimizerAdapter::optionValue().

Here is the call graph for this function:

◆ setOptionValue()

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

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

Definition at line 87 of file OptionContainer.h.

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

References option().

Referenced by MinimizerAdapter::setOptionValue().

Here is the call graph for this function:

◆ size()

size_t OptionContainer::size ( ) const
inline

Definition at line 60 of file OptionContainer.h.

60 { return m_options.size(); }

References m_options.

Referenced by empty().

◆ swapContent()

void OptionContainer::swapContent ( OptionContainer other)
protected

Definition at line 65 of file OptionContainer.cpp.

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

References m_options, and swap().

Referenced by operator=().

Here is the call graph for this function:

Member Data Documentation

◆ m_options

container_t OptionContainer::m_options
protected

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