Back to home page

EIC code displayed by LXR

 
 

    


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

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 <iostream>
0012 
0013 #include "../H5Exception.hpp"
0014 #include "../H5Utility.hpp"
0015 #include "h5i_wrapper.hpp"
0016 
0017 namespace HighFive {
0018 namespace detail {
0019 inline Object make_object(hid_t hid) {
0020     return Object(hid);
0021 }
0022 }  // namespace detail
0023 
0024 
0025 inline Object::Object()
0026     : _hid(H5I_INVALID_HID) {}
0027 
0028 inline Object::Object(hid_t hid)
0029     : _hid(hid) {}
0030 
0031 inline Object::Object(const Object& other)
0032     : _hid(other._hid) {
0033     if (other.isValid()) {
0034         detail::h5i_inc_ref(_hid);
0035     }
0036 }
0037 
0038 inline Object::Object(Object&& other) noexcept
0039     : _hid(other._hid) {
0040     other._hid = H5I_INVALID_HID;
0041 }
0042 
0043 inline Object& Object::operator=(const Object& other) {
0044     if (this != &other) {
0045         if ((*this).isValid()) {
0046             detail::h5i_dec_ref(_hid);
0047         }
0048 
0049         _hid = other._hid;
0050         if (other.isValid()) {
0051             detail::h5i_inc_ref(_hid);
0052         }
0053     }
0054     return *this;
0055 }
0056 
0057 inline Object::~Object() {
0058     if (isValid()) {
0059         if (detail::nothrow::h5i_dec_ref(_hid) < 0) {
0060             HIGHFIVE_LOG_ERROR("Failed to decrease reference count of HID");
0061         }
0062     }
0063 }
0064 
0065 inline bool Object::isValid() const noexcept {
0066     return (_hid > 0) && (detail::nothrow::h5i_is_valid(_hid) > 0);
0067 }
0068 
0069 inline hid_t Object::getId() const noexcept {
0070     return _hid;
0071 }
0072 
0073 static inline ObjectType _convert_object_type(const H5I_type_t& h5type) {
0074     switch (h5type) {
0075     case H5I_FILE:
0076         return ObjectType::File;
0077     case H5I_GROUP:
0078         return ObjectType::Group;
0079     case H5I_DATATYPE:
0080         return ObjectType::UserDataType;
0081     case H5I_DATASPACE:
0082         return ObjectType::DataSpace;
0083     case H5I_DATASET:
0084         return ObjectType::Dataset;
0085     case H5I_ATTR:
0086         return ObjectType::Attribute;
0087     default:
0088         return ObjectType::Other;
0089     }
0090 }
0091 
0092 inline ObjectType Object::getType() const {
0093     // H5Iget_type is a very lightweight func which extracts the type from the id
0094     return _convert_object_type(detail::h5i_get_type(_hid));
0095 }
0096 
0097 inline ObjectInfo Object::getInfo() const {
0098     ObjectInfo info;
0099 #if (H5Oget_info_vers < 3)
0100     if (H5Oget_info(_hid, &info.raw_info) < 0) {
0101 #else
0102     if (H5Oget_info1(_hid, &info.raw_info) < 0) {
0103 #endif
0104         HDF5ErrMapper::ToException<ObjectException>("Unable to obtain info for object");
0105     }
0106     return info;
0107 }
0108 
0109 inline haddr_t ObjectInfo::getAddress() const noexcept {
0110     return raw_info.addr;
0111 }
0112 inline size_t ObjectInfo::getRefCount() const noexcept {
0113     return raw_info.rc;
0114 }
0115 inline time_t ObjectInfo::getCreationTime() const noexcept {
0116     return raw_info.btime;
0117 }
0118 inline time_t ObjectInfo::getModificationTime() const noexcept {
0119     return raw_info.mtime;
0120 }
0121 
0122 
0123 }  // namespace HighFive