Skip to content

Commit

Permalink
Merge pull request #27 from JuliaGraphics/fbot/deps
Browse files Browse the repository at this point in the history
Fix deprecations
  • Loading branch information
Gnimuc authored Aug 4, 2018
2 parents a23e666 + d3731ae commit 2dee208
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/CEnum.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,26 @@ Base.:(==)(a::Integer, b::Cenum) = a == UInt32(b)
Base.:(==)(a::Cenum, b::Integer) = b == a

# typemin and typemax won't change for an enum, so we might as well inline them per type
function Base.typemax{T<:Cenum}(::Type{T})
function Base.typemax(::Type{T}) where T<:Cenum
last(enum_values(T))
end
function Base.typemin{T<:Cenum}(::Type{T})
function Base.typemin(::Type{T}) where T<:Cenum
first(enum_values(T))
end
Base.convert{T<:Integer}(::Type{Integer}, x::Cenum{T}) = Base.bitcast(T, x)
Base.convert{T<:Integer,T2<:Integer}(::Type{T}, x::Cenum{T2}) = convert(T, Base.bitcast(T2, x))
Base.convert(::Type{Integer}, x::Cenum{T}) where {T<:Integer} = Base.bitcast(T, x)
Base.convert(::Type{T}, x::Cenum{T2}) where {T<:Integer,T2<:Integer} = convert(T, Base.bitcast(T2, x))

Base.write(io::IO, x::Cenum) = write(io, Int32(x))
Base.read(io::IO, ::Type{T}) where {T<:Cenum} = T(read(io, Int32))

enum_values{T<:Cenum}(::T) = enum_values(T)
enum_names{T<:Cenum}(::T) = enum_names(T)
enum_values(::T) where {T<:Cenum} = enum_values(T)
enum_names(::T) where {T<:Cenum} = enum_names(T)

function is_member{T<:Cenum}(::Type{T}, x::Integer)
function is_member(::Type{T}, x::Integer) where T<:Cenum
is_member(T, enum_values(T), x)
end
@inline is_member{T<:Cenum}(::Type{T}, r::UnitRange, x::Integer) = x in r
@inline function is_member{T<:Cenum}(::Type{T}, values::Tuple, x::Integer)
@inline is_member(::Type{T}, r::UnitRange, x::Integer) where {T<:Cenum} = x in r
@inline function is_member(::Type{T}, values::Tuple, x::Integer) where T<:Cenum
lo, hi = typemin(T), typemax(T)
x<lo || x>hi && return false
for val in values
Expand Down

0 comments on commit 2dee208

Please sign in to comment.