Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-04-19 08:55:32

0001 /*
0002  *  Copyright (c), 2017, Adrien Devresse <adrien.devresse@epfl.ch>
0003  *
0004  *  Distributed under the Boost Software License, Version 1.0.
0005  *    (See accompanying file LICENSE_1_0.txt or copy at
0006  *          http://www.boost.org/LICENSE_1_0.txt)
0007  *
0008  */
0009 #pragma once
0010 
0011 #include <string>
0012 #include <vector>
0013 
0014 #include <H5Apublic.h>
0015 #include <H5Ppublic.h>
0016 
0017 #include "H5Attribute_misc.hpp"
0018 #include "H5Iterables_misc.hpp"
0019 #include "h5a_wrapper.hpp"
0020 
0021 namespace HighFive {
0022 
0023 template <typename Derivate>
0024 inline Attribute AnnotateTraits<Derivate>::createAttribute(const std::string& attribute_name,
0025                                                            const DataSpace& space,
0026                                                            const DataType& dtype) {
0027     auto attr_id = detail::h5a_create2(static_cast<Derivate*>(this)->getId(),
0028                                        attribute_name.c_str(),
0029                                        dtype.getId(),
0030                                        space.getId(),
0031                                        H5P_DEFAULT,
0032                                        H5P_DEFAULT);
0033     return detail::make_attribute(attr_id);
0034 }
0035 
0036 template <typename Derivate>
0037 template <typename Type>
0038 inline Attribute AnnotateTraits<Derivate>::createAttribute(const std::string& attribute_name,
0039                                                            const DataSpace& space) {
0040     return createAttribute(attribute_name, space, create_and_check_datatype<Type>());
0041 }
0042 
0043 template <typename Derivate>
0044 template <typename T>
0045 inline Attribute AnnotateTraits<Derivate>::createAttribute(const std::string& attribute_name,
0046                                                            const T& data) {
0047     Attribute att =
0048         createAttribute(attribute_name,
0049                         DataSpace::From(data),
0050                         create_and_check_datatype<typename details::inspector<T>::base_type>());
0051     att.write(data);
0052     return att;
0053 }
0054 
0055 template <typename Derivate>
0056 inline void AnnotateTraits<Derivate>::deleteAttribute(const std::string& attribute_name) {
0057     detail::h5a_delete(static_cast<const Derivate*>(this)->getId(), attribute_name.c_str());
0058 }
0059 
0060 template <typename Derivate>
0061 inline Attribute AnnotateTraits<Derivate>::getAttribute(const std::string& attribute_name) const {
0062     const auto attr_id = detail::h5a_open(static_cast<const Derivate*>(this)->getId(),
0063                                           attribute_name.c_str(),
0064                                           H5P_DEFAULT);
0065     return detail::make_attribute(attr_id);
0066 }
0067 
0068 template <typename Derivate>
0069 inline size_t AnnotateTraits<Derivate>::getNumberAttributes() const {
0070     int res = detail::h5a_get_num_attrs(static_cast<const Derivate*>(this)->getId());
0071     return static_cast<size_t>(res);
0072 }
0073 
0074 template <typename Derivate>
0075 inline std::vector<std::string> AnnotateTraits<Derivate>::listAttributeNames() const {
0076     std::vector<std::string> names;
0077     details::HighFiveIterateData iterateData(names);
0078 
0079     size_t num_objs = getNumberAttributes();
0080     names.reserve(num_objs);
0081 
0082     detail::h5a_iterate2(static_cast<const Derivate*>(this)->getId(),
0083                          H5_INDEX_NAME,
0084                          H5_ITER_INC,
0085                          nullptr,
0086                          &details::internal_high_five_iterate<H5A_info_t>,
0087                          static_cast<void*>(&iterateData));
0088 
0089     return names;
0090 }
0091 
0092 template <typename Derivate>
0093 inline bool AnnotateTraits<Derivate>::hasAttribute(const std::string& attr_name) const {
0094     return detail::h5a_exists(static_cast<const Derivate*>(this)->getId(), attr_name.c_str()) > 0;
0095 }
0096 
0097 }  // namespace HighFive