Skip to content
Snippets Groups Projects
Commit eade113f authored by Florian Atteneder's avatar Florian Atteneder
Browse files

make ObjectCache typestable

parent 955d5258
No related branches found
No related tags found
1 merge request!31Draft: refactor mesh infrastructure
export ObjectCache
struct ObjectCache{T_Key,T_Object}
struct ObjectCache{T_Key,T_Object,T_Blueprint}
cache::Dict{T_Key,T_Object}
blueprint::Function
blueprint::T_Blueprint
function ObjectCache{T_Key,T_Object}(blueprint::Function) where {T_Key,T_Object}
function ObjectCache{T_Key,T_Object}(blueprint::T_Blueprint) where {T_Key,T_Object,T_Blueprint}
@assert length(methods(blueprint, [T_Key])) > 0 """
`blueprint` must accept argument `key::$T_Key`
"""
return new{T_Key,T_Object}(Dict{T_Key,T_Object}(), blueprint)
return new{T_Key,T_Object,T_Blueprint}(Dict{T_Key,T_Object}(), blueprint)
end
end
function Base.getindex(c::ObjectCache{T_Key,T_Object}, key::T_Key) where {T_Key,T_Object}
function Base.getindex(c::ObjectCache{T_Key,T_Object,T_Blueprint}, key::T_Key) where {T_Key,T_Object,T_Blueprint}
obj = get(c.cache, key, nothing)
!isnothing(obj) && return obj
obj = c.blueprint(key)::T_Object
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment