![]() |
|
|||
File indexing completed on 2025-04-19 08:55:35
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 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 /// \brief Create a DataSpace of N-dimensions from a std::vector<size_t>. 0063 /// \param dims Dimensions of the new DataSpace 0064 /// 0065 /// \code{.cpp} 0066 /// // Create a DataSpace with 2 dimensions: 1 and 3 0067 /// DataSpace(std::vector<size_t>{1, 3}); 0068 /// \endcode 0069 /// \since 1.0 0070 explicit DataSpace(const std::vector<size_t>& dims); 0071 0072 /// \brief Create a DataSpace of N-dimensions from a std::array<size_t, N>. 0073 /// \param dims Dimensions of the new DataSpace 0074 /// 0075 /// \code{.cpp} 0076 /// // Create a DataSpace with 2 dimensions: 1 and 3 0077 /// DataSpace(std::array<size_t, 2>{1, 3}); 0078 /// \endcode 0079 /// \since 2.3 0080 template <size_t N> 0081 explicit DataSpace(const std::array<size_t, N>& dims); 0082 0083 /// \brief Create a DataSpace of N-dimensions from an initializer list. 0084 /// \param dims Dimensions of the new DataSpace 0085 /// 0086 /// \code{.cpp} 0087 /// // Create a DataSpace with 2 dimensions: 1 and 3 0088 /// DataSpace{1, 3}; 0089 /// \endcode 0090 /// \since 2.1 0091 DataSpace(const std::initializer_list<size_t>& dims); 0092 0093 /// \brief Create a DataSpace of N-dimensions from direct values. 0094 /// \param dim1 The first dimension 0095 /// \param dims The following dimensions 0096 /// 0097 /// \code{.cpp} 0098 /// // Create a DataSpace with 2 dimensions: 1 and 3 0099 /// DataSpace(1, 3); 0100 /// \endcode 0101 /// \since 2.1 0102 template <typename... Args> 0103 explicit DataSpace(size_t dim1, Args... dims); 0104 0105 /// \brief Create a DataSpace from a pair of iterators. 0106 /// \param begin The beginning of the container 0107 /// \param end The end of the container 0108 /// 0109 /// \code{.cpp} 0110 /// // Create a DataSpace with 2 dimensions: 1 and 3 0111 /// std::vector<int> v{1, 3}; 0112 /// DataSpace(v.begin(), v.end()); 0113 /// \endcode 0114 /// 0115 /// \since 2.0 0116 // Attention: Explicitly disable DataSpace(int_like, int_like) from trying 0117 // to use this constructor 0118 template <typename IT, 0119 typename = typename std::enable_if<!std::is_integral<IT>::value, IT>::type> 0120 DataSpace(const IT begin, const IT end); 0121 0122 /// \brief Create a resizable N-dimensional DataSpace. 0123 /// \param dims Initial size of dataspace 0124 /// \param maxdims Maximum size of the dataspace 0125 /// 0126 /// \code{.cpp} 0127 /// // Create a DataSpace with 2 dimensions: 1 and 3. 0128 /// // It can later be resized up to a maximum of 10 x 10 0129 /// DataSpace(std::vector<size_t>{1, 3}, std::vector<size_t>{10, 10}); 0130 /// \endcode 0131 /// 0132 /// \see UNLIMITED for a DataSpace that can be resized without limit. 0133 /// \since 2.0 0134 explicit DataSpace(const std::vector<size_t>& dims, const std::vector<size_t>& maxdims); 0135 0136 /// \brief Create a scalar or a null DataSpace. 0137 /// 0138 /// This overload enables creating scalar or null data spaces, both have 0139 /// dimension 0. 0140 /// 0141 /// \param space_type The value from the enum 0142 /// 0143 /// \code{.cpp} 0144 /// DataSpace(DataspaceType::dataspace_scalar); 0145 /// \endcode 0146 /// 0147 /// \attention Avoid braced intialization in these cases, i.e. 0148 /// \code{.cpp} 0149 /// // This is not a scalar dataset: 0150 /// DataSpace{DataspaceType::dataspace_scalar}; 0151 /// \endcode 0152 /// 0153 /// \since 1.3 0154 explicit DataSpace(DataspaceType space_type); 0155 0156 /// \brief Create a scalar DataSpace. 0157 /// 0158 /// \code{.cpp} 0159 /// auto dataspace = DataSpace::Scalar(); 0160 /// \endcode 0161 /// 0162 /// \since 2.9 0163 static DataSpace Scalar(); 0164 0165 /// \brief Create a null DataSpace. 0166 /// 0167 /// \code{.cpp} 0168 /// auto dataspace = DataSpace::Null(); 0169 /// \endcode 0170 /// 0171 /// \since 2.9 0172 static DataSpace Null(); 0173 0174 /// \brief Create a copy of the DataSpace which will have different id. 0175 /// 0176 /// \code{.cpp} 0177 /// DataSpace dspace1(1, 3); 0178 /// auto dspace2 = dspace.clone(); 0179 /// \endcode 0180 /// 0181 /// \since 1.0 0182 DataSpace clone() const; 0183 0184 /// \brief Returns the number of dimensions of a DataSpace. 0185 /// \code{.cpp} 0186 /// DataSpace dspace(1, 3); 0187 /// size_t number_of_dim = dspace.getNumberDimensions(); // returns 2 0188 /// \endcode 0189 /// \since 1.0 0190 size_t getNumberDimensions() const; 0191 0192 /// \brief Returns the size of the dataset in each dimension. 0193 /// 0194 /// For zero-dimensional datasets (e.g. scalar or null datasets) an empty 0195 /// vector is returned. 0196 /// 0197 /// \code{.cpp} 0198 /// DataSpace dspace(1, 3); 0199 /// auto dims = dspace.getDimensions(); // returns {1, 3} 0200 /// \endcode 0201 /// 0202 /// \sa DataSpace::getMaxDimensions 0203 /// 0204 /// \since 1.0 0205 std::vector<size_t> getDimensions() const; 0206 0207 /// \brief Return the number of elements in this DataSpace. 0208 /// 0209 /// \code{.cpp} 0210 /// DataSpace dspace(1, 3); 0211 /// size_t elementcount = dspace.getElementCount(); // return 1 x 3 = 3 0212 /// \endcode 0213 /// \since 2.1 0214 size_t getElementCount() const; 0215 0216 /// \brief Returns the maximum size of the dataset in each dimension. 0217 /// 0218 /// This is the maximum size a dataset can be extended to, which may be 0219 /// different from the current size of the dataset. 0220 /// 0221 /// \code{.cpp} 0222 /// DataSpace dspace(std::vector<size_t>{1, 3}, std::vector<size_t>{UNLIMITED, 10}); 0223 /// dspace.getMaxDimensions(); // Return {UNLIMITED, 10} 0224 /// \endcode 0225 /// 0226 /// \sa DataSpace::getDimensions 0227 /// \since 2.0 0228 std::vector<size_t> getMaxDimensions() const; 0229 0230 /// \brief Automatically deduce the DataSpace from a container/value. 0231 /// 0232 /// Certain containers and scalar values are fully supported by HighFive. 0233 /// For these containers, HighFive can deduce the dimensions from `value`. 0234 /// 0235 /// \code{.cpp} 0236 /// double d = 42.0; 0237 /// std::vector<std::vector<int>> v = {{4, 5, 6}, {7, 8, 9}}; 0238 /// DataSpace::From(v); // A DataSpace of dimensions 2, 3. 0239 /// DataSpace::From(d); // A scalar dataspace. 0240 /// \endcode 0241 /// 0242 /// \since 1.0 0243 template <typename T> 0244 static DataSpace From(const T& value); 0245 0246 /// \brief Create a DataSpace from a value of type string array. 0247 /// \param string_array An C-array of C-string (null-terminated). 0248 /// 0249 /// \code{.cpp} 0250 /// char string_array[2][10] = {"123456789", "abcdefghi"}; 0251 /// auto dspace = DataSpace::FromCharArrayStrings(string_array); // dspace is a DataSpace of 0252 /// dimensions 2 0253 /// \endcode 0254 /// \since 2.2 0255 template <std::size_t N, std::size_t Width> 0256 static DataSpace FromCharArrayStrings(const char (&string_array)[N][Width]); 0257 0258 protected: 0259 DataSpace() = default; 0260 0261 static DataSpace fromId(hid_t hid) { 0262 DataSpace space; 0263 space._hid = hid; 0264 0265 return space; 0266 } 0267 0268 friend class Attribute; 0269 friend class File; 0270 friend class DataSet; 0271 0272 friend DataSpace detail::make_data_space(hid_t hid); 0273 }; 0274 0275 } // namespace HighFive 0276 0277 // We include bits right away since DataSpace is user-constructible 0278 #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 |
![]() ![]() |