Skip to content

Commit

Permalink
Minor style and typo fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
MicheleCeresoli committed Oct 26, 2023
1 parent 0334eae commit b383f50
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 39 deletions.
61 changes: 43 additions & 18 deletions src/Interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,58 +10,83 @@ export @interface
This macro can be used to create a in interface function within the
JSMD ecosystem.
Interface functions are intended as function with some abstract
types as inputs throwing a not implemented error as default behaviour.
Interface functions are intended as functions with some abstract
types as inputs throwing a [`NotImplementedError`](@ref) as default behaviour.
"""
macro interface(expr)

full_signature = expr.args[1]
fun_where = :()

if full_signature.head == :where
fun_signature = full_signature.args[1]
is_parametric = true

if fun_signature.head == :call
fun_name = fun_signature.args[1]

if length(fun_signature.args) < 2
throw(ErrorException("Interface definition error! Function definition shall have at least one argument."))
throw(
ErrorException(
"Interface definition error! Function definition shall have"*
" at least one argument."
)
)
end

fun_args = fun_signature.args[2:end]
fun_where = full_signature.args[2:end]

else
throw(ErrorException("Interface definition error!"))
end

elseif full_signature.head == :call
fun_signature = full_signature
fun_name = fun_signature.args[1]

if length(fun_signature.args) < 2
throw(ErrorException("Interface definition error! Function definition shall have at least one argument."))
throw(
ErrorException(
"Interface definition error! Function definition shall have"*
" at least one argument."
)
)
end

fun_args = fun_signature.args[2:end]
is_parametric = false

else
throw(ErrorException("Interface definition error! Shall be a valid function."))
end

if is_parametric
return esc(quote
function ($fun_name)($(fun_args...)) where {$(fun_where...)}
throw(
NotImplementedError(
"No method compatible with the current call implemented for the interface '$($fun_name)'!"
return esc(
quote
function ($fun_name)($(fun_args...)) where {$(fun_where...)}
throw(
NotImplementedError(
"No method compatible with the current call has been"*
" implemented for the interface '$($fun_name)'!"
)
)
)
end
end
end)
)
else
return esc(quote
function ($fun_name)($(fun_args...))
throw(
NotImplementedError(
"No compatible with the current call implemented for the interface '$($fun_name)'!"
return esc(
quote
function ($fun_name)($(fun_args...))
throw(
NotImplementedError(
"No method compatible with the current call has been"*
" implemented for the interface '$($fun_name)'!"
)
)
)
end
end
end)
)
end

end
Expand Down
35 changes: 16 additions & 19 deletions src/Models/abstract.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ export AbstractJSMDModel,
Basic abstract type for every JSMD compatible model data.
JSMD _ModelData_ types are the interface of the JSMD environment
with the external world, and is meant to provide a model agnostic interface
any customly formatted file.
JSMD _ModelData_ types are the interface of the JSMD environment with the external world,
and are meant to provide a model agnostic interface to any customly formatted file.
The main objective of this data is actually to create a JSMD simulation
compatible _Model_, by means of the [`parse_model`](@ref) interface.
The main objective of this data type is to create a JSMD simulation compatible _Model_
by means of the [`parse_model`](@ref) interface.
"""
abstract type AbstractJSMDModelData end

Expand All @@ -27,40 +26,38 @@ abstract type AbstractJSMDModel end

"""
parse_data(::Type{T}, ::Type{D}, ::AbstractString;
kargs...) where {T, D<:AbstractJSMDModelData} end
kargs...) where {T, D <: AbstractJSMDModelData} end
This function serves as an interface to create a JSMD compatible
model data object from a file.
"""
@interface function parse_data(::Type{T}, ::Type{D}, ::AbstractString;
kargs...) where {T, D<:AbstractJSMDModelData} end
kargs...) where {T, D <: AbstractJSMDModelData} end

"""
parse_model(::Type{T}, ::Type{M}, ::Type{D}, args...;
kargs...) where {T, D<:AbstractJSMDModelData, M<:AbstractJSMDModel}
kargs...) where {T, D <: AbstractJSMDModelData, M <: AbstractJSMDModel}
This function serves as an interface to create a JSMD compatible
model types from a _ModelData_ type.
model type from a _ModelData_ type.
"""
@interface function parse_model(::Type{T}, ::Type{M}, ::Type{D}, args...;
kargs...) where {T, D<:AbstractJSMDModelData, M<:AbstractJSMDModel} end
kargs...) where {T, D <: AbstractJSMDModelData, M <: AbstractJSMDModel} end

"""
dump_model(::AbstractJSMDModel, ::N, args...;
kargs...) where {N<:AbstractArchiveNode}
kargs...) where {N <: AbstractArchiveNode}
This function serves as an interface to dump to an archive node
a JSMD compatible model.
This function serves as an interface to dump to an archive node a JSMD compatible model.
"""
@interface function dump_model(::AbstractJSMDModel, ::N, args...;
kargs...) where {N<:AbstractArchiveNode} end
kargs...) where {N <: AbstractArchiveNode} end

"""
load_model(::Type{T}, ::Type{<:AbstractJSMDModel}, ::N,
args...; kargs...) where {T, N<:AbstractArchiveNode}
load_model(::Type{T}, ::Type{ <: AbstractJSMDModel}, ::N,
args...; kargs...) where {T, N <: AbstractArchiveNode}
This function serves as an interface to load from an archive node
a JSMD compatible model.
This function serves as an interface to load from an archive node a JSMD compatible model.
"""
@interface function load_model(::Type{T}, ::Type{<:AbstractJSMDModel}, ::N,
args...; kargs...) where {T, N<:AbstractArchiveNode} end
args...; kargs...) where {T, N <: AbstractArchiveNode} end
5 changes: 3 additions & 2 deletions src/Models/acceleration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ Basic abstract type for acceleration models data compatible with JSMD ecosystem.
abstract type AbstractAccelerationModelData <: AbstractJSMDModelData end

"""
compute_acceleration(::M, args...; kwargs...) where {M<:AbstractAccelerationModel} end
compute_acceleration(::M, args...; kwargs...) where {M <: AbstractAccelerationModel} end
This function serves as an interface to compute accelerations from JSMD compatible
acceleration models.
"""
@interface function compute_acceleration(::M, args...; kwargs...) where {M<:AbstractAccelerationModel} end
@interface function compute_acceleration(::M, args...;
kwargs...) where {M <: AbstractAccelerationModel} end

0 comments on commit b383f50

Please sign in to comment.