23 #include "openPMD/IO/AbstractIOHandler.hpp" 24 #include "openPMD/auxiliary/OutOfRangeMsg.hpp" 25 #include "openPMD/backend/Attribute.hpp" 26 #include "openPMD/backend/Writable.hpp" 33 #include <type_traits> 37 #ifndef OPENPMD_protected 38 #define OPENPMD_protected protected 60 : std::runtime_error(what_arg)
81 using A_MAP = std::map<std::string, Attribute>;
88 enum class SetAttributeMode : char
90 WhileReadingAttributes,
99 inline void attr_value_check(
100 std::string
const ,
T , SetAttributeMode)
104 inline void attr_value_check(
105 std::string
const key, std::string
const value, SetAttributeMode mode)
109 case SetAttributeMode::FromPublicAPICall:
111 throw std::runtime_error(
112 "[setAttribute] Value for string attribute '" + key +
113 "' must not be empty!");
115 case SetAttributeMode::WhileReadingAttributes:
131 using A_MAP = std::map<std::string, Attribute>;
133 template <
typename T_elem>
135 template <
typename T,
typename T_key,
typename T_container>
137 template <
typename T>
150 template <
typename T>
173 template <
typename T>
174 bool setAttribute(std::string
const &key,
T value);
175 bool setAttribute(std::string
const &key,
char const value[]);
186 Attribute getAttribute(std::string
const &key)
const;
194 bool deleteAttribute(std::string
const &key);
200 std::vector<std::string> attributes()
const;
205 size_t numAttributes()
const;
211 bool containsAttribute(std::string
const &key)
const;
218 std::string comment()
const;
244 std::string directory;
245 std::string seriesName;
246 std::string seriesExtension;
254 std::vector<std::string> group;
257 std::string filePath()
const;
279 Iteration const &containingIteration()
const;
287 template <
typename T>
288 bool setAttributeImpl(
289 std::string
const &key,
T value, internal::SetAttributeMode);
290 bool setAttributeImpl(
291 std::string
const &key,
char const value[], internal::SetAttributeMode);
333 template <
typename T>
334 T readFloatingpoint(std::string
const &key)
const;
356 template <
typename T>
357 std::vector<T> readVectorFloatingpoint(std::string
const &key)
const;
364 return m_attri->m_writable.IOHandler.get();
368 return m_attri->m_writable.IOHandler.get();
372 return m_attri->m_writable.parent;
376 return m_attri->m_writable.parent;
380 return m_attri->m_writable;
384 return m_attri->m_writable;
395 throw std::runtime_error(
396 "[AttributableInterface] " 397 "Cannot use default-constructed Attributable.");
408 throw std::runtime_error(
409 "[AttributableInterface] " 410 "Cannot use default-constructed Attributable.");
416 return writable().dirty;
420 return writable().dirty;
424 return writable().written;
428 return writable().written;
437 virtual void linkHierarchy(
Writable &w);
447 std::shared_ptr<internal::AttributableData> m_attributableData =
448 std::make_shared<internal::AttributableData>();
453 AttributableInterface::m_attri = m_attributableData.get();
457 template <
typename T>
460 return setAttributeImpl(
461 key, std::move(value), internal::SetAttributeMode::FromPublicAPICall);
467 return setAttributeImpl(
468 key, value, internal::SetAttributeMode::FromPublicAPICall);
473 template <
typename T>
474 inline bool Attributable::setAttributeImpl(
475 std::string
const &key,
477 internal::SetAttributeMode setAttributeMode)
479 internal::attr_value_check(key, value, setAttributeMode);
485 "Attribute",
"can not be set (read-only).");
490 auto it = attri.m_attributes.lower_bound(key);
491 if (it != attri.m_attributes.end() &&
492 !attri.m_attributes.key_comp()(key, it->first))
500 it->second =
Attribute(Attribute::resource(std::move(value)));
506 attri.m_attributes.emplace_hint(
507 it, std::make_pair(key,
Attribute(std::move(value))));
512 inline bool Attributable::setAttributeImpl(
513 std::string
const &key,
515 internal::SetAttributeMode setAttributeMode)
517 return this->setAttributeImpl(key, std::string(value), setAttributeMode);
520 template <
typename T>
524 std::is_floating_point<T>::value,
525 "Type of attribute must be floating point");
527 return getAttribute(key).get<
T>();
530 template <
typename T>
531 inline std::vector<T>
535 std::is_floating_point<T>::value,
536 "Type of attribute must be floating point");
538 return getAttribute(key).get<std::vector<T> >();
Return an error string for read-only access.
Definition: OutOfRangeMsg.hpp:36
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:532
Definition: Attributable.hpp:56
Definition: Series.hpp:498
Container Element Creation Policy.
Definition: Attributable.hpp:46
Logical compilation of data from one snapshot (e.g.
Definition: Iteration.hpp:40
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:521
Writing side of the streaming API.
Definition: WriteIterations.hpp:46
Root level of the openPMD hierarchy.
Definition: Series.hpp:537
Varidic datatype supporting at least all formats for attributes specified in the openPMD standard...
Definition: Attribute.hpp:51
Interface for communicating between logical and physically persistent data.
Definition: AbstractIOHandler.hpp:122
Public definitions of openPMD-api.
Definition: Date.cpp:28
Layer to mirror structure of logical data and persistent data in file.
Definition: Writable.hpp:63
Layer to manage storage of attributes associated with file objects.
Definition: Attributable.hpp:128
Definition: Attributable.hpp:68
bool setAttribute(std::string const &key, T value)
Populate Attribute of provided name with provided value.
Definition: Attributable.hpp:458
Definition: BaseRecord.hpp:35
Parameters recursively passed through the openPMD hierarchy when flushing.
Definition: AbstractIOHandler.hpp:103
Implementation for the root level of the openPMD hierarchy.
Definition: Series.hpp:110
ReadMode
Definition: Attributable.hpp:292
String serialization to describe an Attributable.
Definition: Attributable.hpp:241
Map-like container that enforces openPMD requirements and handles IO.
Definition: Container.hpp:105
Definition: AbstractFilePosition.hpp:25
Definition: Attributable.hpp:444
open series as read-only, fails if series is not found