Skip to content

Commit

Permalink
Base.open method
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonOresten committed Oct 14, 2024
1 parent 84d0d04 commit 689d461
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/store/store.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ end

function Base.setindex!(store::ProteinStructureStore, value::ProteinStructure, key::AbstractString)
store.mode == "r" && error("$ProteinStructureStore object is read-only.")
key in keys(store) && delete!(store, key)
haskey(store, key) && delete!(store, key)
group = HDF5.create_group(store.file, key)
writeh5(group, value)
push!(store.keys, key)
Expand All @@ -92,14 +92,12 @@ end
Base.show(io::IO, store::ProteinStructureStore) = print(io, "$ProteinStructureStore(\"$(store.filename)\", $(store.mode))")
Base.show(io::IO, ::MIME"text/plain", store::ProteinStructureStore) = print(io, summary(store))

function ProteinStructureStore(f::Function, args...)
store = ProteinStructureStore(args...)
try
return f(store)
finally
close(store)
end
end
Base.open(::Type{ProteinStructureStore}, filename::AbstractString, args...) = ProteinStructureStore(filename, args...)

"""
ProteinStructureStore(f::Function, filename, mode="cw")
"""
ProteinStructureStore(f::Function, args...) = open(f, ProteinStructureStore, args...)

"""
serialize(filename::AbstractString, structures::AbstractVector{<:ProteinStructure})
Expand Down

0 comments on commit 689d461

Please sign in to comment.