Skip to content

Commit

Permalink
dict interface for metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaqz committed Dec 12, 2019
1 parent 0c259be commit 420f549
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions src/metadata.jl
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
"""
Abstract type for dimension metadata wrappers.
"""
abstract type Metadata end
abstract type Metadata{K,V} <: AbstractDict{K,V} end

(::Type{T})() where T <: Metadata = T(Dict())

val(metadata::Metadata) = metadata.val

abstract type AbstractDimMetadata <: Metadata end
Base.get(metadata::Metadata, args...) = get(val(metadata), args...)
Base.getindex(metadata::Metadata, args...) = getindex(val(metadata), args...)
Base.setindex!(metadata::Metadata, args...) = setindex!(val(metadata), args...)
Base.keys(metadata::Metadata) = keys(val(metadata))
Base.iterate(metadata::Metadata, args...) = iterate(val(metadata), args...)
Base.IteratorSize(::Metadata{M}) where M = IteratorSize(M)
Base.IteratorEltype(::Metadata{M}) where M = IteratorEltype(M)
Base.eltype(::Metadata{M}) where M = eltype(M)
Base.length(metadata::Metadata) = length(val(metadata))

abstract type AbstractArrayMetadata <: Metadata end
abstract type AbstractDimMetadata{K,V} <: Metadata{K,V} end

struct ArrayMetadata{M} <: AbstractArrayMetadata
val::M
end
abstract type AbstractArrayMetadata{K,V} <: Metadata{K,V} end

struct DimMetadata{M} <: AbstractDimMetadata
val::M
struct ArrayMetadata{K,V} <: AbstractArrayMetadata{K,V}
val::Dict{K,V}
end

struct DimMetadata{K,V} <: AbstractDimMetadata{K,V}
val::Dict{K,V}
end

0 comments on commit 420f549

Please sign in to comment.