23 #include "openPMD/IO/AbstractIOHandler.hpp" 24 #include "openPMD/ThrowError.hpp" 25 #include "openPMD/auxiliary/OutOfRangeMsg.hpp" 26 #include "openPMD/backend/Attribute.hpp" 27 #include "openPMD/backend/Writable.hpp" 34 #include <type_traits> 38 #ifndef OPENPMD_protected 39 #define OPENPMD_protected protected: 69 using A_MAP = std::map<std::string, Attribute>;
96 using A_MAP = std::map<std::string, Attribute>;
98 template <
typename T_elem>
100 template <
typename T_elem>
101 friend class BaseRecordInterface;
104 template <
typename T,
typename T_key,
typename T_container>
106 template <
typename T>
114 std::shared_ptr<internal::AttributableData> m_attri{
118 Attributable(std::shared_ptr<internal::AttributableData>);
139 template <
typename T>
140 bool setAttribute(std::string
const &key,
T value);
141 bool setAttribute(std::string
const &key,
char const value[]);
152 Attribute getAttribute(std::string
const &key)
const;
160 bool deleteAttribute(std::string
const &key);
166 std::vector<std::string> attributes()
const;
171 size_t numAttributes()
const;
177 bool containsAttribute(std::string
const &key)
const;
184 std::string comment()
const;
205 void seriesFlush(std::string backendConfig =
"{}");
215 std::string directory;
216 std::string seriesName;
217 std::string seriesExtension;
225 std::vector<std::string> group;
228 std::string filePath()
const;
242 Series retrieveSeries()
const;
251 Iteration const &containingIteration()
const;
299 template <
typename T>
300 T readFloatingpoint(std::string
const &key)
const;
322 template <
typename T>
323 std::vector<T> readVectorFloatingpoint(std::string
const &key)
const;
335 auto &opt = m_attri->m_writable.IOHandler;
336 if (!opt || !opt->has_value())
340 return &*opt->value();
344 return m_attri->m_writable.parent;
348 return m_attri->m_writable.parent;
352 return m_attri->m_writable;
356 return m_attri->m_writable;
359 inline void setData(std::shared_ptr<internal::AttributableData> attri)
361 m_attri = std::move(attri);
375 return writable().dirty;
379 return writable().dirty;
383 return writable().written;
387 return writable().written;
396 virtual void linkHierarchy(
Writable &w);
401 template <
typename T>
410 "Attribute",
"can not be set (read-only).");
411 error::throwNoSuchAttribute(out_of_range_msg(key));
415 auto it = attri.m_attributes.lower_bound(key);
416 if (it != attri.m_attributes.end() &&
417 !attri.m_attributes.key_comp()(key, it->first))
420 it->second =
Attribute(std::move(value));
426 attri.m_attributes.emplace_hint(
427 it, std::make_pair(key,
Attribute(std::move(value))));
435 return this->setAttribute(key, std::string(value));
438 template <
typename T>
442 std::is_floating_point<T>::value,
443 "Type of attribute must be floating point");
445 return getAttribute(key).get<
T>();
448 template <
typename T>
449 inline std::vector<T>
453 std::is_floating_point<T>::value,
454 "Type of attribute must be floating point");
456 return getAttribute(key).get<std::vector<T> >();
Return an error string for read-only access.
Definition: OutOfRangeMsg.hpp:36
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:439
Definition: Attributable.hpp:85
Container Element Creation Policy.
Definition: Attributable.hpp:47
Logical compilation of data from one snapshot (e.g.
Definition: Iteration.hpp:126
ReadMode
Definition: Attributable.hpp:258
String serialization to describe an Attributable.
Definition: Attributable.hpp:212
Definition: WriteIterations.hpp:53
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:450
Implementation for the root level of the openPMD hierarchy.
Definition: Series.hpp:186
Varidic datatype supporting at least all formats for attributes specified in the openPMD standard...
Definition: Attribute.hpp:54
bool setAttribute(std::string const &key, T value)
Populate Attribute of provided name with provided value.
Definition: Attributable.hpp:402
Interface for communicating between logical and physically persistent data.
Definition: AbstractIOHandler.hpp:179
Writable m_writable
The Writable associated with this Attributable.
Definition: Attributable.hpp:75
Public definitions of openPMD-api.
Layer to mirror structure of logical data and persistent data in file.
Definition: Writable.hpp:64
Definition: Attributable.hpp:56
Mutability of objects in the openPMD object model is determined by the open mode (Access enum)...
Definition: BaseRecord.hpp:58
Parameters recursively passed through the openPMD hierarchy when flushing.
Definition: AbstractIOHandler.hpp:84
Map-like container that enforces openPMD requirements and handles IO.
Definition: Container.hpp:131
Definition: AbstractFilePosition.hpp:25
Open Series as read-only, fails if Series is not found.
Layer to manage storage of attributes associated with file objects.
Definition: Attributable.hpp:93