ATLAS Offline Software
Classes | Public Member Functions | Private Attributes | List of all members
Trig::EmulContext Class Reference

#include <EmulContext.h>

Collaboration diagram for Trig::EmulContext:

Classes

class  HolderT
 
class  IHolder
 

Public Member Functions

 EmulContext ()=default
 
 EmulContext (const EmulContext &)=delete
 
EmulContextoperator= (const EmulContext &)=delete
 
 ~EmulContext ()=default
 
template<typename T >
void store (const std::string &name, std::unique_ptr< T > &&object)
 
template<typename T >
const T * get (const std::string &name) const
 

Private Attributes

std::unordered_map< std::string, std::unique_ptr< IHolder > > m_store
 

Detailed Description

Definition at line 16 of file EmulContext.h.

Constructor & Destructor Documentation

◆ EmulContext() [1/2]

Trig::EmulContext::EmulContext ( )
default

◆ EmulContext() [2/2]

Trig::EmulContext::EmulContext ( const EmulContext )
delete

◆ ~EmulContext()

Trig::EmulContext::~EmulContext ( )
default

Member Function Documentation

◆ get()

template<typename T >
const T * Trig::EmulContext::get ( const std::string &  name) const
inline

Definition at line 94 of file EmulContext.h.

95  {
96  auto itr = m_store.find(name);
97  if ( itr == m_store.end() )
98  throw std::invalid_argument("Object with name `" + name +
99  "` is not in memory. Cannot be retrieved: " + name);
100 
101  const IHolder *holder = (*itr).second.get();
102  if (typeid(T) != holder->type())
103  throw std::invalid_argument("Type mismatch for object '" + name + "'");
104 
105  return reinterpret_cast<const HolderT<T> *>(holder)->value();
106  }

◆ operator=()

EmulContext& Trig::EmulContext::operator= ( const EmulContext )
delete

◆ store()

template<typename T >
void Trig::EmulContext::store ( const std::string &  name,
std::unique_ptr< T > &&  object 
)
inline

Definition at line 77 of file EmulContext.h.

79  {
80  if (name.empty())
81  throw std::invalid_argument("Object can not have an empty name in order to be stored in memory");
82 
83  if (m_store.find(name) != m_store.end())
84  throw std::runtime_error("Object with name `" + name +
85  "` already stored in memory");
86 
87  using stored_object_t = std::unique_ptr<T>;
88  m_store.emplace( name,
89  std::make_unique< HolderT<T> >( std::forward<stored_object_t>( object ) )
90  );
91  }

Member Data Documentation

◆ m_store

std::unordered_map<std::string, std::unique_ptr<IHolder> > Trig::EmulContext::m_store
private

Definition at line 54 of file EmulContext.h.


The documentation for this class was generated from the following file:
make_unique
std::unique_ptr< T > make_unique(Args &&... args)
Definition: SkimmingToolEXOT5.cxx:23
athena.value
value
Definition: athena.py:122
Trig::EmulContext::m_store
std::unordered_map< std::string, std::unique_ptr< IHolder > > m_store
Definition: EmulContext.h:54
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192