Back to home page

EIC code displayed by LXR

 
 

    


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

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 <ctime>
0012 
0013 #include <H5Ipublic.h>
0014 #include <H5Opublic.h>
0015 
0016 #include "bits/H5_definitions.hpp"
0017 #include "bits/H5Friends.hpp"
0018 
0019 namespace HighFive {
0020 
0021 ///
0022 /// \brief Enum of the types of objects (H5O api)
0023 ///
0024 enum class ObjectType {
0025     File,
0026     Group,
0027     UserDataType,
0028     DataSpace,
0029     Dataset,
0030     Attribute,
0031     Other  // Internal/custom object type
0032 };
0033 
0034 namespace detail {
0035 /// \brief Internal hack to create an `Object` from an ID.
0036 ///
0037 /// WARNING: Creating an Object from an ID has implications w.r.t. the lifetime of the object
0038 ///          that got passed via its ID. Using this method careless opens up the suite of issues
0039 ///          related to C-style resource management, including the analog of double free, dangling
0040 ///          pointers, etc.
0041 ///
0042 /// NOTE: This is not part of the API and only serves to work around a compiler issue in GCC which
0043 ///       prevents us from using `friend`s instead. This function should only be used for internal
0044 ///       purposes. The problematic construct is:
0045 ///
0046 ///           template<class Derived>
0047 ///           friend class SomeCRTP<Derived>;
0048 ///
0049 /// \private
0050 Object make_object(hid_t hid);
0051 }  // namespace detail
0052 
0053 
0054 class Object {
0055   public:
0056     // move constructor, reuse hid
0057     Object(Object&& other) noexcept;
0058 
0059     // decrease reference counter
0060     ~Object();
0061 
0062     ///
0063     /// \brief isValid
0064     /// \return true if current Object is a valid HDF5Object
0065     ///
0066     bool isValid() const noexcept;
0067 
0068     ///
0069     /// \brief getId
0070     /// \return internal HDF5 id to the object
0071     ///  provided for C API compatibility
0072     ///
0073     hid_t getId() const noexcept;
0074 
0075     ///
0076     /// \brief Retrieve several infos about the current object (address, dates, etc)
0077     ///
0078     ObjectInfo getInfo() const;
0079 
0080     ///
0081     /// \brief Gets the fundamental type of the object (dataset, group, etc)
0082     /// \exception ObjectException when the _hid is negative or the type
0083     ///     is custom and not registered yet
0084     ///
0085     ObjectType getType() const;
0086 
0087     // Check if refer to same object
0088     bool operator==(const Object& other) const noexcept {
0089         return _hid == other._hid;
0090     }
0091 
0092   protected:
0093     // empty constructor
0094     Object();
0095 
0096     // copy constructor, increase reference counter
0097     Object(const Object& other);
0098 
0099     // Init with an low-level object id
0100     explicit Object(hid_t);
0101 
0102     // Copy-Assignment operator
0103     Object& operator=(const Object& other);
0104 
0105     hid_t _hid;
0106 
0107   private:
0108     friend Object detail::make_object(hid_t);
0109     friend class Reference;
0110     friend class CompoundType;
0111 
0112 #if HIGHFIVE_HAS_FRIEND_DECLARATIONS
0113     template <typename Derivate>
0114     friend class NodeTraits;
0115     template <typename Derivate>
0116     friend class AnnotateTraits;
0117     template <typename Derivate>
0118     friend class PathTraits;
0119 #endif
0120 };
0121 
0122 
0123 ///
0124 /// \brief A class for accessing hdf5 objects info
0125 ///
0126 class ObjectInfo {
0127   public:
0128     /// \brief Retrieve the address of the object (within its file)
0129     /// \deprecated Deprecated since HighFive 2.2. Soon supporting VOL tokens
0130     H5_DEPRECATED("Deprecated since HighFive 2.2. Soon supporting VOL tokens")
0131     haddr_t getAddress() const noexcept;
0132 
0133     /// \brief Retrieve the number of references to this object
0134     size_t getRefCount() const noexcept;
0135 
0136     /// \brief Retrieve the object's creation time
0137     time_t getCreationTime() const noexcept;
0138 
0139     /// \brief Retrieve the object's last modification time
0140     time_t getModificationTime() const noexcept;
0141 
0142   protected:
0143 #if (H5Oget_info_vers < 3)
0144     H5O_info_t raw_info;
0145 #else
0146     // Use compat H5O_info1_t while getAddress() is supported (deprecated)
0147     H5O_info1_t raw_info;
0148 #endif
0149 
0150     friend class Object;
0151 };
0152 
0153 }  // namespace HighFive
0154 
0155 #include "bits/H5Object_misc.hpp"