aboutsummaryrefslogtreecommitdiff
path: root/julia
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2024-01-19 09:52:01 +0100
committerThomas White <taw@physics.org>2024-02-06 16:59:35 +0100
commit9a907d58a931472eb1178c42bfa1e7629e30ab00 (patch)
tree5d7e5e31e72960b82dfe321c4b081dbd19cd1bea /julia
parent1b4fdfa5cc1ab4fe9a1cdcbb0bf1602834eaec13 (diff)
Ownership for Crystal.Cell
Diffstat (limited to 'julia')
-rw-r--r--julia/CrystFEL/src/crystal.jl35
-rw-r--r--julia/CrystFEL/src/image.jl2
2 files changed, 35 insertions, 2 deletions
diff --git a/julia/CrystFEL/src/crystal.jl b/julia/CrystFEL/src/crystal.jl
index eba7a615..38204a62 100644
--- a/julia/CrystFEL/src/crystal.jl
+++ b/julia/CrystFEL/src/crystal.jl
@@ -10,6 +10,7 @@ mutable struct InternalCrystal end
mutable struct Crystal
internalptr::Ptr{InternalCrystal}
+ cell
end
@@ -39,7 +40,7 @@ function Crystal(cell::UnitCell; profileradius=2e6, mosaicity=0)
Cvoid, (Ptr{InternalCrystal},Cdouble),
out, mosaicity)
- cr = Crystal(out)
+ cr = Crystal(out, nothing)
finalizer(cr) do x
ccall((:crystal_free, libcrystfel), Cvoid, (Ptr{InternalCrystal},),
@@ -67,4 +68,36 @@ function Base.setproperty!(cr::Crystal, name::Symbol, val)
end
+function getcell(cr)
+ out = @ccall libcrystfel.crystal_relinquish_cell(cr.internalptr::Ptr{InternalCrystal})::Ptr{InternalUnitCell}
+ if getfield(cr, :cell) === nothing || getfield(cr, :cell).internalptr != out
+ if out != C_NULL
+ setfield!(cr, :cell, UnitCell(out))
+ else
+ setfield!(cr, :cell, nothing)
+ end
+ end
+ return getfield(cr, :cell)
+end
+
+
+function Base.getproperty(cr::Crystal, name::Symbol)
+ if name === :internalptr
+ getfield(cr, :internalptr)
+ elseif name === :cell
+ return getcell(cr)
+ end
+end
+
+
+function Base.show(io::IO, cr::Crystal)
+ write(io, "Crystal(")
+ if cr.cell !== nothing
+ show(io, cr.cell)
+ else
+ write(io, "no cell")
+ end
+ write(io, ")")
+end
+
end # of module
diff --git a/julia/CrystFEL/src/image.jl b/julia/CrystFEL/src/image.jl
index 3384f0c9..5740dfaf 100644
--- a/julia/CrystFEL/src/image.jl
+++ b/julia/CrystFEL/src/image.jl
@@ -76,7 +76,7 @@ function makecrystallist(image, listptr, n)
if n !== nothing
cr = getfield(image, :crystals)[n]
else
- cr = Crystal(pairptr.crystal)
+ cr = Crystal(pairptr.crystal, nothing)
end
if pairptr.reflist == C_NULL