Skip to content

Commit

Permalink
Change Configuration constructor syntax.
Browse files Browse the repository at this point in the history
  • Loading branch information
phrb committed Nov 15, 2015
1 parent 3f1cfe9 commit b488ff5
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 23 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.swp
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
julia 0.4.0-rc2
julia 0.4.0
FactCheck
Optim
35 changes: 14 additions & 21 deletions src/core/configuration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,31 @@ type Configuration{T <: Parameter} <: Parameter
name::ASCIIString
value::Dict{ASCIIString, Any}

Configuration(parameters::Array{T, 1}, name::ASCIIString) = begin
function call{T <: Parameter}(::Type{Configuration}, parameters::Dict{ASCIIString, T}, name::ASCIIString)
values = Dict{ASCIIString, Any}()
for key in keys(parameters)
@inbounds values[key] = parameters[key].value
end
new{T}(parameters, name, values)

end

function call{T <: Parameter}(::Type{Configuration}, parameters::Array{T, 1}, name::ASCIIString)
params = Dict{ASCIIString, T}()
values = Dict{ASCIIString, Any}()
for parameter in parameters
@inbounds params[parameter.name] = parameter
@inbounds values[parameter.name] = parameter.value
end
new(params, name, values)
new{T}(params, name, values)
end

Configuration(parameters::Dict{ASCIIString, T}, name::ASCIIString) = begin
values = Dict{ASCIIString, Any}()
for key in keys(parameters)
@inbounds values[key] = parameters[key].value
end
new(parameters, name, values)
function call(::Type{Configuration}, name::ASCIIString)
params = Dict{ASCIIString, Parameter}()
new{Parameter}(params, name, params)
end
end

Configuration{T <: Parameter}(parameters::Array{T, 1}, name::ASCIIString) = begin
Configuration{T}(parameters, name)
end

Configuration{T <: Parameter}(parameters::Dict{ASCIIString, T}, name::ASCIIString) = begin
Configuration{T}(parameters, name)
end

Configuration(name::ASCIIString) = begin
params = Dict{ASCIIString, Parameter}()
Configuration{Parameter}(params, name)
end

Base.convert{T <: Parameter}(::Type{Array{T}}, configuration::Configuration) = begin
parameter_array = T[]
for key in collect(keys(configuration.parameters))
Expand Down
2 changes: 1 addition & 1 deletion test/configuration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ facts("[Configuration]") do
neighbor!(c)
@fact v --> not(exactly(c["i0"].value))
end
context("update! and convert!") do
context("update! and convert") do
c = Configuration("test")
c["test"] = IntegerParameter(1, 2323, 2, "i0")
a = convert(Array{Parameter}, c)
Expand Down

0 comments on commit b488ff5

Please sign in to comment.