BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
ComponentKeyHandler.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Core/Export/ComponentKeyHandler.h
6 //! @brief Defines class ComponentKeyHandler.
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 
15 #ifdef SWIG
16 #error no need to expose this header to Swig
17 #endif
18 
19 #ifndef USER_API
20 #ifndef BORNAGAIN_CORE_EXPORT_COMPONENTKEYHANDLER_H
21 #define BORNAGAIN_CORE_EXPORT_COMPONENTKEYHANDLER_H
22 
23 #include <map>
24 #include <string>
25 #include <vector>
26 
27 class IComponent;
28 
29 //! Stores IComponent instances, associates them with given tag, and provides unique keys.
30 //! @ingroup tools_internal
31 
33 public:
34  void insertModel(const std::string& tag, const IComponent* s);
35 
36  template <class T> std::vector<const T*> objectsOfType() const;
37  std::string obj2key(const IComponent* s) const;
38 
39 private:
40  std::map<std::string, std::vector<const IComponent*>> m_objects;
41 };
42 
43 template <class T> std::vector<const T*> ComponentKeyHandler::objectsOfType() const
44 {
45  std::vector<const T*> ret;
46  for (auto it : m_objects)
47  for (const IComponent* s : it.second)
48  if (const auto* c = dynamic_cast<const T*>(s); c)
49  ret.emplace_back(c);
50  return ret;
51 }
52 
53 #endif // BORNAGAIN_CORE_EXPORT_COMPONENTKEYHANDLER_H
54 #endif // USER_API
Stores IComponent instances, associates them with given tag, and provides unique keys.
std::vector< const T * > objectsOfType() const
std::map< std::string, std::vector< const IComponent * > > m_objects
void insertModel(const std::string &tag, const IComponent *s)
std::string obj2key(const IComponent *s) const
Root of class hierarchy for sample and instrument model.
Definition: IComponent.h:21