ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
ScriptInterface::ObjectMap< ManagedType, BaseType, KeyType > Class Template Referenceabstract

Owning map of object handles. More...

#include <ObjectMap.hpp>

+ Inheritance diagram for ScriptInterface::ObjectMap< ManagedType, BaseType, KeyType >:
+ Collaboration diagram for ScriptInterface::ObjectMap< ManagedType, BaseType, KeyType >:

Public Types

using Base = ObjectContainer< ObjectMap, ManagedType, BaseType >
 
using key_type = KeyType
 
using mapped_type = std::shared_ptr< ManagedType >
 
using container_type = std::unordered_map< key_type, mapped_type >
 

Public Member Functions

 ObjectMap ()
 
 ~ObjectMap () override
 
void do_construct (VariantMap const &params) override=0
 
void insert (key_type const &key, mapped_type const &element)
 Add an element to the map.
 
key_type insert (mapped_type const &element)
 Add an element to the map.
 
void erase (key_type const &key)
 Removes all occurrences of an element from the map.
 
auto constelements () const
 Map elements.
 
void clear ()
 Clear the map.
 

Protected Member Functions

void do_destruct ()
 
Variant do_call_method (std::string const &method, VariantMap const &parameters) override
 
void restore_from_checkpoint (VariantMap const &params)
 
key_type get_key (Variant const &key) const
 

Private Member Functions

virtual key_type insert_in_core (mapped_type const &obj_ptr)=0
 
virtual void insert_in_core (key_type const &key, mapped_type const &obj_ptr)=0
 
virtual void erase_in_core (key_type const &key)=0
 

Detailed Description

template<typename ManagedType, class BaseType = ObjectHandle, class KeyType = int>
class ScriptInterface::ObjectMap< ManagedType, BaseType, KeyType >

Owning map of object handles.

Mapped elements are cleared from the core during destruction. Due to how dynamic dispatch works, derived types must mark erase_in_core as final` and call do_destruct in their virtual destructor. This is to ensure that pure virtual functions called by clear cannot be executed in a type derived from the type currently being destructed, since derived types no longer exist at this point of the destruction sequence.

Template Parameters
ManagedTypeType of the managed objects, needs to be derived from ObjectHandle

Definition at line 52 of file ObjectMap.hpp.

Member Typedef Documentation

◆ Base

◆ container_type

template<typename ManagedType , class BaseType = ObjectHandle, class KeyType = int>
using ScriptInterface::ObjectMap< ManagedType, BaseType, KeyType >::container_type = std::unordered_map<key_type, mapped_type>

Definition at line 58 of file ObjectMap.hpp.

◆ key_type

Definition at line 56 of file ObjectMap.hpp.

◆ mapped_type

template<typename ManagedType , class BaseType = ObjectHandle, class KeyType = int>
using ScriptInterface::ObjectMap< ManagedType, BaseType, KeyType >::mapped_type = std::shared_ptr<ManagedType>

Definition at line 57 of file ObjectMap.hpp.

Constructor & Destructor Documentation

◆ ObjectMap()

◆ ~ObjectMap()

template<typename ManagedType , class BaseType = ObjectHandle, class KeyType = int>
ScriptInterface::ObjectMap< ManagedType, BaseType, KeyType >::~ObjectMap ( )
inlineoverride

Definition at line 84 of file ObjectMap.hpp.

References ScriptInterface::get_value().

Member Function Documentation

◆ clear()

◆ do_call_method()

◆ do_construct()

◆ do_destruct()

◆ elements()

template<typename ManagedType , class BaseType = ObjectHandle, class KeyType = int>
auto const & ScriptInterface::ObjectMap< ManagedType, BaseType, KeyType >::elements ( ) const
inline

Map elements.

Definition at line 125 of file ObjectMap.hpp.

Referenced by ScriptInterface::Interactions::BondedInteractions::do_call_method().

◆ erase()

template<typename ManagedType , class BaseType = ObjectHandle, class KeyType = int>
void ScriptInterface::ObjectMap< ManagedType, BaseType, KeyType >::erase ( key_type const key)
inline

Removes all occurrences of an element from the map.

Parameters
keyIdentifier of the element to remove.

Definition at line 117 of file ObjectMap.hpp.

References ScriptInterface::ObjectMap< ManagedType, BaseType, KeyType >::erase_in_core(), and ScriptInterface::get_value().

Referenced by ScriptInterface::ObjectMap< ManagedType, BaseType, KeyType >::do_call_method().

◆ erase_in_core()

◆ get_key()

◆ insert() [1/2]

template<typename ManagedType , class BaseType = ObjectHandle, class KeyType = int>
void ScriptInterface::ObjectMap< ManagedType, BaseType, KeyType >::insert ( key_type const key,
mapped_type const element 
)
inline

Add an element to the map.

Parameters
keyIdentifier of the element to add.
elementThe element to add.

Definition at line 95 of file ObjectMap.hpp.

References ScriptInterface::get_value(), and ScriptInterface::ObjectMap< ManagedType, BaseType, KeyType >::insert_in_core().

Referenced by ScriptInterface::ObjectMap< ManagedType, BaseType, KeyType >::do_call_method().

◆ insert() [2/2]

template<typename ManagedType , class BaseType = ObjectHandle, class KeyType = int>
key_type ScriptInterface::ObjectMap< ManagedType, BaseType, KeyType >::insert ( mapped_type const element)
inline

Add an element to the map.

A free key is generated automatically.

Parameters
elementThe element to add.

Definition at line 106 of file ObjectMap.hpp.

References ScriptInterface::get_value(), and ScriptInterface::ObjectMap< ManagedType, BaseType, KeyType >::insert_in_core().

◆ insert_in_core() [1/2]

◆ insert_in_core() [2/2]

◆ restore_from_checkpoint()


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