Skip to content

Commit

Permalink
Move from . to _ as tag start, allow paramters to have "hidden" fields
Browse files Browse the repository at this point in the history
  • Loading branch information
nHackel committed Aug 23, 2023
1 parent 5f89470 commit d88b567
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
19 changes: 13 additions & 6 deletions src/AlgorithmPlan.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions src/StructTransforms.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit d88b567

Please sign in to comment.