Skip to content

Commit

Permalink
Add isopen(obj::HDF5File) (#399)
Browse files Browse the repository at this point in the history
* Add isopen(obj::HDF5File)
  • Loading branch information
ggggggggg authored and musm committed May 10, 2017
1 parent f79fc68 commit 037eb08
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/HDF5.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ using Compat: unsafe_convert, String
import Base:
==, close, convert, done, dump, eltype, endof, flush, getindex,
isempty, isvalid, length, names, ndims, next, parent, read,
setindex!, show, size, sizeof, start, write
setindex!, show, size, sizeof, start, write, isopen

export
# types
Expand Down Expand Up @@ -690,6 +690,13 @@ function close(obj::HDF5File)
nothing
end

"""
isopen(obj::HDF5File)
Returns `true` if `obj` has not been closed, `false` if it has been closed.
"""
isopen(obj::HDF5File) = obj.id != -1

for (h5type, h5func) in
((:(Union{HDF5Group, HDF5Dataset}), :h5o_close),
(:HDF5Attribute, :h5a_close))
Expand Down
2 changes: 2 additions & 0 deletions test/plain.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ using Compat.String
# Create a new file
fn = joinpath(tempdir(),"test.h5")
f = h5open(fn, "w")
@test isopen(f)
# Write scalars
f["Float64"] = 3.2
f["Int16"] = Int16(4)
Expand Down Expand Up @@ -107,6 +108,7 @@ using Compat.String
# Create a dataset designed to be deleted
f["deleteme"] = 17.2
close(f)
@test !isopen(f)
# Test the h5read/write interface, with attributes
W = copy(reshape(1:120, 15, 8))
Wa = Dict("a"=>1, "b"=>2)
Expand Down

0 comments on commit 037eb08

Please sign in to comment.