@@ -21,8 +21,6 @@ using FillArrays: Zeros
2121
2222using Base64: base64encode
2323
24- import Base: close, isopen, show
25-
2624using VTKBase:
2725 VTKBase,
2826 VTKCellTypes, # cell type definitions as in vtkCellType.h
@@ -50,7 +48,7 @@ const HeaderType = UInt64 # should be UInt32 or UInt64
5048"""
5149 VTKFile
5250
53- Abstract type describing a VTK file that may be written using [`vtk_save `](@ref).
51+ Abstract type describing a VTK file that may be written using [`close `](@ref).
5452"""
5553abstract type VTKFile end
5654
@@ -104,8 +102,10 @@ struct DatasetFile <: VTKFile
104102 end
105103end
106104
107- DatasetFile (dtype, xdoc:: XMLDocument , fname:: AbstractString , args... ; kwargs... ) =
105+ function DatasetFile (dtype, xdoc:: XMLDocument , fname:: AbstractString , args... ; kwargs... )
106+ finalizer (LightXML. free, xdoc)
108107 DatasetFile (xdoc, add_extension (fname, dtype), xml_name (dtype), args... ; kwargs... )
108+ end
109109
110110function data_format (vtk:: DatasetFile )
111111 if vtk. appended
@@ -117,24 +117,39 @@ function data_format(vtk::DatasetFile)
117117 end
118118end
119119
120- function show (io:: IO , vtk:: DatasetFile )
120+ function Base . show (io:: IO , vtk:: DatasetFile )
121121 open_str = isopen (vtk) ? " open" : " closed"
122122 print (io, " VTK file '$(vtk. path) ' ($(vtk. grid_type) file, $open_str )" )
123123end
124124
125125"""
126- close(vtk::VTKFile)
126+ Base. close(vtk::VTKFile) -> Vector{String}
127127
128128Write and close VTK file.
129+
130+ Returns a list of paths pointing to the written VTK files (typically just one file, but can
131+ be more for e.g. `MultiblockFile`).
132+
133+ ---
134+
135+ Base.close(vtm::MultiblockFile) -> Vector{String}
136+
137+ Save and close multiblock file (`.vtm`).
138+ The VTK files included in the multiblock file are also saved.
129139"""
130- close (vtk:: VTKFile ) = free (vtk. xdoc)
140+ Base. close (vtk:: VTKFile ) = vtk_save (vtk) # for backwards compatibility, the actual implementation is in vtk_save (which still works)
141+
142+ # Free LightXML memory. Note that this is also called when an xdoc object is finalised, but
143+ # it seems to be OK to call `free` multiple times.
144+ # After calling this, the VTK file is considered as closed (see `isopen` below).
145+ close_xml (vtk:: VTKFile ) = LightXML. free (vtk. xdoc)
131146
132147"""
133- isopen(vtk::VTKFile)
148+ Base. isopen(vtk::VTKFile)
134149
135150Check if VTK file is still being written.
136151"""
137- isopen (vtk:: VTKFile ) = (vtk. xdoc. ptr != C_NULL )
152+ Base . isopen (vtk:: VTKFile ) = (vtk. xdoc. ptr != C_NULL )
138153
139154# Add a default extension to the filename, unless the user have already given
140155# the correct one.
@@ -201,7 +216,7 @@ for func in (:vtk_grid, :pvtk_grid, :vtk_multiblock, :paraview_collection,
201216 try
202217 f (vtk)
203218 finally
204- outfiles = vtk_save (vtk)
219+ outfiles = close (vtk)
205220 end
206221 outfiles :: Vector{String}
207222 end
0 commit comments