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 >
166 bool setAttribute(std::string
const& key,
T value);
167 bool setAttribute(std::string
const& key,
char const value[]);
177 Attribute getAttribute(std::string
const& key)
const;
184 bool deleteAttribute(std::string
const& key);
190 std::vector< std::string > attributes()
const;
195 size_t numAttributes()
const;
201 bool containsAttribute(std::string
const& key)
const;
208 std::string comment()
const;
233 std::string directory;
234 std::string seriesName;
235 std::string seriesExtension;
243 std::vector< std::string > group;
246 std::string filePath()
const;
268 Iteration const & containingIteration()
const;
274 void flushAttributes();
308 template<
typename T >
309 T readFloatingpoint(std::string
const& key)
const;
324 template<
typename T >
325 std::vector< T > readVectorFloatingpoint(std::string
const& key)
const;
331 return m_attri->m_writable.IOHandler.get();
335 return m_attri->m_writable.IOHandler.get();
339 return m_attri->m_writable.parent;
343 return m_attri->m_writable.parent;
347 return m_attri->m_writable;
351 return m_attri->m_writable;
363 throw std::runtime_error(
364 "[AttributableInterface] " 365 "Cannot use default-constructed Attributable." );
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);
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))));
451 return this->setAttribute(key, std::string(value));
454 template<
typename T >
457 static_assert(std::is_floating_point< T >::value,
"Type of attribute must be floating point");
459 return getAttribute(key).
get<
T >();
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");
468 return getAttribute(key).
get< std::vector< T > >();
Return an error string for read-only access.
Definition: OutOfRangeMsg.hpp:37
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
Definition: Attributable.hpp:57
U get() const
Retrieve a stored specific Attribute and cast if convertible.
Definition: Attribute.hpp:332
Definition: Series.hpp:441
Container Element Creation Policy.
Definition: Attributable.hpp:47
Logical compilation of data from one snapshot (e.g.
Definition: Iteration.hpp:39
FlushLevel
Determine what items should be flushed upon Series::flush()
Definition: AbstractIOHandler.hpp:63
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
Writing side of the streaming API.
Definition: WriteIterations.hpp:47
Root level of the openPMD hierarchy.
Definition: Series.hpp:476
Varidic datatype supporting at least all formats for attributes specified in the openPMD standard...
Definition: Attribute.hpp:50
Interface for communicating between logical and physically persistent data.
Definition: AbstractIOHandler.hpp:98
Public definitions of openPMD-api.
Definition: Date.cpp:29
Layer to mirror structure of logical data and persistent data in file.
Definition: Writable.hpp:64
Layer to manage storage of attributes associated with file objects.
Definition: Attributable.hpp:115
Definition: Attributable.hpp:68
bool setAttribute(std::string const &key, T value)
Populate Attribute of provided name with provided value.
Definition: Attributable.hpp:417
Definition: BaseRecord.hpp:36
Implementation for the root level of the openPMD hierarchy.
Definition: Series.hpp:112
ReadMode
Definition: Attributable.hpp:274
String serialization to describe an Attributable.
Definition: Attributable.hpp:230
Map-like container that enforces openPMD requirements and handles IO.
Definition: Container.hpp:106
Definition: AbstractFilePosition.hpp:26
Definition: Attributable.hpp:401
open series as read-only, fails if series is not found