-
-
Save ivarne/026e9fb6f5a2d7e91f4f to your computer and use it in GitHub Desktop.
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
const _interfaces = Dict{Function,Vector{DataType}}() | |
function addInterface(d::DataType, f::Function...) | |
for g in f | |
if haskey(_interfaces, g) | |
push!(_interfaces[g], d) | |
else | |
_interfaces[g] = DataType[d] | |
end | |
end | |
end | |
function checkInterface(d::DataType) | |
for (f,itypes) in _interfaces | |
isInInterfaceTable = false | |
local parentType | |
for it in itypes | |
if d <: it | |
isInInterfaceTable = true | |
parentType = it | |
end | |
end | |
isInMethodTable = false | |
if isInInterfaceTable | |
mt = methods(f) | |
for m in mt | |
if d <: m.sig[1] | |
isInMethodTable = true | |
end | |
end | |
end | |
if isInInterfaceTable && !isInMethodTable | |
error("Interface not implemented!\n $d has to implement ", string(f), " in order to be subtype of $parentType !") | |
end | |
end | |
return true | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment