BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
ModelView::ItemCatalogue Class Reference

Catalogue for item constructions. More...

Classes

struct  ItemCatalogueImpl
 

Public Member Functions

 ItemCatalogue ()
 
 ItemCatalogue (const ItemCatalogue &other)
 
 ~ItemCatalogue ()
 
bool contains (const std::string &modelType) const
 
std::unique_ptr< SessionItemcreate (const std::string &modelType) const
 
int itemCount () const
 
std::vector< std::string > labels () const
 
void merge (const ItemCatalogue &other)
 Adds content of other catalogue to this. More...
 
std::vector< std::string > modelTypes () const
 
ItemCatalogueoperator= (const ItemCatalogue &other)
 
template<typename T >
void registerItem (const std::string &label={})
 
void registerItem (const std::string &modelType, item_factory_func_t func, const std::string &label)
 

Private Attributes

std::unique_ptr< ItemCatalogueImplp_impl
 

Detailed Description

Catalogue for item constructions.

Contains collection of factory functions associated with item's modelType and optional label.

Definition at line 30 of file itemcatalogue.h.

Constructor & Destructor Documentation

◆ ItemCatalogue() [1/2]

ItemCatalogue::ItemCatalogue ( )

Definition at line 32 of file itemcatalogue.cpp.

32 : p_impl(std::make_unique<ItemCatalogueImpl>()) {}
std::unique_ptr< ItemCatalogueImpl > p_impl
Definition: itemcatalogue.h:56

◆ ~ItemCatalogue()

ItemCatalogue::~ItemCatalogue ( )
default

◆ ItemCatalogue() [2/2]

ItemCatalogue::ItemCatalogue ( const ItemCatalogue other)

Definition at line 34 of file itemcatalogue.cpp.

35 {
36  p_impl = std::make_unique<ItemCatalogueImpl>(*other.p_impl);
37 }

References p_impl.

Member Function Documentation

◆ contains()

bool ItemCatalogue::contains ( const std::string &  modelType) const

Definition at line 57 of file itemcatalogue.cpp.

58 {
59  return p_impl->factory.contains(modelType);
60 }

References p_impl.

Referenced by merge(), and TEST_F().

◆ create()

std::unique_ptr< SessionItem > ItemCatalogue::create ( const std::string &  modelType) const

Definition at line 62 of file itemcatalogue.cpp.

63 {
64  return p_impl->factory.create(modelType);
65 }

References p_impl.

Referenced by TEST_F().

◆ itemCount()

int ItemCatalogue::itemCount ( ) const

Definition at line 83 of file itemcatalogue.cpp.

84 {
85  return static_cast<int>(p_impl->factory.size());
86 }

References p_impl.

Referenced by TEST_F().

◆ labels()

std::vector< std::string > ItemCatalogue::labels ( ) const

Definition at line 75 of file itemcatalogue.cpp.

76 {
77  std::vector<std::string> result;
78  for (const auto& x : p_impl->m_info)
79  result.push_back(x.item_label);
80  return result;
81 }

References p_impl.

Referenced by TEST_F().

◆ merge()

void ItemCatalogue::merge ( const ItemCatalogue other)

Adds content of other catalogue to this.

Definition at line 90 of file itemcatalogue.cpp.

91 {
92  size_t index(0);
93  for (auto it : other.p_impl->factory) {
94  if (contains(it.first))
95  throw std::runtime_error(
96  "ItemCatalogue::add() -> Catalogue contains duplicated records");
97 
98  registerItem(it.first, it.second, other.p_impl->m_info[index].item_label);
99  ++index;
100  }
101 }
void registerItem(const std::string &label={})
Definition: itemcatalogue.h:60
bool contains(const std::string &modelType) const

References contains(), p_impl, and registerItem().

Referenced by TEST_F().

Here is the call graph for this function:

◆ modelTypes()

std::vector< std::string > ItemCatalogue::modelTypes ( ) const

Definition at line 67 of file itemcatalogue.cpp.

68 {
69  std::vector<std::string> result;
70  for (const auto& x : p_impl->m_info)
71  result.push_back(x.item_type);
72  return result;
73 }

References p_impl.

Referenced by TEST_F().

◆ operator=()

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

Definition at line 39 of file itemcatalogue.cpp.

40 {
41  if (this != &other) {
42  ItemCatalogue tmp(other);
43  std::swap(this->p_impl, tmp.p_impl);
44  }
45  return *this;
46 }
void swap(OutputDataIterator< TValue, TContainer > &left, OutputDataIterator< TValue, TContainer > &right)
make Swappable
Catalogue for item constructions.
Definition: itemcatalogue.h:30

References p_impl, and swap().

Here is the call graph for this function:

◆ registerItem() [1/2]

template<typename T >
void ModelView::ItemCatalogue::registerItem ( const std::string &  label = {})

Definition at line 60 of file itemcatalogue.h.

61 {
62  registerItem(T().modelType(), ItemFactoryFunction<T>(), label);
63 }

Referenced by merge(), and TEST_F().

◆ registerItem() [2/2]

void ItemCatalogue::registerItem ( const std::string &  modelType,
item_factory_func_t  func,
const std::string &  label 
)

Definition at line 48 of file itemcatalogue.cpp.

50 {
51  p_impl->factory.add(modelType, func);
52  p_impl->m_info.push_back({modelType, label});
53 }

References p_impl.

Member Data Documentation

◆ p_impl

std::unique_ptr<ItemCatalogueImpl> ModelView::ItemCatalogue::p_impl
private

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