1
- import Base: get,length
1
+ import Base: get, length, show
2
2
3
3
export CosDict, CosString, CosNumeric, CosBoolean, CosTrue, CosFalse,
4
4
CosObject, CosNull, CosNullType,CosFloat, CosInt, CosArray, CosName,
30
30
val:: Int
31
31
end
32
32
33
+ show (io:: IO , o:: CosObject ) = print (io, o. val)
34
+
35
+ show (io:: IO , o:: CosNullType ) = print (io, " null" )
36
+
33
37
"""
34
38
A parsed data structure to ensure the object information is stored as an object.
35
39
This has no meaning without a associated CosDoc. When a reference object is hit
@@ -40,27 +44,51 @@ the object should be searched from the CosDoc and returned.
40
44
CosIndirectObjectRef (num:: Int , gen:: Int )= new ((num,gen))
41
45
end
42
46
47
+ show (io:: IO , o:: CosIndirectObjectRef ) = @printf io " %d %d R" o. val[1 ] o. val[2 ]
48
+
43
49
# hash(o::CosIndirectObjectRef, h::UInt=zero(UInt)) = hash(o.val, h)
44
50
# isequal(r1::CosIndirectObjectRef, r2::CosIndirectObjectRef) = isequal(r1.val, r2.val)
45
51
46
52
@compat mutable struct CosIndirectObject{T <: CosObject } <: CosObject
47
- num:: Int
48
- gen:: Int
49
- obj:: T
53
+ num:: Int
54
+ gen:: Int
55
+ obj:: T
50
56
end
51
57
52
58
get (o:: CosIndirectObject ) = get (o. obj)
53
59
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
+
54
70
@compat struct CosName <: CosObject
55
71
val:: Symbol
56
72
CosName (str:: String )= new (Symbol (" CosName_" ,str))
57
73
end
58
74
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
+
59
82
@compat struct CosXString <: CosString
60
83
val:: Vector{UInt8}
61
84
CosXString (arr:: Vector{UInt8} )= new (arr)
62
85
end
63
86
87
+ function show (io:: IO , o:: CosXString )
88
+ str = @sprintf " %s" " <" * String (copy (o. val))* " >"
89
+ print (io, str)
90
+ end
91
+
64
92
Base. convert (:: Type{Vector{UInt8}} , xstr:: CosXString )=
65
93
(xstr. val |> String |> hex2bytes)
66
94
75
103
76
104
CosLiteralString (str:: AbstractString )= CosLiteralString (transcode (UInt8,str))
77
105
106
+ function show (io:: IO , o:: CosLiteralString )
107
+ str = @sprintf " %s" " (" * String (copy (o. val))* " )"
108
+ print (io, str)
109
+ end
110
+
78
111
Base. convert (:: Type{Vector{UInt8}} , str:: CosLiteralString )= copy (str. val)
79
112
80
113
Base. convert (:: Type{String} , str:: CosLiteralString )=
@@ -92,6 +125,14 @@ Base.convert(::Type{String}, str::CosLiteralString)=
92
125
CosArray ()= new (Array {CosObject,1} ())
93
126
end
94
127
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
95
136
96
137
get (o:: CosArray , isNative= false )= isNative ? map ((x)-> get (x),o. val) : o. val
97
138
length (o:: CosArray )= length (o. val)
@@ -105,6 +146,18 @@ get(dict::CosDict, name::CosName)=get(dict.val,name,CosNull)
105
146
106
147
get (o:: CosIndirectObject{CosDict} , name:: CosName ) = get (o. obj, name)
107
148
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
+
108
161
"""
109
162
Set the value to object. If the object is CosNull the key is deleted.
110
163
"""
@@ -126,6 +179,11 @@ set!(o::CosIndirectObject{CosDict}, name::CosName, obj::CosObject) =
126
179
CosStream (d:: CosDict ,isInternal:: Bool = true )= new (d,isInternal)
127
180
end
128
181
182
+ function show (io:: IO , stm:: CosStream )
183
+ show (io, stm. extent);
184
+ print (io, " stream\n ...\n endstream\n " )
185
+ end
186
+
129
187
get (stm:: CosStream , name:: CosName ) = get (stm. extent, name)
130
188
131
189
get (o:: CosIndirectObject{CosStream} , name:: CosName ) = get (o. obj,name)
@@ -141,7 +199,7 @@ Decodes the stream and provides output as an BufferedInputStream.
141
199
"""
142
200
get (stm:: CosStream ) = decode (stm)
143
201
144
- @compat mutable struct CosObjectStream<: CosObject
202
+ @compat mutable struct CosObjectStream <: CosObject
145
203
stm:: CosStream
146
204
n:: Int
147
205
first:: Int
@@ -162,6 +220,8 @@ get(stm::CosStream) = decode(stm)
162
220
end
163
221
end
164
222
223
+ show (io:: IO , os:: CosObjectStream ) = show (io, os. stm)
224
+
165
225
get (os:: CosObjectStream , name:: CosName ) = get (os. stm, name)
166
226
167
227
get (os:: CosIndirectObject{CosObjectStream} , name:: CosName ) = get (os. obj,name)
0 commit comments