openPMD-api
Classes | Public Types | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Friends | List of all members
openPMD::Container< T, T_key, T_container > Class Template Reference

Map-like container that enforces openPMD requirements and handles IO. More...

#include <Container.hpp>

Inheritance diagram for openPMD::Container< T, T_key, T_container >:
Inheritance graph
[legend]
Collaboration diagram for openPMD::Container< T, T_key, T_container >:
Collaboration graph
[legend]

Classes

class  EraseStaleEntries
 This class wraps a Container and forwards operator[]() and at() to it. More...
 

Public Types

using key_type = typename InternalContainer::key_type
 
using mapped_type = typename InternalContainer::mapped_type
 
using value_type = typename InternalContainer::value_type
 
using size_type = typename InternalContainer::size_type
 
using difference_type = typename InternalContainer::difference_type
 
using allocator_type = typename InternalContainer::allocator_type
 
using reference = typename InternalContainer::reference
 
using const_reference = typename InternalContainer::const_reference
 
using pointer = typename InternalContainer::pointer
 
using const_pointer = typename InternalContainer::const_pointer
 
using iterator = typename InternalContainer::iterator
 
using const_iterator = typename InternalContainer::const_iterator
 

Public Member Functions

 Container (Container const &)=default
 
iterator begin () noexcept
 
const_iterator begin () const noexcept
 
const_iterator cbegin () const noexcept
 
iterator end () noexcept
 
const_iterator end () const noexcept
 
const_iterator cend () const noexcept
 
bool empty () const noexcept
 
size_type size () const noexcept
 
void clear ()
 Remove all objects from the container and (if written) from disk. More...
 
std::pair< iterator, bool > insert (value_type const &value)
 
template<class P >
std::pair< iterator, bool > insert (P &&value)
 
iterator insert (const_iterator hint, value_type const &value)
 
template<class P >
iterator insert (const_iterator hint, P &&value)
 
template<class InputIt >
void insert (InputIt first, InputIt last)
 
void insert (std::initializer_list< value_type > ilist)
 
void swap (Container &other)
 
mapped_type & at (key_type const &key)
 
mapped_type const & at (key_type const &key) const
 
virtual mapped_type & operator[] (key_type const &key)
 Access the value that is mapped to a key equivalent to key, creating it if such key does not exist already. More...
 
virtual mapped_type & operator[] (key_type &&key)
 Access the value that is mapped to a key equivalent to key, creating it if such key does not exist already. More...
 
iterator find (key_type const &key)
 
const_iterator find (key_type const &key) const
 
size_type count (key_type const &key) const
 This returns either 1 if the key is found in the container of 0 if not. More...
 
bool contains (key_type const &key) const
 Checks if there is an element with a key equivalent to an exiting key in the container. More...
 
virtual size_type erase (key_type const &key)
 Remove a single element from the container and (if written) from disk. More...
 
virtual iterator erase (iterator res)
 
template<class... Args>
auto emplace (Args &&... args) -> decltype(InternalContainer().emplace(std::forward< Args >(args)...))
 
- Public Member Functions inherited from openPMD::AttributableInterface
Attribute getAttribute (std::string const &key) const
 Retrieve value of Attribute stored with provided key. More...
 
bool deleteAttribute (std::string const &key)
 Remove Attribute of provided value both logically and physically. More...
 
std::vector< std::string > attributes () const
 List all currently stored Attributes' keys. More...
 
size_t numAttributes () const
 Count all currently stored Attributes. More...
 
bool containsAttribute (std::string const &key) const
 Check whether am Attribute with a given key exists. More...
 
std::string comment () const
 Retrieve a user-supplied comment associated with the object. More...
 
AttributableInterfacesetComment (std::string const &comment)
 Populate Attribute corresponding to a comment with the user-supplied comment. More...
 
void seriesFlush ()
 Flush the corresponding Series object. More...
 
MyPath myPath () const
 The path to this object within its containing Series. More...
 
template<typename T >
bool setAttribute (std::string const &key, T value)
 Populate Attribute of provided name with provided value. More...
 
bool setAttribute (std::string const &key, char const value[])
 

Protected Types

using InternalContainer = T_container
 
- Protected Types inherited from openPMD::AttributableInterface
enum  ReadMode { IgnoreExisting, OverrideExisting, FullyReread }
 

Protected Member Functions

void clear_unchecked ()
 
virtual void flush (std::string const &path)
 
EraseStaleEntries eraseStaleEntries ()
 
- Protected Member Functions inherited from openPMD::AttributableInterface
 AttributableInterface (internal::AttributableData *)
 
template<typename T >
 AttributableInterface (T *attri)
 
const internal::SeriesInternalretrieveSeries () const
 
internal::SeriesInternalretrieveSeries ()
 
void seriesFlush (FlushLevel)
 
void flushAttributes ()
 
void readAttributes (ReadMode)
 
template<typename T >
readFloatingpoint (std::string const &key) const
 Retrieve the value of a floating point Attribute of user-defined precision with ensured type-safety. More...
 
template<typename T >
std::vector< T > readVectorFloatingpoint (std::string const &key) const
 Retrieve a vector of values of a floating point Attributes of user-defined precision with ensured type-safety. More...
 
AbstractIOHandlerIOHandler ()
 
const AbstractIOHandlerIOHandler () const
 
Writable *& parent ()
 
const Writableparent () const
 
Writablewritable ()
 
const Writablewritable () const
 
internal::AttributableDataget ()
 
const internal::AttributableDataget () const
 
bool dirty () const
 
bool & dirty ()
 
bool written () const
 
bool & written ()
 
const IterationcontainingIteration () const
 Returns the corresponding Iteration. More...
 
IterationcontainingIteration ()
 

Protected Attributes

std::shared_ptr< InternalContainer > m_container
 
- Protected Attributes inherited from openPMD::LegacyAttributable
std::shared_ptr< internal::AttributableDatam_attributableData
 
- Protected Attributes inherited from openPMD::AttributableInterface
internal::AttributableDatam_attri = nullptr
 

Friends

class Iteration
 
class ParticleSpecies
 
class internal::SeriesData
 
class SeriesInterface
 
class Series
 

Detailed Description

template<typename T, typename T_key = std::string, typename T_container = std::map< T_key, T >>
class openPMD::Container< T, T_key, T_container >

Map-like container that enforces openPMD requirements and handles IO.

See also
http://en.cppreference.com/w/cpp/container/map
Template Parameters
TType of objects stored
T_keyKey type to look elements up by
T_containerType of container used for internal storage (must supply the same type traits and interface as std::map)

Member Function Documentation

◆ clear()

template<typename T , typename T_key = std::string, typename T_container = std::map< T_key, T >>
void openPMD::Container< T, T_key, T_container >::clear ( )
inline

Remove all objects from the container and (if written) from disk.

Note
Calling this operation on any container in a Series with Access::READ_ONLY will throw an exception.
Exceptions
std::runtime_error

◆ contains()

template<typename T , typename T_key = std::string, typename T_container = std::map< T_key, T >>
bool openPMD::Container< T, T_key, T_container >::contains ( key_type const &  key) const
inline

Checks if there is an element with a key equivalent to an exiting key in the container.

Parameters
keykey value of the element to search for
Returns
true of key is found, else false

◆ count()

template<typename T , typename T_key = std::string, typename T_container = std::map< T_key, T >>
size_type openPMD::Container< T, T_key, T_container >::count ( key_type const &  key) const
inline

This returns either 1 if the key is found in the container of 0 if not.

Parameters
keykey value of the element to count
Returns
since keys are unique in this container, returns 0 or 1

◆ emplace()

template<typename T , typename T_key = std::string, typename T_container = std::map< T_key, T >>
template<class... Args>
auto openPMD::Container< T, T_key, T_container >::emplace ( Args &&...  args) -> decltype(InternalContainer().emplace(std::forward<Args>(args)...))
inline
Todo:
add also:

◆ erase() [1/2]

template<typename T , typename T_key = std::string, typename T_container = std::map< T_key, T >>
virtual iterator openPMD::Container< T, T_key, T_container >::erase ( iterator  res)
inlinevirtual
Todo:
why does const_iterator not work compile with pybind11?

◆ erase() [2/2]

template<typename T , typename T_key = std::string, typename T_container = std::map< T_key, T >>
virtual size_type openPMD::Container< T, T_key, T_container >::erase ( key_type const &  key)
inlinevirtual

Remove a single element from the container and (if written) from disk.

Note
Calling this operation on any container in a Series with Access::READ_ONLY will throw an exception.
Exceptions
std::runtime_error
Parameters
keyKey of the element to remove.
Returns
Number of elements removed (either 0 or 1).

◆ operator[]() [1/2]

template<typename T , typename T_key = std::string, typename T_container = std::map< T_key, T >>
virtual mapped_type& openPMD::Container< T, T_key, T_container >::operator[] ( key_type &&  key)
inlinevirtual

Access the value that is mapped to a key equivalent to key, creating it if such key does not exist already.

Parameters
keyKey of the element to find (rvalue).
Returns
Reference to the mapped value of the new element if no element with key key existed. Otherwise a reference to the mapped value of the existing element whose key is equivalent to key.
Exceptions
std::out_of_rangeerror if in READ_ONLY mode and key does not exist, otherwise key will be created

◆ operator[]() [2/2]

template<typename T , typename T_key = std::string, typename T_container = std::map< T_key, T >>
virtual mapped_type& openPMD::Container< T, T_key, T_container >::operator[] ( key_type const &  key)
inlinevirtual

Access the value that is mapped to a key equivalent to key, creating it if such key does not exist already.

Parameters
keyKey of the element to find (lvalue).
Returns
Reference to the mapped value of the new element if no element with key key existed. Otherwise a reference to the mapped value of the existing element whose key is equivalent to key.
Exceptions
std::out_of_rangeerror if in READ_ONLY mode and key does not exist, otherwise key will be created

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