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

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

Public Member Functions

void insertMaterial (const Material *sample)
 
const std::string & mat2key (const Material *sample) const
 
const std::map< const std::string, const Material * > & materialMap () const
 

Private Attributes

std::map< const std::string, const Material * > m_Key2Mat
 
std::map< const Material *, const Material * > m_Mat2Unique
 

Detailed Description

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

Definition at line 32 of file MaterialKeyHandler.h.

Member Function Documentation

◆ insertMaterial()

void MaterialKeyHandler::insertMaterial ( const Material sample)

Definition at line 22 of file MaterialKeyHandler.cpp.

23 {
24  for (const auto& it : m_Mat2Unique)
25  if (*it.second == *mat) {
26  m_Mat2Unique.emplace(mat, it.second);
27  return;
28  }
29  m_Mat2Unique.emplace(mat, mat);
30 
31  const std::string key = "material_" + mat->getName();
32  if (m_Key2Mat.count(key))
33  throw std::runtime_error(
34  "Material name " + mat->getName()
35  + " used more than once, which is not supported by Python exporter");
36  m_Key2Mat.emplace(key, mat);
37 }
std::map< const Material *, const Material * > m_Mat2Unique
std::map< const std::string, const Material * > m_Key2Mat

References Material::getName(), m_Key2Mat, and m_Mat2Unique.

Here is the call graph for this function:

◆ mat2key()

const std::string & MaterialKeyHandler::mat2key ( const Material sample) const

Definition at line 39 of file MaterialKeyHandler.cpp.

40 {
41  const Material* unique_mat = m_Mat2Unique.at(mat);
42  for (const auto& it : m_Key2Mat)
43  if (it.second == unique_mat)
44  return it.first;
45  ASSERT(0);
46 }
#define ASSERT(condition)
Definition: Assert.h:31
A wrapper for underlying material implementation.
Definition: Material.h:29

References ASSERT, m_Key2Mat, and m_Mat2Unique.

◆ materialMap()

const std::map< const std::string, const Material * > & MaterialKeyHandler::materialMap ( ) const

Definition at line 48 of file MaterialKeyHandler.cpp.

49 {
50  return m_Key2Mat;
51 }

References m_Key2Mat.

Member Data Documentation

◆ m_Key2Mat

std::map<const std::string, const Material*> MaterialKeyHandler::m_Key2Mat
private

Definition at line 41 of file MaterialKeyHandler.h.

Referenced by insertMaterial(), mat2key(), and materialMap().

◆ m_Mat2Unique

std::map<const Material*, const Material*> MaterialKeyHandler::m_Mat2Unique
private

Definition at line 40 of file MaterialKeyHandler.h.

Referenced by insertMaterial(), and mat2key().


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