BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
OptionContainer.cpp
Go to the documentation of this file.
1 // ************************************************************************** //
2 //
3 // BornAgain: simulate and fit scattering at grazing incidence
4 //
5 //! @file Fit/Tools/OptionContainer.cpp
6 //! @brief Implements class OptionContainer.
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************** //
14 
16 #include <sstream>
17 
18 //! Returns true if option with such name already exists.
20 {
21  for (const auto& option : other.m_options)
22  m_options.push_back(option_t(new MultiOption(*option)));
23 }
24 
26 {
27  if (this != &other) {
28  OptionContainer tmp(other);
29  tmp.swapContent(*this);
30  }
31  return *this;
32 }
33 
34 OptionContainer::option_t OptionContainer::option(const std::string& optionName)
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 }
44 
45 const OptionContainer::option_t OptionContainer::option(const std::string& optionName) const
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 }
55 
56 bool OptionContainer::exists(const std::string& name)
57 {
58  for (const auto& option : m_options) {
59  if (option->name() == name)
60  return true;
61  }
62  return false;
63 }
64 
66 {
68 }
Declares class OptionContainer.
void swap(OutputDataIterator< TValue, TContainer > &left, OutputDataIterator< TValue, TContainer > &right)
make Swappable
Stores a single option for minimization algorithm.
Definition: MultiOption.h:26
Stores multi option (int,double,string) in a container.
std::shared_ptr< MultiOption > option_t
OptionContainer & operator=(const OptionContainer &other)
container_t m_options
option_t option(const std::string &optionName)
void swapContent(OptionContainer &other)
bool exists(const std::string &name)