BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
ComponentKeyHandler Class Reference

Stores IComponent instances, associates them with given tag, and provides unique keys. More...

Public Member Functions

void insertModel (const std::string &tag, const IComponent *s)
 
std::string obj2key (const IComponent *s) const
 
template<class T >
std::vector< const T * > objectsOfType () const
 

Private Attributes

std::map< std::string, std::vector< const IComponent * > > m_objects
 

Detailed Description

Stores IComponent instances, associates them with given tag, and provides unique keys.

Definition at line 32 of file ComponentKeyHandler.h.

Member Function Documentation

◆ insertModel()

void ComponentKeyHandler::insertModel ( const std::string &  tag,
const IComponent s 
)

Definition at line 20 of file ComponentKeyHandler.cpp.

21 {
22  m_objects[tag].emplace_back(s);
23 }
std::map< std::string, std::vector< const IComponent * > > m_objects

References m_objects.

◆ obj2key()

std::string ComponentKeyHandler::obj2key ( const IComponent s) const

Definition at line 25 of file ComponentKeyHandler.cpp.

26 {
27  for (auto it : m_objects) {
28  const std::vector<const IComponent*>& v = it.second;
29  const auto vpos = std::find(v.begin(), v.end(), s);
30  if (vpos == std::end(v))
31  continue;
32  const std::string& tag = it.first;
33  if (v.size() == 1)
34  return tag;
35  return tag + "_" + std::to_string(vpos - v.begin() + 1);
36  }
37  throw std::runtime_error("BUG: object not found in ComponentKeyHandler");
38 }

References m_objects.

◆ objectsOfType()

template<class T >
std::vector< const T * > ComponentKeyHandler::objectsOfType

Definition at line 43 of file ComponentKeyHandler.h.

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 }
Root of class hierarchy for sample and instrument model.
Definition: IComponent.h:21

References m_objects.

Member Data Documentation

◆ m_objects

std::map<std::string, std::vector<const IComponent*> > ComponentKeyHandler::m_objects
private

Definition at line 40 of file ComponentKeyHandler.h.

Referenced by insertModel(), obj2key(), and objectsOfType().


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