-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add get_supplemental_attributes for components
- Loading branch information
1 parent
f0db36a
commit 3bdfd53
Showing
12 changed files
with
243 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
function iterate_instances( | ||
::Type{T}, | ||
data::Union{ComponentsByType, SupplementalAttributesByType}, | ||
filter_func::Union{Nothing, Function} = nothing, | ||
) where {T <: InfrastructureSystemsType} | ||
if isconcretetype(T) | ||
_components = get(data, T, nothing) | ||
if !isnothing(filter_func) && !isnothing(_components) | ||
_filter_func = x -> filter_func(x.second) | ||
_components = values(filter(_filter_func, _components)) | ||
end | ||
if isnothing(_components) | ||
iter = FlattenIteratorWrapper(T, Vector{Base.ValueIterator}([])) | ||
else | ||
iter = | ||
FlattenIteratorWrapper(T, Vector{Base.ValueIterator}([values(_components)])) | ||
end | ||
else | ||
types = [x for x in keys(data) if x <: T] | ||
if isnothing(filter_func) | ||
_components = [values(data[x]) for x in types] | ||
else | ||
_filter_func = x -> filter_func(x.second) | ||
_components = [values(filter(_filter_func, data[x])) for x in types] | ||
end | ||
iter = FlattenIteratorWrapper(T, _components) | ||
end | ||
|
||
@assert_op eltype(iter) == T | ||
return iter | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.