|
|
|||
File indexing completed on 2026-09-13 09:13:20
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 <vector> 0012 #include <array> 0013 #include <cstdint> 0014 #include <type_traits> 0015 #include <initializer_list> 0016 0017 #include "H5Object.hpp" 0018 #include "bits/H5_definitions.hpp" 0019 0020 namespace HighFive { 0021 0022 namespace detail { 0023 /// @brief Create a HighFive::DataSpace from an HID, without incrementing the id. 0024 /// 0025 /// @note This is internal API and subject to change. 0026 /// @internal 0027 DataSpace make_data_space(hid_t hid); 0028 } // namespace detail 0029 0030 /// \brief Class representing the space (dimensions) of a DataSet 0031 /// 0032 /// \code{.cpp} 0033 /// // Create a DataSpace of dimension 1 x 2 x 3 0034 /// DataSpace dspace(1, 2, 3); 0035 /// std::cout << dspace.getElementCount() << std::endl; // Print 1 * 2 * 3 = 6 0036 /// std::cout << dspace.getNumberDimensions() << std::endl; // Print 3 0037 /// std::vector<size_t> dims = dspace.getDimensions(); // dims is {1, 2, 3} 0038 /// \endcode 0039 class DataSpace: public Object { 0040 public: 0041 const static ObjectType type = ObjectType::DataSpace; 0042 0043 /// \brief Magic value to specify that a DataSpace can grow without limit. 0044 /// 0045 /// This value should be used with DataSpace::DataSpace(const std::vector<size_t>& dims, const 0046 /// std::vector<size_t>& maxdims); 0047 /// 0048 /// \since 2.0 0049 static const size_t UNLIMITED = SIZE_MAX; 0050 0051 /// \brief An enum to create scalar and null DataSpace with DataSpace::DataSpace(DataspaceType dtype). 0052 /// 0053 /// This enum is needed otherwise we will not be able to distringuish between both with normal 0054 /// constructors. Both have a dimension of 0. 0055 /// \since 1.3 0056 enum class DataspaceType { 0057 dataspace_scalar, ///< Value to create scalar DataSpace 0058 dataspace_null, ///< Value to create null DataSpace 0059 // simple dataspace are handle directly from their dimensions 0060 }; 0061 0062 // For backward compatibility: `DataSpace::dataspace_scalar`. 0063 constexpr static DataspaceType dataspace_scalar = DataspaceType::dataspace_scalar; 0064 constexpr static DataspaceType dataspace_null = DataspaceType::dataspace_null; 0065 0066 /// \brief Create a DataSpace of N-dimensions from a std::vector<size_t>. 0067 /// \param dims Dimensions of the new DataSpace 0068 /// 0069 /// \code{.cpp} 0070 /// // Create a DataSpace with 2 dimensions: 1 and 3 0071 /// DataSpace(std::vector<size_t>{1, 3}); 0072 /// \endcode 0073 /// \since 1.0 0074 explicit DataSpace(const std::vector<size_t>& dims); 0075 0076 /// \brief Create a DataSpace of N-dimensions from a std::array<size_t, N>. 0077 /// \param dims Dimensions of the new DataSpace 0078 /// 0079 /// \code{.cpp} 0080 /// // Create a DataSpace with 2 dimensions: 1 and 3 0081 /// DataSpace(std::array<size_t, 2>{1, 3}); 0082 /// \endcode 0083 /// \since 2.3 0084 template <size_t N> 0085 constexpr explicit DataSpace(const std::array<size_t, N>& dims); 0086 0087 /// \brief Create a DataSpace of N-dimensions from an initializer list. 0088 /// \param dims Dimensions of the new DataSpace 0089 /// 0090 /// \code{.cpp} 0091 /// // Create a DataSpace with 2 dimensions: 1 and 3 0092 /// DataSpace{1, 3}; 0093 /// \endcode 0094 /// \since 2.1 0095 DataSpace(const std::initializer_list<size_t>& dims); 0096 0097 /// \brief Create a DataSpace of N-dimensions from direct values. 0098 /// \param dim1 The first dimension 0099 /// \param dims The following dimensions 0100 /// 0101 /// \code{.cpp} 0102 /// // Create a DataSpace with 2 dimensions: 1 and 3 0103 /// DataSpace(1, 3); 0104 /// \endcode 0105 /// \since 2.1 0106 template <typename... Args> 0107 explicit DataSpace(size_t dim1, Args... dims); 0108 0109 /// \brief Create a DataSpace from a pair of iterators. 0110 /// \param begin The beginning of the container 0111 /// \param end The end of the container 0112 /// 0113 /// \code{.cpp} 0114 /// // Create a DataSpace with 2 dimensions: 1 and 3 0115 /// std::vector<int> v{1, 3}; 0116 /// DataSpace(v.begin(), v.end()); 0117 /// \endcode 0118 /// 0119 /// \since 2.0 0120 // Attention: Explicitly disable DataSpace(int_like, int_like) from trying 0121 // to use this constructor 0122 template <typename IT, 0123 typename = typename std::enable_if<!std::is_integral<IT>::value, IT>::type> 0124 DataSpace(IT begin, IT end); 0125 0126 /// \brief Create a resizable N-dimensional DataSpace. 0127 /// \param dims Initial size of dataspace 0128 /// \param maxdims Maximum size of the dataspace 0129 /// 0130 /// \code{.cpp} 0131 /// // Create a DataSpace with 2 dimensions: 1 and 3. 0132 /// // It can later be resized up to a maximum of 10 x 10 0133 /// DataSpace(std::vector<size_t>{1, 3}, std::vector<size_t>{10, 10}); 0134 /// \endcode 0135 /// 0136 /// \see UNLIMITED for a DataSpace that can be resized without limit. 0137 /// \since 2.0 0138 explicit DataSpace(const std::vector<size_t>& dims, const std::vector<size_t>& maxdims); 0139 0140 /// \brief Create a scalar or a null DataSpace. 0141 /// 0142 /// This overload enables creating scalar or null data spaces, both have 0143 /// dimension 0. 0144 /// 0145 /// \param space_type The value from the enum 0146 /// 0147 /// \code{.cpp} 0148 /// DataSpace(DataspaceType::dataspace_scalar); 0149 /// \endcode 0150 /// 0151 /// \attention Avoid braced intialization in these cases, i.e. 0152 /// \code{.cpp} 0153 /// // This is not a scalar dataset: 0154 /// DataSpace{DataspaceType::dataspace_scalar}; 0155 /// \endcode 0156 /// 0157 /// \since 1.3 0158 explicit DataSpace(DataspaceType space_type); 0159 0160 /// \brief Create a scalar DataSpace. 0161 /// 0162 /// \code{.cpp} 0163 /// auto dataspace = DataSpace::Scalar(); 0164 /// \endcode 0165 /// 0166 /// \since 2.9 0167 static DataSpace Scalar(); 0168 0169 /// \brief Create a null DataSpace. 0170 /// 0171 /// \code{.cpp} 0172 /// auto dataspace = DataSpace::Null(); 0173 /// \endcode 0174 /// 0175 /// \since 2.9 0176 static DataSpace Null(); 0177 0178 /// \brief Create a copy of the DataSpace which will have different id. 0179 /// 0180 /// \code{.cpp} 0181 /// DataSpace dspace1(1, 3); 0182 /// auto dspace2 = dspace.clone(); 0183 /// \endcode 0184 /// 0185 /// \since 1.0 0186 DataSpace clone() const; 0187 0188 /// \brief Returns the number of dimensions of a DataSpace. 0189 /// \code{.cpp} 0190 /// DataSpace dspace(1, 3); 0191 /// size_t number_of_dim = dspace.getNumberDimensions(); // returns 2 0192 /// \endcode 0193 /// \since 1.0 0194 size_t getNumberDimensions() const; 0195 0196 /// \brief Returns the size of the dataset in each dimension. 0197 /// 0198 /// For zero-dimensional datasets (e.g. scalar or null datasets) an empty 0199 /// vector is returned. 0200 /// 0201 /// \code{.cpp} 0202 /// DataSpace dspace(1, 3); 0203 /// auto dims = dspace.getDimensions(); // returns {1, 3} 0204 /// \endcode 0205 /// 0206 /// \sa DataSpace::getMaxDimensions 0207 /// 0208 /// \since 1.0 0209 std::vector<size_t> getDimensions() const; 0210 0211 /// \brief Return the number of elements in this DataSpace. 0212 /// 0213 /// \code{.cpp} 0214 /// DataSpace dspace(1, 3); 0215 /// size_t elementcount = dspace.getElementCount(); // return 1 x 3 = 3 0216 /// \endcode 0217 /// \since 2.1 0218 size_t getElementCount() const; 0219 0220 /// \brief Returns the maximum size of the dataset in each dimension. 0221 /// 0222 /// This is the maximum size a dataset can be extended to, which may be 0223 /// different from the current size of the dataset. 0224 /// 0225 /// \code{.cpp} 0226 /// DataSpace dspace(std::vector<size_t>{1, 3}, std::vector<size_t>{UNLIMITED, 10}); 0227 /// dspace.getMaxDimensions(); // Return {UNLIMITED, 10} 0228 /// \endcode 0229 /// 0230 /// \sa DataSpace::getDimensions 0231 /// \since 2.0 0232 std::vector<size_t> getMaxDimensions() const; 0233 0234 /// \brief Automatically deduce the DataSpace from a container/value. 0235 /// 0236 /// Certain containers and scalar values are fully supported by HighFive. 0237 /// For these containers, HighFive can deduce the dimensions from `value`. 0238 /// 0239 /// \code{.cpp} 0240 /// double d = 42.0; 0241 /// std::vector<std::vector<int>> v = {{4, 5, 6}, {7, 8, 9}}; 0242 /// DataSpace::From(v); // A DataSpace of dimensions 2, 3. 0243 /// DataSpace::From(d); // A scalar dataspace. 0244 /// \endcode 0245 /// 0246 /// \since 1.0 0247 template <typename T> 0248 static DataSpace From(const T& value); 0249 0250 /// \brief Create a DataSpace from a value of type string array. 0251 /// \param string_array An C-array of C-string (null-terminated). 0252 /// 0253 /// \code{.cpp} 0254 /// char string_array[2][10] = {"123456789", "abcdefghi"}; 0255 /// auto dspace = DataSpace::FromCharArrayStrings(string_array); // dspace is a DataSpace of 0256 /// dimensions 2 0257 /// \endcode 0258 /// \since 2.2 0259 template <std::size_t N, std::size_t Width> 0260 static DataSpace FromCharArrayStrings(const char (&string_array)[N][Width]); 0261 0262 protected: 0263 DataSpace() = default; 0264 0265 static DataSpace fromId(hid_t hid) { 0266 DataSpace space; 0267 space._hid = hid; 0268 0269 return space; 0270 } 0271 0272 friend class Attribute; 0273 friend class File; 0274 friend class DataSet; 0275 0276 friend DataSpace detail::make_data_space(hid_t hid); 0277 }; 0278 0279 } // namespace HighFive 0280 0281 // We include bits right away since DataSpace is user-constructible 0282 #include "bits/H5Dataspace_misc.hpp"
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|