Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/src/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import AbstractFBCModels as A

A.accessors()

@test length(A.accessors()) == 35 #src
@test length(A.accessors()) == 37 #src

@test length(A.required_accessors()) == 11 #src
@test length(A.required_accessors()) == 13 #src

# You do not need to overload all of them (e.g., if you model does not have any
# genes you can completely omit all gene-related functions). The main required
Expand Down
28 changes: 22 additions & 6 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,12 @@ end
unimplemented(t::Type, x::Symbol) =
error("AbstractFBCModels interface method $x is not implemented for type $t")


"""
$(TYPEDSIGNATURES)

Provide a `methodswith`-style listing of accessors that the model implementors
may implement.

For typesystem reasons, the list **will not contain** methods for
[`load`](@ref) and [`filename_extensions`](@ref) that dispatch on type objects.
You should implement these as well.

See also [`required_accessors`](@ref) for the minimal list that must be implemented.
"""
function accessors()
ms = Method[]
Expand All @@ -48,9 +43,29 @@ function accessors()
methodswith(AbstractFBCModels.AbstractFBCModel, f, ms)
end
end

append!(ms, _type_accessors())
return ms
end

function _type_accessors()
# special case: some "accessors" take the Type argument instead of actual instance
ms = Method[]
for f in (AbstractFBCModels.load, AbstractFBCModels.filename_extensions)
for m in methods(f)
m.sig isa UnionAll || continue
# Deep magic: basically this matches on `f(::Type{A},...) where A<:AbstractFBCModel`
type_param = Base.unwrap_unionall(m.sig).parameters[2].parameters[1].ub
if type_param == AbstractFBCModels.AbstractFBCModel
push!(ms, m)
end
end
end

return ms
end


"""
$(TYPEDSIGNATURES)

Expand All @@ -70,6 +85,7 @@ function required_accessors()
for f in REQUIRED_ACCESSORS
methodswith(AbstractFBCModels.AbstractFBCModel, f, ms)
end
append!(ms, _type_accessors())
return ms
end

Expand Down
Loading