Skip to content

Commit

Permalink
add AutoVal struct so keywords can be incorporated later
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaqz committed Nov 23, 2023
1 parent c779d42 commit 6d6d765
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Dimensions/Dimensions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export name, label, dimnum, hasdim, hasselection, otherdims, commondims, combine
basetypeof, basedims, dimstride, dims2indices, slicedims, dimsmatch, comparedims, reducedims

export Dimension, IndependentDim, DependentDim, XDim, YDim, ZDim, TimeDim,
X, Y, Z, Ti, Dim, AnonDim, Coord, MergedLookup
X, Y, Z, Ti, Dim, AnonDim, Coord, MergedLookup, AutoVal

export @dim

Expand Down
20 changes: 19 additions & 1 deletion src/Dimensions/dimension.jl
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ const AllDims = Union{Symbol,Dimension,DimTuple,SymbolTuple,DimType,DimTypeTuple

# DimensionalData interface methods

struct AutoVal{T,K}
val::T
kw::K
end
val(av::AutoVal) = av.val

"""
rebuild(dim::Dimension, val) => Dimension
rebuild(dim::Dimension; val=val(dim)) => Dimension
Expand Down Expand Up @@ -329,8 +335,13 @@ Dim{:custom} Char['a', 'b', 'c']
"""
struct Dim{S,T} <: Dimension{T}
val::T
function Dim{S}(val; kw...) where {S}
if length(kw) > 0
val = AutoVal(val, values(kw))
end
new{S,typeof(val)}(val)
end
end
Dim{S}(val::T) where {S,T} = Dim{S,T}(val)
function Dim{S}(val::AbstractArray; kw...) where S
if length(kw) > 0
val = AutoLookup(val, values(kw))
Expand Down Expand Up @@ -393,6 +404,13 @@ function dimmacro(typ, supertype, name::String=string(typ))
quote
Base.@__doc__ struct $typ{T} <: $supertype{T}
val::T
function $typ(val; kw...)
if length(kw) > 0
val = AutoVal(val, values(kw))
end
new{typeof(val)}(val)
end
$typ{T}(val::T; kw...) where T = new(val::T)
end
function $typ(val::AbstractArray; kw...)
if length(kw) > 0
Expand Down
2 changes: 1 addition & 1 deletion src/LookupArrays/lookup_arrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ _check_ordered_cyclic(order::Unordered) = throw(ArgumentError("Cyclic lookups mu

function rebuild(l::Cyclic;
data=parent(l), order=order(l), span=span(l), sampling=sampling(l), metadata=metadata(l),
cycle=cycle(l), _cycle_status=cycle_status(l), kw...
cycle=cycle(l), cycle_status=cycle_status(l), kw...
)
Cyclic(data, order, span, sampling, metadata, cycle, cycle_status)
end
Expand Down

0 comments on commit 6d6d765

Please sign in to comment.