From 57601ae16dd8276946f0851cc199eb09e4211656 Mon Sep 17 00:00:00 2001 From: arkanoid87 Date: Sun, 10 Mar 2024 01:54:20 +0100 Subject: [PATCH] Update attributes.nim move `contains` declaration before `let attr_exists = name in h5attr` because declaration order matters when calling ` h5f.attrs["foo", T]` from inside a generic procedure --- src/nimhdf5/attributes.nim | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/nimhdf5/attributes.nim b/src/nimhdf5/attributes.nim index 24e3569..a6ce416 100644 --- a/src/nimhdf5/attributes.nim +++ b/src/nimhdf5/attributes.nim @@ -334,6 +334,11 @@ proc readStringAttribute(attr: H5Attr): string = doAssert err >= 0 result = buf_string +proc contains*(attr: H5Attributes, key: string): bool = + ## proc to check whether a given attribute with name `key` exists in the attribute + ## field of a group or dataset + result = attr.parent_id.existsAttribute(key) + proc read_attribute*[T](h5attr: H5Attributes, name: string, dtype: typedesc[T]): T = ## now implement reading of attributes ## finally still need a read_all attribute. This function only reads a single one, if @@ -396,11 +401,6 @@ proc `[]`*(h5attr: H5Attributes, name: string): DtypeKind = # attribute as an AnyKind value h5attr.attr_tab[name].dtypeAnyKind -proc contains*(attr: H5Attributes, key: string): bool = - ## proc to check whether a given attribute with name `key` exists in the attribute - ## field of a group or dataset - result = attr.parent_id.existsAttribute(key) - template withAttr*(h5attr: H5Attributes, name: string, actions: untyped) = ## convenience template to read and work with an attribute from the file and perform actions ## with that attribute, without having to manually check the data type of the attribute