Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/highfive/bits/H5Object_misc.hpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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