![]() |
|
|||
File indexing completed on 2025-04-19 08:55:33
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 0013 #include "../H5PropertyList.hpp" 0014 #include "H5_definitions.hpp" 0015 #include "H5Converter_misc.hpp" 0016 0017 namespace HighFive { 0018 0019 enum class IndexType : std::underlying_type<H5_index_t>::type { 0020 NAME = H5_INDEX_NAME, 0021 CRT_ORDER = H5_INDEX_CRT_ORDER, 0022 }; 0023 0024 /// 0025 /// \brief NodeTraits: Base class for Group and File 0026 /// 0027 template <typename Derivate> 0028 class NodeTraits { 0029 public: 0030 /// 0031 /// \brief createDataSet Create a new dataset in the current file of 0032 /// datatype type and of size space 0033 /// \param dataset_name identifier of the dataset 0034 /// \param space Associated DataSpace, see \ref DataSpace for more information 0035 /// \param type Type of Data 0036 /// \param createProps A property list with data set creation properties 0037 /// \param accessProps A property list with data set access properties 0038 /// \param parents Create intermediate groups if needed. Default: true. 0039 /// \return DataSet Object 0040 DataSet createDataSet(const std::string& dataset_name, 0041 const DataSpace& space, 0042 const DataType& type, 0043 const DataSetCreateProps& createProps = DataSetCreateProps::Default(), 0044 const DataSetAccessProps& accessProps = DataSetAccessProps::Default(), 0045 bool parents = true); 0046 0047 /// 0048 /// \brief createDataSet create a new dataset in the current file with a 0049 /// size specified by space 0050 /// \param dataset_name identifier of the dataset 0051 /// \param space Associated DataSpace, see \ref DataSpace for more information 0052 /// \param createProps A property list with data set creation properties 0053 /// \param accessProps A property list with data set access properties 0054 /// \param parents Create intermediate groups if needed. Default: true. 0055 /// \return DataSet Object 0056 template <typename T> 0057 DataSet createDataSet(const std::string& dataset_name, 0058 const DataSpace& space, 0059 const DataSetCreateProps& createProps = DataSetCreateProps::Default(), 0060 const DataSetAccessProps& accessProps = DataSetAccessProps::Default(), 0061 bool parents = true); 0062 0063 /// 0064 /// \brief createDataSet create a new dataset in the current file and 0065 /// write to it, inferring the DataSpace from the data. 0066 /// \param dataset_name identifier of the dataset 0067 /// \param data Associated data, must support DataSpace::From, see 0068 /// \ref DataSpace for more information 0069 /// \param createProps A property list with data set creation properties 0070 /// \param accessProps A property list with data set access properties 0071 /// \param parents Create intermediate groups if needed. Default: true. 0072 /// \return DataSet Object 0073 template <typename T> 0074 DataSet createDataSet(const std::string& dataset_name, 0075 const T& data, 0076 const DataSetCreateProps& createProps = DataSetCreateProps::Default(), 0077 const DataSetAccessProps& accessProps = DataSetAccessProps::Default(), 0078 bool parents = true); 0079 0080 0081 template <std::size_t N> 0082 H5_DEPRECATED("Use 'std::vector<std::string>'.") 0083 DataSet createDataSet(const std::string& dataset_name, 0084 const deprecated::FixedLenStringArray<N>& data, 0085 const DataSetCreateProps& createProps = DataSetCreateProps::Default(), 0086 const DataSetAccessProps& accessProps = DataSetAccessProps::Default(), 0087 bool parents = true); 0088 0089 /// 0090 /// \brief get an existing dataset in the current file 0091 /// \param dataset_name 0092 /// \param accessProps property list to configure dataset chunk cache 0093 /// \return return the named dataset, or throw exception if not found 0094 DataSet getDataSet(const std::string& dataset_name, 0095 const DataSetAccessProps& accessProps = DataSetAccessProps::Default()) const; 0096 0097 /// 0098 /// \brief create a new group, and eventually intermediate groups 0099 /// \param group_name 0100 /// \param parents Create intermediate groups if needed. Default: true. 0101 /// \return the group object 0102 Group createGroup(const std::string& group_name, bool parents = true); 0103 0104 /// 0105 /// \brief create a new group, and eventually intermediate groups 0106 /// \param group_name 0107 /// \param createProps A property list with group creation properties 0108 /// \param parents Create intermediate groups if needed. Default: true. 0109 /// \return the group object 0110 Group createGroup(const std::string& group_name, 0111 const GroupCreateProps& createProps, 0112 bool parents = true); 0113 0114 /// 0115 /// \brief open an existing group with the name group_name 0116 /// \param group_name 0117 /// \return the group object 0118 Group getGroup(const std::string& group_name) const; 0119 0120 /// 0121 /// \brief open a commited datatype with the name type_name 0122 /// \param type_name 0123 /// \return the datatype object 0124 DataType getDataType( 0125 const std::string& type_name, 0126 const DataTypeAccessProps& accessProps = DataTypeAccessProps::Default()) const; 0127 0128 /// 0129 /// \brief return the number of leaf objects of the node / group 0130 /// \return number of leaf objects 0131 size_t getNumberObjects() const; 0132 0133 /// 0134 /// \brief return the name of the object with the given index 0135 /// \return the name of the object 0136 std::string getObjectName(size_t index) const; 0137 0138 /// 0139 /// \brief moves an object and its content within an HDF5 file. 0140 /// \param src_path relative path of the object to current File/Group 0141 /// \param dest_path new relative path of the object to current File/Group 0142 /// \param parents Create intermediate groups if needed. Default: true. 0143 /// \return boolean that is true if the move was successful 0144 bool rename(const std::string& src_path, 0145 const std::string& dest_path, 0146 bool parents = true) const; 0147 0148 /// 0149 /// \brief list all leaf objects name of the node / group 0150 /// \param idx_type tell if the list should be ordered by Name or CreationOrderTime. 0151 /// CreationOrderTime can be use only if the file/group has been created with 0152 /// the HighFive::LinkCreationTime property. 0153 /// \return number of leaf objects 0154 std::vector<std::string> listObjectNames(IndexType idx_type = IndexType::NAME) const; 0155 0156 /// 0157 /// \brief check a dataset or group exists in the current node / group 0158 /// \param node_name dataset/group name to check 0159 /// \return true if a dataset/group with the associated name exists, or false 0160 bool exist(const std::string& node_name) const; 0161 0162 /// 0163 /// \brief unlink the given dataset or group 0164 /// \param node_name dataset/group name to unlink 0165 void unlink(const std::string& node_name) const; 0166 0167 /// 0168 /// \brief Returns the kind of link of the given name (soft, hard...) 0169 /// \param node_name The entry to check, path relative to the current group 0170 LinkType getLinkType(const std::string& node_name) const; 0171 0172 /// 0173 /// \brief A shorthand to get the kind of object pointed to (group, dataset, type...) 0174 /// \param node_name The entry to check, path relative to the current group 0175 ObjectType getObjectType(const std::string& node_name) const; 0176 0177 /// 0178 /// \brief A shorthand to create softlink to any object which provides `getPath` 0179 /// The link will be created with default properties along with required parent groups 0180 template <typename T, typename = decltype(&T::getPath)> 0181 void createSoftLink(const std::string& linkName, const T& obj) { 0182 static_assert(!std::is_same<T, Attribute>::value, 0183 "hdf5 doesn't support soft links to Attributes"); 0184 createSoftLink(linkName, obj.getPath()); 0185 } 0186 0187 /// 0188 /// \brief Creates softlinks 0189 /// \param link_name The name of the link 0190 /// \param obj_path The target object path 0191 /// \param linkCreateProps A Link_Create property list. Notice "parents=true" overrides 0192 /// \param linkAccessProps The Link_Access property list 0193 /// \param parents Whether parent groups should be created: Default: true 0194 void createSoftLink(const std::string& link_name, 0195 const std::string& obj_path, 0196 LinkCreateProps linkCreateProps = LinkCreateProps(), 0197 const LinkAccessProps& linkAccessProps = LinkAccessProps(), 0198 const bool parents = true); 0199 0200 void createExternalLink(const std::string& link_name, 0201 const std::string& h5_file, 0202 const std::string& obj_path, 0203 LinkCreateProps linkCreateProps = LinkCreateProps(), 0204 const LinkAccessProps& linkAccessProps = LinkAccessProps(), 0205 const bool parents = true); 0206 0207 /// 0208 /// \brief Creates hardlinks 0209 /// \param link_name The name of the link 0210 /// \param target_obj The target object 0211 /// \param linkCreateProps A Link_Create property list. Notice "parents=true" overrides 0212 /// \param linkAccessProps The Link_Access property list 0213 /// \param parents Whether parent groups should be created: Default: true 0214 template <typename T, typename = decltype(&T::getPath)> 0215 void createHardLink(const std::string& link_name, 0216 const T& target_obj, 0217 LinkCreateProps linkCreateProps = LinkCreateProps(), 0218 const LinkAccessProps& linkAccessProps = LinkAccessProps(), 0219 const bool parents = true); 0220 0221 private: 0222 using derivate_type = Derivate; 0223 0224 // A wrapper over the low-level H5Lexist 0225 // It makes behavior consistent among versions and by default transforms 0226 // errors to exceptions 0227 bool _exist(const std::string& node_name, bool raise_errors = true) const; 0228 0229 // Opens an arbitrary object to obtain info 0230 Object _open(const std::string& node_name) const; 0231 }; 0232 0233 0234 /// 0235 /// \brief The possible types of group entries (link concept) 0236 /// 0237 enum class LinkType { 0238 Hard, 0239 Soft, 0240 External, 0241 Other // Reserved or User-defined 0242 }; 0243 0244 0245 } // namespace HighFive
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |