BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
itemcatalogue.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // qt-mvvm: Model-view-view-model framework for large GUI applications
4 //
5 //! @file mvvm/model/mvvm/model/itemcatalogue.h
6 //! @brief Defines class CLASS?
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2020
11 //! @authors Gennady Pospelov et al, Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
15 #ifndef BORNAGAIN_MVVM_MODEL_MVVM_MODEL_ITEMCATALOGUE_H
16 #define BORNAGAIN_MVVM_MODEL_MVVM_MODEL_ITEMCATALOGUE_H
17 
19 #include "mvvm/model_export.h"
20 #include <string>
21 #include <vector>
22 
23 namespace ModelView {
24 
25 class SessionItem;
26 
27 //! Catalogue for item constructions. Contains collection of factory functions associated with
28 //! item's modelType and optional label.
29 
30 class MVVM_MODEL_EXPORT ItemCatalogue {
31 public:
32  ItemCatalogue();
34 
35  ItemCatalogue(const ItemCatalogue& other);
36  ItemCatalogue& operator=(const ItemCatalogue& other);
37 
38  template <typename T> void registerItem(const std::string& label = {});
39 
40  void registerItem(const std::string& modelType, item_factory_func_t func,
41  const std::string& label);
42 
43  bool contains(const std::string& modelType) const;
44 
45  std::unique_ptr<SessionItem> create(const std::string& modelType) const;
46 
47  std::vector<std::string> modelTypes() const;
48 
49  std::vector<std::string> labels() const;
50 
51  int itemCount() const;
52 
53  void merge(const ItemCatalogue& other);
54 
55 private:
56  struct ItemCatalogueImpl;
57  std::unique_ptr<ItemCatalogueImpl> p_impl;
58 };
59 
60 template <typename T> void ItemCatalogue::registerItem(const std::string& label)
61 {
62  registerItem(T().modelType(), ItemFactoryFunction<T>(), label);
63 }
64 
65 } // namespace ModelView
66 
67 #endif // BORNAGAIN_MVVM_MODEL_MVVM_MODEL_ITEMCATALOGUE_H
Catalogue for item constructions.
Definition: itemcatalogue.h:30
void registerItem(const std::string &label={})
Definition: itemcatalogue.h:60
std::unique_ptr< ItemCatalogueImpl > p_impl
Definition: itemcatalogue.h:56
Defines class CLASS?
materialitems.h Collection of materials to populate MaterialModel.
std::function< std::unique_ptr< SessionItem >()> item_factory_func_t
Definition for item factory funciton.