BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
ComponentKeyHandler.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Sim/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_SIM_EXPORT_COMPONENTKEYHANDLER_H
21 #define BORNAGAIN_SIM_EXPORT_COMPONENTKEYHANDLER_H
22 
23 #include <map>
24 #include <string>
25 #include <vector>
26 
27 class INode;
28 
29 //! Stores INode instances, associates them with given tag, and provides unique keys.
30 
32 public:
33  void insertModel(const std::string& tag, const INode* s);
34 
35  template <class T>
36  std::vector<const T*> objectsOfType() const;
37  std::string obj2key(const INode* s) const;
38 
39 private:
40  std::map<std::string, std::vector<const INode*>> m_objects;
41 };
42 
43 template <class T>
44 std::vector<const T*> ComponentKeyHandler::objectsOfType() const
45 {
46  std::vector<const T*> result;
47  for (const auto& it : m_objects)
48  for (const INode* s : it.second)
49  if (const auto* c = dynamic_cast<const T*>(s); c)
50  result.emplace_back(c);
51  return result;
52 }
53 
54 #endif // BORNAGAIN_SIM_EXPORT_COMPONENTKEYHANDLER_H
55 #endif // USER_API
Stores INode instances, associates them with given tag, and provides unique keys.
std::vector< const T * > objectsOfType() const
std::string obj2key(const INode *s) const
std::map< std::string, std::vector< const INode * > > m_objects
void insertModel(const std::string &tag, const INode *s)
Base class for tree-like structures containing parameterized objects.
Definition: INode.h:40