@@ -17,7 +17,14 @@ for f in (:enumerate, :length, :lastindex)
1717 end
1818end
1919
20- Base. getindex (w:: WriteOnceReadMany , i:: Union{Int, INDEX_TYPE, Symbol} ) = getindex (w. _raw_data, i)
20+ Base. getindex (w:: WriteOnceReadMany , i:: Union{Integer,Symbol} ) = getindex (w. _raw_data, i)
21+ Base. get (w:: WriteOnceReadMany{<:Dict} , a, b) = get (w. _raw_data, a, b)
22+
23+ # Only define setindex! for Dicts, and throw an error if the key already exists
24+ function Base. setindex! (w:: DynamicQuantities.WriteOnceReadMany{<:Dict} , i, s:: Symbol )
25+ haskey (w. _raw_data, s) && throw (" Unit $s already exists at index $(w[s]) " )
26+ setindex! (w. _raw_data, i, s)
27+ end
2128
2229Base. iterate (w:: WriteOnceReadMany ) = iterate (w. _raw_data)
2330Base. iterate (w:: WriteOnceReadMany , i:: Int ) = iterate (w. _raw_data, i)
@@ -33,10 +40,3 @@ for f in (:findfirst, :filter)
3340 end
3441end
3542
36- Base. setindex! (w:: DynamicQuantities.WriteOnceReadMany{Dict{Symbol, INDEX_TYPE}} , i:: Int , s:: Symbol ) = setindex! (w, INDEX_TYPE (i), s)
37- function Base. setindex! (w:: DynamicQuantities.WriteOnceReadMany{Dict{Symbol, T}} , i:: T , s:: Symbol ) where T <: Union{Int, INDEX_TYPE}
38- haskey (w. _raw_data, s) && throw (" Unit $s already exists at index $(w[s]) " )
39- setindex! (w. _raw_data, i, s)
40- end
41-
42- Base. get (w:: WriteOnceReadMany{Dict{Symbol, INDEX_TYPE}} , a, b) = get (w. _raw_data, a, b)
0 commit comments