Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:42:08

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 "../H5Easy.hpp"
0012 #include "H5Easy_misc.hpp"
0013 #include "H5Easy_scalar.hpp"
0014 
0015 namespace H5Easy {
0016 namespace detail {
0017 
0018 using HighFive::details::inspector;
0019 
0020 template <typename T>
0021 struct default_io_impl {
0022     inline static std::vector<size_t> shape(const T& data) {
0023         return inspector<T>::getDimensions(data);
0024     }
0025 
0026     inline static DataSet dump(File& file,
0027                                const std::string& path,
0028                                const T& data,
0029                                const DumpOptions& options) {
0030         using value_type = typename inspector<T>::base_type;
0031         DataSet dataset = initDataset<value_type>(file, path, shape(data), options);
0032         dataset.write(data);
0033         if (options.flush()) {
0034             file.flush();
0035         }
0036         return dataset;
0037     }
0038 
0039     inline static T load(const File& file, const std::string& path) {
0040         return file.getDataSet(path).read<T>();
0041     }
0042 
0043     inline static Attribute dumpAttribute(File& file,
0044                                           const std::string& path,
0045                                           const std::string& key,
0046                                           const T& data,
0047                                           const DumpOptions& options) {
0048         using value_type = typename inspector<T>::base_type;
0049         Attribute attribute = initAttribute<value_type>(file, path, key, shape(data), options);
0050         attribute.write(data);
0051         if (options.flush()) {
0052             file.flush();
0053         }
0054         return attribute;
0055     }
0056 
0057     inline static T loadAttribute(const File& file,
0058                                   const std::string& path,
0059                                   const std::string& key) {
0060         auto read_attribute = [&key](const auto& obj) {
0061             return obj.getAttribute(key).template read<T>();
0062         };
0063 
0064         return apply_attr_func(file, path, read_attribute);
0065     }
0066 };
0067 
0068 }  // namespace detail
0069 }  // namespace H5Easy