Skip to content

Commit 7c3b15c

Browse files
committed
Refactoring show methods
1 parent e43ae9b commit 7c3b15c

File tree

1 file changed

+47
-61
lines changed

1 file changed

+47
-61
lines changed

src/CosObject.jl

Lines changed: 47 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ end
3030
val::Int
3131
end
3232

33-
show(io::IO, o::CosObject) = print(io, o.val)
34-
35-
show(io::IO, o::CosNullType) = print(io, "null")
36-
3733
"""
3834
A parsed data structure to ensure the object information is stored as an object.
3935
This has no meaning without a associated CosDoc. When a reference object is hit
@@ -44,8 +40,6 @@ the object should be searched from the CosDoc and returned.
4440
CosIndirectObjectRef(num::Int, gen::Int)=new((num,gen))
4541
end
4642

47-
show(io::IO, o::CosIndirectObjectRef) = @printf io "%d %d R" o.val[1] o.val[2]
48-
4943
#hash(o::CosIndirectObjectRef, h::UInt=zero(UInt)) = hash(o.val, h)
5044
#isequal(r1::CosIndirectObjectRef, r2::CosIndirectObjectRef) = isequal(r1.val, r2.val)
5145

@@ -57,38 +51,16 @@ end
5751

5852
get(o::CosIndirectObject) = get(o.obj)
5953

60-
showref(io::IO, o::CosIndirectObject) = @printf io "%d %d R" o.num o.gen
61-
62-
showref(io::IO, o::CosObject)=show(io, o)
63-
64-
function show(io::IO, o::CosIndirectObject)
65-
str = @sprintf "%d %d obj\n" o.num o.gen
66-
print(io, str)
67-
show(io, o.obj)
68-
end
69-
7054
@compat struct CosName <: CosObject
7155
val::Symbol
7256
CosName(str::String)=new(Symbol("CosName_",str))
7357
end
7458

75-
function show(io::IO, o::CosName)
76-
val = String(o.val)
77-
val = split(val,'_')[2]
78-
str = @sprintf "/%s" val
79-
print(io, str)
80-
end
81-
8259
@compat struct CosXString <: CosString
8360
val::Vector{UInt8}
8461
CosXString(arr::Vector{UInt8})=new(arr)
8562
end
8663

87-
function show(io::IO, o::CosXString)
88-
str = @sprintf "%s" "<"*String(copy(o.val))*">"
89-
print(io, str)
90-
end
91-
9264
Base.convert(::Type{Vector{UInt8}}, xstr::CosXString)=
9365
(xstr.val |> String |> hex2bytes)
9466

@@ -103,11 +75,6 @@ end
10375

10476
CosLiteralString(str::AbstractString)=CosLiteralString(transcode(UInt8,str))
10577

106-
function show(io::IO, o::CosLiteralString)
107-
str = @sprintf "%s" "("*String(copy(o.val))*")"
108-
print(io, str)
109-
end
110-
11178
Base.convert(::Type{Vector{UInt8}}, str::CosLiteralString)=copy(str.val)
11279

11380
Base.convert(::Type{String}, str::CosLiteralString)=
@@ -125,15 +92,6 @@ Base.convert(::Type{String}, str::CosLiteralString)=
12592
CosArray()=new(Array{CosObject,1}())
12693
end
12794

128-
function show(io::IO, o::CosArray)
129-
print(io, '[')
130-
for obj in o.val
131-
showref(io, obj)
132-
print(io, ' ')
133-
end
134-
print(io, ']')
135-
end
136-
13795
get(o::CosArray, isNative=false)=isNative ? map((x)->get(x),o.val) : o.val
13896
length(o::CosArray)=length(o.val)
13997

@@ -146,18 +104,6 @@ get(dict::CosDict, name::CosName)=get(dict.val,name,CosNull)
146104

147105
get(o::CosIndirectObject{CosDict}, name::CosName) = get(o.obj, name)
148106

149-
function show(io::IO, o::CosDict)
150-
print(io, "<<\n")
151-
for key in keys(o.val)
152-
print(io, "\t")
153-
show(io, key)
154-
print(io, "\t")
155-
showref(io, get(o,key))
156-
println(io, "")
157-
end
158-
print(io, ">>")
159-
end
160-
161107
"""
162108
Set the value to object. If the object is CosNull the key is deleted.
163109
"""
@@ -179,11 +125,6 @@ set!(o::CosIndirectObject{CosDict}, name::CosName, obj::CosObject) =
179125
CosStream(d::CosDict,isInternal::Bool=true)=new(d,isInternal)
180126
end
181127

182-
function show(io::IO, stm::CosStream)
183-
show(io, stm.extent);
184-
print(io, "stream\n...\nendstream\n")
185-
end
186-
187128
get(stm::CosStream, name::CosName) = get(stm.extent, name)
188129

189130
get(o::CosIndirectObject{CosStream}, name::CosName) = get(o.obj,name)
@@ -220,8 +161,6 @@ get(stm::CosStream) = decode(stm)
220161
end
221162
end
222163

223-
show(io::IO, os::CosObjectStream) = show(io, os.stm)
224-
225164
get(os::CosObjectStream, name::CosName) = get(os.stm, name)
226165

227166
get(os::CosIndirectObject{CosObjectStream}, name::CosName) = get(os.obj,name)
@@ -253,3 +192,50 @@ set!(os::CosIndirectObject{CosXRefStream}, name::CosName, obj::CosObject)=
253192
set!(os.obj,name,obj)
254193

255194
get(os::CosXRefStream) = get(os.stm)
195+
196+
# All show methods
197+
198+
show(io::IO, o::CosObject) = print(io, o.val)
199+
200+
showref(io::IO, o::CosObject) = show(io, o)
201+
202+
show(io::IO, o::CosNullType) = print(io, "null")
203+
204+
show(io::IO, o::CosName) = @printf io "/%s" split(String(o.val),'_')[2]
205+
206+
show(io::IO, o::CosXString) = @printf "%s" "<"*String(copy(o.val))*">"
207+
208+
show(io::IO, o::CosLiteralString) = @printf "%s" "("*String(copy(o.val))*")"
209+
210+
function show(io::IO, o::CosArray)
211+
print(io, '[')
212+
for obj in o.val
213+
showref(io, obj)
214+
print(io, ' ')
215+
end
216+
print(io, ']')
217+
end
218+
219+
function show(io::IO, o::CosDict)
220+
print(io, "<<\n")
221+
map(keys(o.val)) do key
222+
print(io, '\t')
223+
show(io, key)
224+
print(io, '\t')
225+
showref(io, get(o, key))
226+
println(io, "")
227+
end
228+
print(io, ">>")
229+
end
230+
231+
show(io::IO, stm::CosStream) =
232+
(show(io, stm.extent); print(io, "stream\n...\nendstream\n"))
233+
234+
show(io::IO, os::CosObjectStream) = show(io, os.stm)
235+
236+
show(io::IO, o::CosIndirectObjectRef) = @printf io "%d %d R" o.val[1] o.val[2]
237+
238+
showref(io::IO, o::CosIndirectObject) = @printf io "%d %d R" o.num o.gen
239+
240+
show(io::IO, o::CosIndirectObject) =
241+
(@printf io "\n%d %d obj\n" o.num o.gen; show(io, o.obj); println(io, "\nendobj\n"))

0 commit comments

Comments
 (0)