Module: HDF5::Hierarchy
Instance Method Summary collapse
- #create_hard_link(target, name) ⇒ Object
- #create_soft_link(target, name) ⇒ Object
- #delete(name) ⇒ Object
- #each_key(&block) ⇒ Object
- #key?(name) ⇒ Boolean
- #keys ⇒ Object
- #link_info(name) ⇒ Object
- #move(source, destination) ⇒ Object
- #open_dataset(name) ⇒ Object
- #require_group(path) ⇒ Object
Instance Method Details
#create_hard_link(target, name) ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/hdf5/hierarchy.rb', line 53 def create_hard_link(target, name) status = HDF5::FFI.H5Lcreate_hard(hdf5_id, target, hdf5_id, name, HDF5::DEFAULT_PROPERTY_LIST, HDF5::DEFAULT_PROPERTY_LIST) raise HDF5::Error, "Failed to create hard link: #{name}" if status < 0 self end |
#create_soft_link(target, name) ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/hdf5/hierarchy.rb', line 61 def create_soft_link(target, name) status = HDF5::FFI.H5Lcreate_soft(target, hdf5_id, name, HDF5::DEFAULT_PROPERTY_LIST, HDF5::DEFAULT_PROPERTY_LIST) raise HDF5::Error, "Failed to create soft link: #{name}" if status < 0 self end |
#delete(name) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/hdf5/hierarchy.rb', line 46 def delete(name) status = HDF5::FFI.H5Ldelete(hdf5_id, name, HDF5::DEFAULT_PROPERTY_LIST) raise HDF5::Error, "Failed to delete link: #{name}" if status < 0 self end |
#each_key(&block) ⇒ Object
7 8 9 10 11 12 |
# File 'lib/hdf5/hierarchy.rb', line 7 def each_key(&block) return enum_for(__method__) unless block keys.each(&block) self end |
#key?(name) ⇒ Boolean
39 40 41 42 43 44 |
# File 'lib/hdf5/hierarchy.rb', line 39 def key?(name) exists = HDF5::FFI.H5Lexists(hdf5_id, name, HDF5::DEFAULT_PROPERTY_LIST) raise HDF5::Error, "Failed to check link existence: #{name}" if exists.negative? exists.positive? end |
#keys ⇒ Object
3 4 5 |
# File 'lib/hdf5/hierarchy.rb', line 3 def keys list_entries end |
#link_info(name) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/hdf5/hierarchy.rb', line 69 def link_info(name) info = HDF5::FFI::MiV == 10 ? HDF5::FFI::H5LInfoT.new : HDF5::FFI::H5LInfo2T.new status = if HDF5::FFI::MiV == 10 HDF5::FFI.H5Lget_info(hdf5_id, name, info, HDF5::DEFAULT_PROPERTY_LIST) else HDF5::FFI.H5Lget_info2(hdf5_id, name, info, HDF5::DEFAULT_PROPERTY_LIST) end raise HDF5::Error, "Failed to get link information: #{name}" if status < 0 type = info[:type] return { type: :hard } if type == :H5L_TYPE_HARD size = info[:u][:val_size] buffer = ::FFI::MemoryPointer.new(:char, size) status = HDF5::FFI.H5Lget_val(hdf5_id, name, buffer, size, HDF5::DEFAULT_PROPERTY_LIST) raise HDF5::Error, "Failed to get link value: #{name}" if status < 0 raw = buffer.read_bytes(size) return { type: :soft, target: raw.delete_suffix("\0") } if type == :H5L_TYPE_SOFT if type == :H5L_TYPE_EXTERNAL filename, path = raw.byteslice(1..).split("\0", 2) return { type: :external, filename:, path: path&.delete_suffix("\0") } end raise UnsupportedTypeError, "Unsupported link type: #{type}" end |
#move(source, destination) ⇒ Object
97 98 99 100 101 102 103 |
# File 'lib/hdf5/hierarchy.rb', line 97 def move(source, destination) status = HDF5::FFI.H5Lmove(hdf5_id, source, hdf5_id, destination, HDF5::DEFAULT_PROPERTY_LIST, HDF5::DEFAULT_PROPERTY_LIST) raise HDF5::Error, "Failed to move link: #{source}" if status < 0 self end |
#open_dataset(name) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/hdf5/hierarchy.rb', line 27 def open_dataset(name) object = self[name] raise HDF5::Error, "Object is not a dataset: #{name}" unless object.is_a?(Dataset) return object unless block_given? begin yield object ensure object.close end end |
#require_group(path) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/hdf5/hierarchy.rb', line 14 def require_group(path) path.split('/').reject(&:empty?).inject(self) do |parent, name| if parent.key?(name) child = parent[name] raise HDF5::Error, "Existing object is not a group: #{name}" unless child.is_a?(Group) child else parent.create_group(name) end end end |