From 689d46189d4fbe148e2f427f323685aea578d494 Mon Sep 17 00:00:00 2001 From: AntonOresten Date: Tue, 15 Oct 2024 01:59:05 +0200 Subject: [PATCH] Base.open method --- src/store/store.jl | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/store/store.jl b/src/store/store.jl index 0834cfe..628fe07 100644 --- a/src/store/store.jl +++ b/src/store/store.jl @@ -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) @@ -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})