Skip to content

Commit b521dcf

Browse files
author
Chris Foster
committed
Upgrade to support julia 0.6, 0.7, 1.0
1 parent 21ce324 commit b521dcf

File tree

5 files changed

+39
-31
lines changed

5 files changed

+39
-31
lines changed

REQUIRE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
julia 0.5
2-
Compat 0.19.0
1+
julia 0.6 2.0
2+
Compat 1.0.1

src/io.jl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ ply_type_name(::Float64) = "float64"
4646

4747
const PlyNativeType = Union{UInt8,UInt16,UInt32,UInt64,Int8,Int16,Int32,Int64,Float32,Float64}
4848

49-
ply_type_name{T<:PlyNativeType}(A::AbstractArray{T}) = ply_type_name(T)
49+
ply_type_name(A::AbstractArray{T}) where {T<:PlyNativeType} = ply_type_name(T)
5050

5151
ply_type_name(A::AbstractArray) = !isempty(A) ? ply_type_name(A[1]) :
5252
error("Unknown ply element type name for empty array of type $(typeof(A))")
@@ -124,13 +124,13 @@ function write_header_field(stream::IO, prop::ArrayProperty)
124124
println(stream, "property $(ply_type_name(prop.data)) $(prop.name)")
125125
end
126126

127-
function write_header_field{T,Names<:PropNameList}(stream::IO, prop::ArrayProperty{T,Names})
127+
function write_header_field(stream::IO, prop::ArrayProperty{T,Names}) where {T,Names<:PropNameList}
128128
for n in prop.name
129129
println(stream, "property $(ply_type_name(prop.data)) $(n)")
130130
end
131131
end
132132

133-
function write_header_field{S}(stream::IO, prop::ListProperty{S})
133+
function write_header_field(stream::IO, prop::ListProperty{S}) where {S}
134134
println(stream, "property list $(ply_type_name(S)) $(ply_type_name(prop.data)) $(prop.name)")
135135
end
136136

@@ -165,7 +165,7 @@ end
165165
#-------------------------------------------------------------------------------
166166
# ASCII IO for properties and elements
167167

168-
function parse_ascii{T}(::Type{T}, io::IO)
168+
function parse_ascii(::Type{T}, io::IO) where {T}
169169
# FIXME: sadly unbuffered, will probably have terrible performance.
170170
buf = UInt8[]
171171
while !eof(io)
@@ -181,10 +181,10 @@ function parse_ascii{T}(::Type{T}, io::IO)
181181
parse(T, String(buf))
182182
end
183183

184-
function read_ascii_value!{T}(stream::IO, prop::ArrayProperty{T}, index)
184+
function read_ascii_value!(stream::IO, prop::ArrayProperty{T}, index) where {T}
185185
prop.data[index] = parse_ascii(T, stream)
186186
end
187-
function read_ascii_value!{S,T}(stream::IO, prop::ListProperty{S,T}, index)
187+
function read_ascii_value!(stream::IO, prop::ListProperty{S,T}, index) where {S,T}
188188
N = parse_ascii(S, stream)
189189
prop.start_inds[index+1] = prop.start_inds[index] + N
190190
for i=1:N
@@ -198,20 +198,20 @@ end
198198

199199
#--------------------------------------------------
200200
# property IO
201-
function read_binary_value!{T}(stream::IO, prop::ArrayProperty{T}, index)
201+
function read_binary_value!(stream::IO, prop::ArrayProperty{T}, index) where {T}
202202
prop.data[index] = read(stream, T)
203203
end
204-
function read_binary_value!{S,T}(stream::IO, prop::ListProperty{S,T}, index)
204+
function read_binary_value!(stream::IO, prop::ListProperty{S,T}, index) where {S,T}
205205
N = read(stream, S)
206206
prop.start_inds[index+1] = prop.start_inds[index] + N
207-
inds = read(stream, T, Int(N))
207+
inds = read!(stream, Vector{T}(undef, Int(N)))
208208
append!(prop.data, inds)
209209
end
210210

211211
function write_binary_value(stream::IO, prop::ArrayProperty, index)
212212
write(stream, prop.data[index])
213213
end
214-
function write_binary_value{S}(stream::IO, prop::ListProperty{S}, index)
214+
function write_binary_value(stream::IO, prop::ListProperty{S}, index) where {S}
215215
len = prop.start_inds[index+1] - prop.start_inds[index]
216216
write(stream, convert(S, len))
217217
esize = sizeof(eltype(prop.data))
@@ -230,7 +230,7 @@ end
230230
function write_ascii_value(stream::IO, prop::ArrayProperty, index)
231231
print(stream, prop.data[index])
232232
end
233-
function write_ascii_value{T<:AbstractArray}(stream::IO, prop::ArrayProperty{T}, index)
233+
function write_ascii_value(stream::IO, prop::ArrayProperty{<:AbstractArray}, index)
234234
p = prop.data[index]
235235
for i = 1:length(p)
236236
if i != 1
@@ -290,7 +290,7 @@ end
290290
# for elements constructed of simple arrays with homogenous type -
291291
# serialization speed generally seems to be limited by the many individual
292292
# calls to write() with small buffers.
293-
function write_binary_values{T}(stream::IO, elen, props::ArrayProperty{T}...)
293+
function write_binary_values(stream::IO, elen, props::ArrayProperty{T}...) where {T}
294294
batchsize = 100
295295
numprops = length(props)
296296
buf = Matrix{T}(numprops, batchsize)

src/types.jl

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,22 @@ const PropNameList = Union{AbstractVector,Tuple}
1818
A ply `property \$T \$name`, modelled as an abstract vector, with a name which
1919
can be retrieved using `plyname()`.
2020
"""
21-
type ArrayProperty{T,Name} <: AbstractVector{T}
21+
mutable struct ArrayProperty{T,Name} <: AbstractVector{T}
2222
name::Name
2323
data::Vector{T}
2424
end
2525

2626
#=
2727
# FIXME: Ambiguous constructor
28-
function ArrayProperty{T}(names::PropNameList, data::AbstractVector{T})
28+
function ArrayProperty(names::PropNameList, data::AbstractVector{T}) where {T}
2929
if length(names) != length(T)
3030
error("Number of property names in $names does not match length($T)")
3131
end
3232
ArrayProperty(names, data)
3333
end
3434
=#
3535

36-
ArrayProperty{T}(name::AbstractString, ::Type{T}) = ArrayProperty(String(name), Vector{T}())
36+
ArrayProperty(name::AbstractString, ::Type{T}) where {T} = ArrayProperty(String(name), Vector{T}())
3737

3838
Base.summary(prop::ArrayProperty) = "$(length(prop))-element $(typeof(prop)) \"$(plyname(prop))\""
3939

@@ -59,13 +59,13 @@ plyname(prop::ArrayProperty) = prop.name
5959
A ply `property list \$S \$T \$name`, modelled as a abstract vector of vectors,
6060
with a name which can be retrieved using `plyname()`.
6161
"""
62-
type ListProperty{S,T} <: AbstractVector{Vector{T}}
62+
mutable struct ListProperty{S,T} <: AbstractVector{Vector{T}}
6363
name::String
6464
start_inds::Vector{Int}
6565
data::Vector{T}
6666
end
6767

68-
ListProperty{S,T}(name, ::Type{S}, ::Type{T}) = ListProperty{S,T}(String(name), ones(Int,1), Vector{T}())
68+
ListProperty(name, ::Type{S}, ::Type{T}) where {S,T} = ListProperty{S,T}(String(name), ones(Int,1), Vector{T}())
6969

7070
function ListProperty(name::AbstractString, a::AbstractVector)
7171
# Construct list from an array of arrays
@@ -109,7 +109,7 @@ the array interface, or looked up by indexing with a string.
109109
The expected length `len` is used if it is set, otherwise the length shared by
110110
the property vectors is used.
111111
"""
112-
type PlyElement
112+
mutable struct PlyElement
113113
name::String
114114
prior_len::Int # Length as expected, or as read from file
115115
properties::Vector
@@ -154,10 +154,14 @@ function Base.getindex(element::PlyElement, prop_name)
154154
end
155155

156156
# List methods
157-
Base.start(elem::PlyElement) = start(elem.properties)
158-
Base.next(elem::PlyElement, state) = next(elem.propertes, state)
159-
Base.done(elem::PlyElement, state) = done(elem.propertes, state)
160-
Base.push!(elem::PlyElement, prop) = (push!(elem.properties, prop); elem)
157+
if VERSION >= v"0.7"
158+
Base.iterate(elem::PlyElement, s...) = iterate(elem.properties, s...)
159+
else
160+
Base.start(elem::PlyElement) = start(elem.properties)
161+
Base.next(elem::PlyElement, state) = next(elem.propertes, state)
162+
Base.done(elem::PlyElement, state) = done(elem.propertes, state)
163+
Base.push!(elem::PlyElement, prop) = (push!(elem.properties, prop); elem)
164+
end
161165

162166
# Ply methods
163167
plyname(elem::PlyElement) = elem.name
@@ -169,7 +173,7 @@ plyname(elem::PlyElement) = elem.name
169173
170174
A ply comment.
171175
"""
172-
immutable PlyComment
176+
struct PlyComment
173177
comment::String
174178
location::Int # index of previous element
175179
end
@@ -188,7 +192,7 @@ contents of the header. Ply elements and comments can be added using
188192
`push!()`, elements can be iterated over with the standard iterator
189193
interface, and looked up by indexing with a string.
190194
"""
191-
type Ply
195+
mutable struct Ply
192196
elements::Vector{PlyElement}
193197
comments::Vector{PlyComment}
194198
end
@@ -218,7 +222,10 @@ function Base.getindex(ply::Ply, elem_name::AbstractString)
218222
end
219223

220224
Base.length(ply::Ply) = length(ply.elements)
221-
Base.start(ply::Ply) = start(ply.elements)
222-
Base.next(ply::Ply, state) = next(ply.elements, state)
223-
Base.done(ply::Ply, state) = done(ply.elements, state)
224-
225+
if VERSION >= v"0.7"
226+
Compat.iterate(ply::Ply, s...) = iterate(ply.elements, s...)
227+
else
228+
Base.start(ply::Ply) = start(ply.elements)
229+
Base.next(ply::Ply, state) = next(ply.elements, state)
230+
Base.done(ply::Ply, state) = done(ply.elements, state)
231+
end

test/REQUIRE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
StaticArrays
2+
Compat

test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using PlyIO
22
using StaticArrays
3-
using Base.Test
43
using Compat
4+
using Compat.Test
55

66
@testset "PlyIO" begin
77

0 commit comments

Comments
 (0)