RMF
Object.h
Go to the documentation of this file.
1 /**
2  * \file RMF/HDF5/Object.h
3  * \brief Handle read/write of Model data from/to files.
4  *
5  * Copyright 2007-2022 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef RMF_HDF5_OBJECT_H
10 #define RMF_HDF5_OBJECT_H
11 
12 #include "RMF/config.h"
13 #include "types.h"
14 #include "handle.h"
15 #include "infrastructure_macros.h"
16 #include <hdf5.h>
17 #include <memory>
18 
19 RMF_ENABLE_WARNINGS
20 
21 namespace RMF {
22 namespace HDF5 {
23 
24 class File;
25 
26 /** Wrap an HDF5 Object. See
27  \external{https://support.hdfgroup.org/HDF5/doc/RM/RM_H5O.html,
28  the HDF5 manual} for more information.
29  */
30 class RMFEXPORT Object {
31  std::shared_ptr<SharedHandle> h_;
32 #ifndef SWIG
33  protected:
34  Object(std::shared_ptr<SharedHandle> h);
35  // silliness
36  friend class Group;
37  std::shared_ptr<SharedHandle> get_shared_handle() const { return h_; }
38  void open(std::shared_ptr<SharedHandle> h) { h_ = h; }
39  Object() {}
40 #else
41  private:
42  Object();
43 #endif
44  public:
45  std::string get_name() const {
46  char buf[10000];
47  RMF_HDF5_CALL(H5Iget_name(h_->get_hid(), buf, 10000));
48  return std::string(buf);
49  }
50 
51  //! Get an object for the file containing the object
52  File get_file() const;
53 
54  RMF_SHOWABLE(Object, "Object " << get_name());
55 
56  hid_t get_handle() const {
57  RMF_USAGE_CHECK(h_, "No handle in uninitialized Object");
58  return h_->get_hid();
59  }
60 
61 #if !defined(RMF_DOXYGEN) && !defined(SWIG)
62  typedef void (Object::*bool_type)() const;
63  void this_type_does_not_support_comparisons() const {}
64  operator bool_type() const {
65  return h_ ? &Object::this_type_does_not_support_comparisons : 0;
66  }
67 #endif
68 };
69 
70 #ifndef RMF_DOXYGEN
71 /** \ingroup hdf5 */
72 typedef std::vector<Object> Objects;
73 #ifndef SWIG
74 // work around issues with the bool_type being outputable
75 inline std::ostream& operator<<(std::ostream& out, const Object& o) {
76  out << "Object " << o.get_name();
77  return out;
78 }
79 #endif
80 #endif
81 } /* namespace HDF5 */
82 } /* namespace RMF */
83 
84 RMF_DISABLE_WARNINGS
85 
86 #endif /* RMF_HDF5_OBJECT_H */
Various general useful macros for IMP.
Handle read/write of Model data from/to files.
#define RMF_HDF5_CALL(v)
Include all non-deprecated headers in RMF.HDF5.
Handle read/write of Model data from/to files.