Skip to content

Commit

Permalink
no need for inner constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander-Barth committed Nov 16, 2023
1 parent e58ce15 commit 3e108fd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 30 deletions.
30 changes: 30 additions & 0 deletions src/dataset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,36 @@ function defmode(ds::Dataset)
end
end



function NCDataset(ncid::Integer,
iswritable::Bool,
isdefmode::Ref{Bool};
parentdataset = nothing)

function _finalize(ds)
# only close open root group
if (ds.ncid != -1) && (ds.parentdataset == nothing)
close(ds)
end
end

ds = NCDataset{typeof(parentdataset)}(
parentdataset,
ncid,
iswritable,
isdefmode,
Dict{String,String}())

if !iswritable
initboundsmap!(ds)
end

finalizer(_finalize, ds)
return ds
end


############################################################
# High-level
############################################################
Expand Down
30 changes: 0 additions & 30 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,37 +35,7 @@ mutable struct NCDataset{TDS} <: AbstractNCDataset where TDS <: Union{AbstractNC
# mapping between variables related via the bounds attribute
# It is only used for read-only datasets to improve performance
_boundsmap::Dict{String,String}
function NCDataset(ncid::Integer,
iswritable::Bool,
isdefmode::Ref{Bool};
parentdataset = nothing,
)

function _finalize(ds)
#@debug begin
# ccall(:jl_, Cvoid, (Any,), "finalize $ncid $timeid \n")
#end
# only close open root group
if (ds.ncid != -1) && (ds.parentdataset == nothing)
close(ds)
end
end
ds = new{typeof(parentdataset)}()
ds.parentdataset = parentdataset
ds.ncid = ncid
ds.iswritable = iswritable
ds.isdefmode = isdefmode
ds._boundsmap = Dict{String,String}()
if !iswritable
initboundsmap!(ds)
end
#timeid = Dates.now()
#@debug "add finalizer $ncid $(timeid)"
finalizer(_finalize, ds)
return ds
end
end

"Alias to `NCDataset`"
const Dataset = NCDataset

0 comments on commit 3e108fd

Please sign in to comment.