RMF
ConstGroup.h
Go to the documentation of this file.
1 /**
2  * \file RMF/HDF5/ConstGroup.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_CONST_GROUP_H
10 #define RMF_HDF5_CONST_GROUP_H
11 
12 #include "RMF/config.h"
13 #include "Object.h"
14 #include "DataSetD.h"
15 #include "ConstAttributes.h"
17 
18 RMF_ENABLE_WARNINGS namespace RMF {
19  namespace HDF5 {
20 
21  typedef ConstAttributes<Object> ConstGroupAttributes;
22 #ifndef RMF_DOXYGEN
23  typedef std::vector<ConstGroupAttributes> ConstGroupAttributesList;
24 #endif
25 
26  /** Wrap an HDF5 Group. See
27  \external{https://docs.hdfgroup.org/releases/hdf5/v1_14/v1_14_4/documentation/doxygen/group___h5_g.html,
28  the HDF5 manual} for more information.
29  */
30  class RMFEXPORT ConstGroup : public ConstAttributes<Object> {
31  typedef ConstAttributes<Object> P;
32  friend class ConstFile;
33  unsigned int get_number_of_links() const {
34  H5G_info_t info;
35  RMF_HDF5_CALL(H5Gget_info(get_handle(), &info));
36  unsigned int n = info.nlinks;
37  return n;
38  }
39 #ifndef SWIG
40  protected:
41  ConstGroup(std::shared_ptr<SharedHandle> h);
42 #endif
43  public:
44  ConstGroup() {};
45  RMF_SHOWABLE(ConstGroup, "Group " << get_name());
46 
47  // create from an existing group
48  ConstGroup(ConstGroup parent, std::string name);
49  template <class TypeTraits, unsigned int D>
50  ConstDataSetD<TypeTraits, D> get_child_data_set(std::string name) const {
52  return ConstDataSetD<TypeTraits, D>(get_shared_handle(), name, props);
53  }
54  template <class TypeTraits, unsigned int D>
55  ConstDataSetD<TypeTraits, D> get_child_data_set(
56  std::string name, DataSetAccessPropertiesD<TypeTraits, D> props) const {
57  return ConstDataSetD<TypeTraits, D>(get_shared_handle(), name, props);
58  }
59 
60 #define RMF_HDF5_DATA_SET_CONST_METHODS_D( \
61  lcname, UCName, PassValue, ReturnValue, PassValues, ReturnValues, D) \
62  ConstDataSetD<UCName##Traits, D> get_child_##lcname##_data_set_##D##d( \
63  std::string name, \
64  DataSetAccessPropertiesD<UCName##Traits, D> props) const { \
65  return get_child_data_set<UCName##Traits, D>(name, props); \
66  } \
67  ConstDataSetD<UCName##Traits, D> get_child_##lcname##_data_set_##D##d( \
68  std::string name) const { \
69  return get_child_data_set<UCName##Traits, D>(name); \
70  }
71 
72 #define RMF_HDF5_DATA_SET_CONST_METHODS(lcname, UCName, PassValue, \
73  ReturnValue, PassValues, ReturnValues) \
74  RMF_HDF5_DATA_SET_CONST_METHODS_D(lcname, UCName, PassValue, ReturnValue, \
75  PassValues, ReturnValues, 1); \
76  RMF_HDF5_DATA_SET_CONST_METHODS_D(lcname, UCName, PassValue, ReturnValue, \
77  PassValues, ReturnValues, 2); \
78  RMF_HDF5_DATA_SET_CONST_METHODS_D(lcname, UCName, PassValue, ReturnValue, \
79  PassValues, ReturnValues, 3)
80 
81  /** \name Untemplated methods
82  When using Python, you must call the non-templated methods listed
83  below.
84  @{
85  */
86  RMF_HDF5_FOREACH_TYPE(RMF_HDF5_DATA_SET_CONST_METHODS);
87  /** @} */
88 
89  unsigned int get_number_of_children() const;
90  std::string get_child_name(unsigned int i) const;
91  bool get_has_child(std::string name) const;
92  bool get_child_is_group(unsigned int i) const;
93  bool get_child_is_data_set(unsigned int i) const;
94  ConstGroup get_child_group(unsigned int i) const;
95 
96  //! get child group with given name without checks
97  //! - verify group exists using get_has_child()
98  //! and that it's a group using get_child_is_group()
99  ConstGroup get_child_group(std::string name) const;
100 
101  //! returns true if child is group without checks
102  //! - verify child exists using get_has_child()
103  bool get_child_is_group(std::string name) const;
104  };
105 
106  } /* namespace HDF5 */
107 } /* namespace RMF */
108 
109 RMF_DISABLE_WARNINGS
110 
111 #endif /* RMF_HDF5_CONST_GROUP_H */
Handle read/write of Model data from/to files.
Handle read/write of Model data from/to files.
#define RMF_HDF5_CALL(v)
Handle read/write of Model data from/to files.
Handle read/write of Model data from/to files.