From d88b56724a9abdad1df0969ca6a9b56cf4aba571 Mon Sep 17 00:00:00 2001 From: nHackel Date: Wed, 23 Aug 2023 12:29:52 +0000 Subject: [PATCH] Move from . to _ as tag start, allow paramters to have "hidden" fields --- src/AlgorithmPlan.jl | 19 +++++++++++++------ src/StructTransforms.jl | 10 +++++----- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/AlgorithmPlan.jl b/src/AlgorithmPlan.jl index 914542f..1411bb7 100644 --- a/src/AlgorithmPlan.jl +++ b/src/AlgorithmPlan.jl @@ -5,6 +5,8 @@ abstract type AbstractPlanListener end abstract type TransientListener <: AbstractPlanListener end abstract type SerializableListener <: AbstractPlanListener end +const LISTENER_TAG = "_listener" + mutable struct RecoPlan{T<:Union{AbstractImageReconstructionParameter, AbstractImageReconstructionAlgorithm}} parent::Union{Nothing, RecoPlan} values::Dict{Symbol, Any} @@ -14,7 +16,7 @@ mutable struct RecoPlan{T<:Union{AbstractImageReconstructionParameter, AbstractI dict = Dict{Symbol, Any}() listeners = Dict{Symbol, Vector{AbstractPlanListener}}() setProperties = Dict{Symbol, Bool}() - for field in fieldnames(T) + for field in filter(f -> !startswith(string(f), "_"), fieldnames(T)) dict[field] = missing listeners[field] = AbstractPlanListener[] setProperties[field] = false @@ -248,7 +250,7 @@ function addDictValue!(dict, value::RecoPlan) end end if !isempty(listenerDict) - dict[".listener"] = listenerDict + dict[LISTENER_TAG] = listenerDict end end return dict @@ -359,13 +361,18 @@ function loadPlanValue(t::Union, value::Dict, modDict) type = isnothing(idx) ? t : types[idx] return loadPlanValue(type, value[VALUE_TAG], modDict) end -loadPlanValue(t::DataType, value::Dict, modDict) = fromTOML(specializeType(t, value, modDict), value) +function loadPlanValue(t::DataType, value::Dict, modDict) + s = specializeType(t, value, modDict) + @show s + @show value + fromTOML(s, value) +end loadPlanValue(t, value, modDict) = fromTOML(t, value) function tomlType(dict::Dict, modDict; prefix::String = "") - if haskey(dict, ".$(prefix)module") && haskey(dict, ".$(prefix)type") - mod = dict[".$(prefix)module"] - type = dict[".$(prefix)type"] + if haskey(dict, "_$(prefix)module") && haskey(dict, "_$(prefix)type") + mod = dict["_$(prefix)module"] + type = dict["_$(prefix)type"] if haskey(modDict, mod) && haskey(modDict[mod], type) return modDict[mod][type] end diff --git a/src/StructTransforms.jl b/src/StructTransforms.jl index c63bbdf..a062574 100644 --- a/src/StructTransforms.jl +++ b/src/StructTransforms.jl @@ -1,11 +1,11 @@ export toTOML, toDict, toDict!, toDictValue, toKwargs, toKwargs!, fromKwargs # TODO adapt tomlType -const MODULE_TAG = ".module" -const TYPE_TAG = ".type" -const VALUE_TAG = ".value" -const UNION_TYPE_TAG = ".uniontype" -const UNION_MODULE_TAG = ".unionmodule" +const MODULE_TAG = "_module" +const TYPE_TAG = "_type" +const VALUE_TAG = "_value" +const UNION_TYPE_TAG = "_uniontype" +const UNION_MODULE_TAG = "_unionmodule" function toTOML(fileName::AbstractString, value) open(fileName, "w") do io