23 #include "openPMD/IO/AbstractIOHandler.hpp"
24 #include "openPMD/backend/Attribute.hpp"
25 #include "openPMD/backend/Writable.hpp"
26 #include "openPMD/auxiliary/OutOfRangeMsg.hpp"
34 #include <type_traits>
37 #ifndef OPENPMD_protected
38 # define OPENPMD_protected protected
46 template<
typename T >
61 : std::runtime_error(what_arg)
81 using A_MAP = std::map< std::string, Attribute >;
92 template<
typename T >
94 attr_value_check( std::string
const , T )
100 attr_value_check( std::string
const key, std::string
const value )
103 throw std::runtime_error(
104 "[setAttribute] Value for string attribute '" + key +
105 "' must not be empty!" );
118 using A_MAP = std::map< std::string, Attribute >;
120 template<
typename T_elem >
128 template<
typename T >
141 template<
typename T >
165 template<
typename T >
167 bool setAttribute(std::string
const& key,
char const value[]);
190 std::vector< std::string >
attributes()
const;
233 std::string directory;
274 void flushAttributes();
308 template<
typename T >
324 template<
typename T >
331 return m_attri->m_writable.IOHandler.get();
333 AbstractIOHandler
const * IOHandler()
const
335 return m_attri->m_writable.IOHandler.get();
339 return m_attri->m_writable.parent;
341 Writable
const * parent()
const
343 return m_attri->m_writable.parent;
345 Writable & writable()
347 return m_attri->m_writable;
349 Writable
const & writable()
const
351 return m_attri->m_writable;
355 internal::AttributableData & get()
363 throw std::runtime_error(
364 "[AttributableInterface] "
365 "Cannot use default-constructed Attributable." );
369 internal::AttributableData
const & get()
const
377 throw std::runtime_error(
378 "[AttributableInterface] "
379 "Cannot use default-constructed Attributable." );
383 bool dirty()
const {
return writable().dirty; }
384 bool& dirty() {
return writable().dirty; }
385 bool written()
const {
return writable().written; }
386 bool& written() {
return writable().written; }
394 virtual void linkHierarchy(Writable& w);
399 using Attributable = AttributableInterface;
404 std::shared_ptr< internal::AttributableData > m_attributableData =
405 std::make_shared< internal::AttributableData >();
410 AttributableInterface::m_attri = m_attributableData.get();
415 template<
typename T >
419 internal::attr_value_check( key, value );
421 auto & attri = get();
426 "can not be set (read-only)."
432 auto it = attri.m_attributes.lower_bound(key);
433 if( it != attri.m_attributes.end()
434 && !attri.m_attributes.key_comp()(key, it->first) )
442 attri.m_attributes.emplace_hint(
443 it, std::make_pair(key,
Attribute(std::move(value))));
454 template<
typename T >
457 static_assert(std::is_floating_point< T >::value,
"Type of attribute must be floating point");
462 template<
typename T >
463 inline std::vector< T >
466 static_assert(std::is_floating_point< T >::value,
"Type of attribute must be floating point");
@ READ_ONLY
open series as read-only, fails if series is not found
MyPath myPath() const
The path to this object within its containing Series.
Definition: Attributable.cpp:192
@ OverrideExisting
Read all the attributes that the backend has to offer and override if it has been read previously.
Definition: Attributable.hpp:285
Layer to mirror structure of logical data and persistent data in file.
Definition: Writable.hpp:64
@ FullyReread
Remove all attributes that have been read previously and read everything that the backend currently h...
Definition: Attributable.hpp:290
bool setAttribute(std::string const &key, T value)
Populate Attribute of provided name with provided value.
Definition: Attributable.hpp:417
Definition: Attributable.hpp:68
Definition: BaseRecord.hpp:36
Definition: Attributable.hpp:401
const Iteration & containingIteration() const
Returns the corresponding Iteration.
Definition: Attributable.cpp:138
bool deleteAttribute(std::string const &key)
Remove Attribute of provided value both logically and physically.
Definition: Attributable.cpp:58
String serialization to describe an Attributable.
Definition: Attributable.hpp:231
Definition: AbstractFilePosition.hpp:26
void seriesFlush()
Flush the corresponding Series object.
Definition: Attributable.cpp:116
Varidic datatype supporting at least all formats for attributes specified in the openPMD standard.
Definition: Attribute.hpp:50
Writing side of the streaming API.
Definition: WriteIterations.hpp:47
Definition: Series.hpp:443
Interface for communicating between logical and physically persistent data.
Definition: AbstractIOHandler.hpp:98
std::string seriesName
e.g., samples/git-samples/
Definition: Attributable.hpp:234
std::vector< std::string > attributes() const
List all currently stored Attributes' keys.
Definition: Attributable.cpp:78
Root level of the openPMD hierarchy.
Definition: Series.hpp:478
Return an error string for read-only access.
Definition: OutOfRangeMsg.hpp:37
bool containsAttribute(std::string const &key) const
Check whether am Attribute with a given key exists.
Definition: Attributable.cpp:96
Implementation for the root level of the openPMD hierarchy.
Definition: Series.hpp:112
Logical compilation of data from one snapshot (e.g.
Definition: Iteration.hpp:39
std::string comment() const
Retrieve a user-supplied comment associated with the object.
Definition: Attributable.cpp:103
std::vector< std::string > group
e.g., .bp, .h5, .json, ...
Definition: Attributable.hpp:243
Attribute getAttribute(std::string const &key) const
Retrieve value of Attribute stored with provided key.
Definition: Attributable.cpp:47
Public definitions of openPMD-api.
Definition: Date.cpp:29
std::string filePath() const
Reconstructs a path that can be passed to a Series constructor.
Definition: Attributable.cpp:187
T readFloatingpoint(std::string const &key) const
Retrieve the value of a floating point Attribute of user-defined precision with ensured type-safety.
Definition: Attributable.hpp:455
Map-like container that enforces openPMD requirements and handles IO.
Definition: Container.hpp:106
U get() const
Retrieve a stored specific Attribute and cast if convertible.
Definition: Attribute.hpp:332
Definition: Attributable.hpp:57
Layer to manage storage of attributes associated with file objects.
Definition: Attributable.hpp:115
Container Element Creation Policy.
Definition: Attributable.hpp:47
AttributableInterface & setComment(std::string const &comment)
Populate Attribute corresponding to a comment with the user-supplied comment.
Definition: Attributable.cpp:109
@ IgnoreExisting
Don't read an attribute from the backend if it has been previously read.
Definition: Attributable.hpp:280
ReadMode
Definition: Attributable.hpp:275
FlushLevel
Determine what items should be flushed upon Series::flush()
Definition: AbstractIOHandler.hpp:63
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 typ...
Definition: Attributable.hpp:464
std::string seriesExtension
e.g., dataT
Definition: Attributable.hpp:235
size_t numAttributes() const
Count all currently stored Attributes.
Definition: Attributable.cpp:90