Skip to content

Commit

Permalink
Update attributes.nim
Browse files Browse the repository at this point in the history
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
  • Loading branch information
arkanoid87 authored and Vindaar committed Mar 11, 2024
1 parent 4dc50f9 commit 05b422d
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/nimhdf5/attributes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 05b422d

Please sign in to comment.