Mercurial > projects > orange
annotate orange/serialization/archives/XMLArchive.d @ 22:963b756ed579
Resolved merge conflicts.
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Mon, 04 Oct 2010 20:42:45 +0200 |
parents | 8ab9588b92bf 51f05fd6a626 |
children | 55f0a9d5df8d |
rev | line source |
---|---|
0 | 1 /** |
2 * Copyright: Copyright (c) 2010 Jacob Carlborg. | |
3 * Authors: Jacob Carlborg | |
4 * Version: Initial created: Jan 26, 2010 | |
5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0) | |
6 */ | |
7 module orange.serialization.archives.XMLArchive; | |
8 | |
9 version (Tango) | |
10 import tango.util.Convert : to; | |
11 | |
9
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
12 else |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
13 import std.conv; |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
14 |
0 | 15 import orange.serialization.archives._; |
16 import orange.util._; | |
9
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
17 import orange.xml.XMLDocument; |
0 | 18 |
19 private enum ArchiveMode | |
20 { | |
21 archiving, | |
22 unarchiving | |
23 } | |
24 | |
25 class XMLArchive (U = char) : Archive!(U) | |
26 { | |
27 static assert (isChar!(U), format!(`The given type "`, U, `" is not a valid type. Valid types are: "char", "wchar" and "dchar".`)); | |
28 | |
29 private struct Tags | |
30 { | |
31 static const DataType structTag = "struct"; | |
32 static const DataType dataTag = "data"; | |
33 static const DataType archiveTag = "archive"; | |
34 static const DataType arrayTag = "array"; | |
35 static const DataType objectTag = "object"; | |
36 static const DataType baseTag = "base"; | |
37 static const DataType stringTag = "string"; | |
38 static const DataType referenceTag = "reference"; | |
39 static const DataType pointerTag = "pointer"; | |
40 static const DataType associativeArrayTag = "associativeArray"; | |
41 static const DataType typedefTag = "typedef"; | |
42 static const DataType nullTag = "null"; | |
20
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
43 static const DataType enumTag = "enum"; |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
44 static const DataType sliceTag = "slice"; |
0 | 45 } |
46 | |
47 private struct Attributes | |
48 { | |
49 static const DataType typeAttribute = "type"; | |
50 static const DataType versionAttribute = "version"; | |
51 static const DataType lengthAttribute = "length"; | |
52 static const DataType keyAttribute = "key"; | |
53 static const DataType runtimeTypeAttribute = "runtimeType"; | |
54 static const DataType idAttribute = "id"; | |
55 static const DataType keyTypeAttribute = "keyType"; | |
56 static const DataType valueTypeAttribute = "valueType"; | |
20
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
57 static const DataType offsetAttribute = "offset"; |
0 | 58 } |
59 | |
60 private | |
61 { | |
20
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
62 struct ArrayNode |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
63 { |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
64 XMLDocument!(U).Node parent; |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
65 XMLDocument!(U).Node node; |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
66 DataType id; |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
67 DataType key; |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
68 } |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
69 |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
70 struct Array |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
71 { |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
72 void* ptr; |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
73 size_t length; |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
74 size_t elementSize; |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
75 |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
76 static Array opCall (T) (T[] value) |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
77 { |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
78 Array array; |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
79 array.ptr = value.ptr; |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
80 array.length = value.length; |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
81 array.elementSize = T.sizeof; |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
82 |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
83 return array; |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
84 } |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
85 |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
86 bool isSliceOf (Array b) |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
87 { |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
88 return ptr >= b.ptr && ptr + length * elementSize <= b.ptr + b.length * b.elementSize; |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
89 } |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
90 } |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
91 |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
92 struct Slice |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
93 { |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
94 size_t length; |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
95 size_t offset; |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
96 DataType id; |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
97 } |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
98 |
0 | 99 DataType archiveType = "org.dsource.orange.xml"; |
100 DataType archiveVersion = "0.1"; | |
101 | |
9
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
102 XMLDocument!(U) doc; |
0 | 103 doc.Node lastElement; |
9
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
104 //DocPrinter!(U) printer; |
0 | 105 doc.Node lastElementSaved; |
106 | |
107 bool hasBegunArchiving; | |
108 bool hasBegunUnarchiving; | |
109 | |
110 DataType[void*] archivedReferences; | |
111 void*[DataType] unarchivedReferences; | |
112 | |
20
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
113 ArrayNode[Array] arraysToBeArchived; |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
114 void[][DataType] unarchivedSlices; |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
115 |
0 | 116 size_t idCounter; |
117 } | |
118 | |
119 this () | |
120 { | |
9
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
121 doc = new XMLDocument!(U); |
0 | 122 } |
123 | |
124 public void beginArchiving () | |
125 { | |
126 if (!hasBegunArchiving) | |
127 { | |
128 doc.header; | |
9
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
129 lastElement = doc.tree.element(Tags.archiveTag) |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
130 .attribute(Attributes.typeAttribute, archiveType) |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
131 .attribute(Attributes.versionAttribute, archiveVersion); |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
132 lastElement = lastElement.element(Tags.dataTag); |
0 | 133 |
134 hasBegunArchiving = true; | |
135 } | |
136 } | |
137 | |
138 public void beginUnarchiving (DataType data) | |
139 { | |
140 if (!hasBegunUnarchiving) | |
141 { | |
142 doc.parse(data); | |
143 hasBegunUnarchiving = true; | |
144 | |
145 auto set = doc.query[Tags.archiveTag][Tags.dataTag]; | |
146 | |
147 if (set.nodes.length == 1) | |
148 lastElement = set.nodes[0]; | |
149 | |
150 else | |
18
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
151 { |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
152 if (errorCallback) |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
153 { |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
154 if (set.nodes.length == 0) |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
155 errorCallback(new ArchiveException(errorMessage!(ArchiveMode.unarchiving) ~ `The "` ~ to!(string)(Tags.dataTag) ~ `" tag could not be found.`, __FILE__, __LINE__), [Tags.dataTag]); |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
156 |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
157 else |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
158 errorCallback(new ArchiveException(errorMessage!(ArchiveMode.unarchiving) ~ `There were more than one "` ~ to!(string)(Tags.dataTag) ~ `" tag.`, __FILE__, __LINE__), [Tags.dataTag]); |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
159 } |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
160 } |
0 | 161 } |
162 } | |
163 | |
164 public DataType data () | |
165 { | |
9
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
166 /*if (!printer) |
0 | 167 printer = new DocPrinter!(U); |
168 | |
9
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
169 return printer.print(doc);*/ |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
170 |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
171 return doc.toString(); |
0 | 172 } |
173 | |
174 public void reset () | |
175 { | |
176 hasBegunArchiving = false; | |
177 hasBegunUnarchiving = false; | |
178 idCounter = 0; | |
179 doc.reset; | |
180 } | |
181 | |
182 private void begin () | |
183 { | |
184 lastElementSaved = lastElement; | |
185 } | |
186 | |
187 private void end () | |
188 { | |
189 lastElement = lastElementSaved; | |
190 } | |
191 | |
192 public void archive (T) (T value, DataType key, void delegate () dg = null) | |
193 { | |
194 if (!hasBegunArchiving) | |
195 beginArchiving(); | |
196 | |
197 restore(lastElement) in { | |
198 bool callDelegate = true; | |
199 | |
200 static if (isTypeDef!(T)) | |
201 archiveTypeDef(value, key); | |
202 | |
203 else static if (isObject!(T)) | |
204 archiveObject(value, key, callDelegate); | |
205 | |
206 else static if (isStruct!(T)) | |
207 archiveStruct(value, key); | |
208 | |
209 else static if (isString!(T)) | |
210 archiveString(value, key); | |
211 | |
212 else static if (isArray!(T)) | |
213 archiveArray(value, key); | |
214 | |
215 else static if (isAssociativeArray!(T)) | |
216 archiveAssociativeArray(value, key); | |
217 | |
218 else static if (isPrimitive!(T)) | |
219 archivePrimitive(value, key); | |
220 | |
221 else static if (isPointer!(T)) | |
222 archivePointer(value, key, callDelegate); | |
223 | |
224 else static if (isEnum!(T)) | |
225 archiveEnum(value, key); | |
226 | |
227 else | |
228 static assert(false, format!(`The type "`, T, `" cannot be archived.`)); | |
229 | |
230 if (callDelegate && dg) | |
231 dg(); | |
232 }; | |
233 } | |
234 | |
235 private void archiveObject (T) (T value, DataType key, ref bool callDelegate) | |
236 { | |
237 if (!value) | |
238 { | |
9
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
239 lastElement.element(Tags.nullTag) |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
240 .attribute(Attributes.typeAttribute, toDataType(T.stringof)) |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
241 .attribute(Attributes.keyAttribute, key); |
0 | 242 callDelegate = false; |
243 } | |
244 | |
245 else if (auto reference = getArchivedReference(value)) | |
246 { | |
247 archiveReference(key, reference); | |
248 callDelegate = false; | |
249 } | |
250 | |
251 else | |
252 { | |
253 DataType id = nextId; | |
254 | |
9
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
255 lastElement = lastElement.element(Tags.objectTag) |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
256 .attribute(Attributes.runtimeTypeAttribute, toDataType(value.classinfo.name)) |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
257 .attribute(Attributes.typeAttribute, toDataType(T.stringof)) |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
258 .attribute(Attributes.keyAttribute, key) |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
259 .attribute(Attributes.idAttribute, id); |
0 | 260 |
261 addArchivedReference(value, id); | |
262 } | |
263 } | |
264 | |
265 private void archiveStruct (T) (T value, DataType key) | |
266 { | |
9
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
267 lastElement = lastElement.element(Tags.structTag) |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
268 .attribute(Attributes.typeAttribute, toDataType(T.stringof)) |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
269 .attribute(Attributes.keyAttribute, key); |
0 | 270 } |
271 | |
272 private void archiveString (T) (T value, DataType key) | |
20
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
273 { |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
274 archiveArrayImpl(value, key, Tags.stringTag, toDataType(value)); |
0 | 275 } |
276 | |
277 private void archiveArray (T) (T value, DataType key) | |
20
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
278 { |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
279 archiveArrayImpl(value, key, Tags.arrayTag); |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
280 } |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
281 |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
282 private void archiveArrayImpl (T) (T value, DataType key, DataType tag, DataType content = null) |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
283 { |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
284 DataType id = nextId; |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
285 auto parent = lastElement; |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
286 |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
287 if (value.length == 0) |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
288 lastElement = lastElement.element(tag); |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
289 |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
290 else |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
291 lastElement = doc.createNode(tag, content); |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
292 |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
293 lastElement.attribute(Attributes.typeAttribute, toDataType(BaseTypeOfArray!(T).stringof)) |
9
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
294 .attribute(Attributes.lengthAttribute, toDataType(value.length)) |
20
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
295 .attribute(Attributes.keyAttribute, key) |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
296 .attribute(Attributes.idAttribute, id); |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
297 |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
298 arraysToBeArchived[Array(value)] = ArrayNode(parent, lastElement, id, key); |
0 | 299 } |
300 | |
301 private void archiveAssociativeArray (T) (T value, DataType key) | |
302 { | |
9
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
303 lastElement = lastElement.element(Tags.associativeArrayTag) |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
304 .attribute(Attributes.keyTypeAttribute, toDataType(KeyTypeOfAssociativeArray!(T).stringof)) |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
305 .attribute(Attributes.valueTypeAttribute, toDataType(ValueTypeOfAssociativeArray!(T).stringof)) |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
306 .attribute(Attributes.lengthAttribute, toDataType(value.length)) |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
307 .attribute(Attributes.keyAttribute, key); |
0 | 308 } |
309 | |
310 private void archivePointer (T) (T value, DataType key, ref bool callDelegate) | |
311 { | |
312 if (auto reference = getArchivedReference(value)) | |
313 { | |
314 archiveReference(key, reference); | |
315 callDelegate = false; | |
316 } | |
317 | |
318 else | |
319 { | |
320 DataType id = nextId; | |
321 | |
9
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
322 lastElement = lastElement.element(Tags.pointerTag) |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
323 .attribute(Attributes.keyAttribute, key) |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
324 .attribute(Attributes.idAttribute, id); |
0 | 325 |
326 addArchivedReference(value, id); | |
327 } | |
328 } | |
329 | |
330 private void archiveEnum (T) (T value, DataType key) | |
331 { | |
9
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
332 lastElement.element(Tags.enumTag, toDataType(value)) |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
333 .attribute(Attributes.typeAttribute, toDataType(T.stringof)) |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
334 .attribute(Attributes.keyAttribute, key); |
0 | 335 } |
336 | |
337 private void archivePrimitive (T) (T value, DataType key) | |
338 { | |
9
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
339 lastElement.element(toDataType(T.stringof), toDataType(value)) |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
340 .attribute(Attributes.keyAttribute, key); |
0 | 341 } |
342 | |
343 private void archiveTypeDef (T) (T value, DataType key) | |
344 { | |
9
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
345 lastElement = lastElement.element(Tags.typedefTag) |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
346 .attribute(Attributes.typeAttribute, toDataType(BaseTypeOfTypeDef!(T).stringof)); |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
347 .attribute(Attributes.key, key); |
0 | 348 } |
349 | |
350 public T unarchive (T) (DataType key, T delegate (T) dg = null) | |
351 { | |
352 if (!hasBegunUnarchiving) | |
353 beginUnarchiving(data); | |
354 | |
355 return restore!(T)(lastElement) in { | |
356 T value; | |
357 | |
358 bool callDelegate = true; | |
359 | |
360 static if (isTypeDef!(T)) | |
361 value = unarchiveTypeDef!(T)(key); | |
362 | |
363 else static if (isObject!(T)) | |
364 value = unarchiveObject!(T)(key, callDelegate); | |
365 | |
366 else static if (isStruct!(T)) | |
367 value = unarchiveStruct!(T)(key); | |
368 | |
369 else static if (isString!(T)) | |
370 value = unarchiveString!(T)(key); | |
371 | |
372 else static if (isArray!(T)) | |
20
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
373 value = unarchiveArray!(T)(key, callDelegate); |
0 | 374 |
375 else static if (isAssociativeArray!(T)) | |
376 value = unarchiveAssociativeArray!(T)(key); | |
377 | |
378 else static if (isPrimitive!(T)) | |
379 value = unarchivePrimitive!(T)(key); | |
380 | |
381 else static if (isPointer!(T)) | |
382 value = unarchivePointer!(T)(key, callDelegate); | |
383 | |
384 else static if (isEnum!(T)) | |
385 value = unarchiveEnum!(T)(key); | |
386 | |
387 else | |
388 static assert(false, format!(`The type "`, T, `" cannot be unarchived.`)); | |
389 | |
390 if (callDelegate && dg) | |
391 return dg(value); | |
392 | |
393 return value; | |
394 }; | |
395 } | |
396 | |
397 private T unarchiveObject (T) (DataType key, ref bool callDelegate) | |
398 { | |
399 DataType id = unarchiveReference(key); | |
400 | |
401 if (auto reference = getUnarchivedReference!(T)(id)) | |
402 { | |
403 callDelegate = false; | |
404 return *reference; | |
405 } | |
406 | |
407 auto tmp = getElement(Tags.objectTag, key, Attributes.keyAttribute, false); | |
11
27c5b6c5425f
Deserialization now works as well using D2. Compiles again with D1 and Tango. Cleaned up orange.util.io a bit.
Jacob Carlborg <doob@me.com>
parents:
10
diff
changeset
|
408 |
9
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
409 if (!tmp.isValid) |
0 | 410 { |
411 lastElement = getElement(Tags.nullTag, key); | |
412 callDelegate = false; | |
413 return null; | |
414 } | |
18
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
415 |
0 | 416 lastElement = tmp; |
417 | |
418 auto runtimeType = getValueOfAttribute(Attributes.runtimeTypeAttribute); | |
21
51f05fd6a626
Merged changes from dsource repository.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
419 |
51f05fd6a626
Merged changes from dsource repository.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
420 if (!runtimeType) |
22 | 421 return T.init; |
21
51f05fd6a626
Merged changes from dsource repository.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
422 |
0 | 423 auto name = fromDataType!(string)(runtimeType); |
21
51f05fd6a626
Merged changes from dsource repository.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
424 id = getValueOfAttribute(Attributes.idAttribute); |
51f05fd6a626
Merged changes from dsource repository.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
425 |
51f05fd6a626
Merged changes from dsource repository.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
426 if (!id) |
51f05fd6a626
Merged changes from dsource repository.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
427 return T.init; |
0 | 428 |
20
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
429 T result = cast(T) newInstance(name); |
0 | 430 |
431 addUnarchivedReference(result, id); | |
432 | |
433 return result; | |
434 } | |
435 | |
436 private T unarchiveStruct (T) (DataType key) | |
437 { | |
18
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
438 auto element = getElement(Tags.structTag, key); |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
439 |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
440 if (element.isValid) |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
441 lastElement = element; |
0 | 442 |
443 return T.init; | |
444 } | |
445 | |
446 private T unarchiveString (T) (DataType key) | |
447 { | |
20
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
448 auto slice = unarchiveSlice(key); |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
449 |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
450 if (auto tmp = getUnarchivedSlice!(T)(slice)) |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
451 return *tmp; |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
452 |
18
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
453 auto element = getElement(Tags.stringTag, key); |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
454 |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
455 if (!element.isValid) |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
456 return T.init; |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
457 |
20
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
458 auto value = fromDataType!(T)(element.value); |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
459 slice.id = getValueOfAttribute(Attributes.idAttribute, element); |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
460 |
22 | 461 if (!slice.id) |
462 return T.init; | |
463 | |
20
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
464 addUnarchivedSlice(value, slice.id); |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
465 |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
466 return value; |
0 | 467 } |
468 | |
20
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
469 private T unarchiveArray (T) (DataType key, ref bool callDelegate) |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
470 { |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
471 auto slice = unarchiveSlice(key); |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
472 |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
473 if (auto tmp = getUnarchivedSlice!(T)(slice)) |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
474 { |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
475 callDelegate = false; |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
476 return *tmp; |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
477 } |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
478 |
0 | 479 T value; |
480 | |
18
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
481 auto element = getElement(Tags.arrayTag, key); |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
482 |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
483 if (!element.isValid) |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
484 return T.init; |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
485 |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
486 lastElement = element; |
21
51f05fd6a626
Merged changes from dsource repository.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
487 auto length = getValueOfAttribute(Attributes.lengthAttribute); |
51f05fd6a626
Merged changes from dsource repository.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
488 |
51f05fd6a626
Merged changes from dsource repository.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
489 if (!length) |
51f05fd6a626
Merged changes from dsource repository.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
490 return T.init; |
51f05fd6a626
Merged changes from dsource repository.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
491 |
0 | 492 value.length = fromDataType!(size_t)(length); |
20
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
493 slice.id = getValueOfAttribute(Attributes.idAttribute); |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
494 |
21
51f05fd6a626
Merged changes from dsource repository.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
495 if (!slice.id) |
51f05fd6a626
Merged changes from dsource repository.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
496 return T.init; |
51f05fd6a626
Merged changes from dsource repository.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
497 |
20
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
498 addUnarchivedSlice(value, slice.id); |
0 | 499 |
500 return value; | |
501 } | |
502 | |
503 private T unarchiveAssociativeArray (T) (DataType key) | |
504 { | |
18
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
505 auto element = getElement(Tags.associativeArrayTag, key); |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
506 |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
507 if (element.isValid) |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
508 lastElement = element; |
0 | 509 |
510 return T.init; | |
511 } | |
512 | |
513 private T unarchivePointer (T) (DataType key, ref bool callDelegate) | |
514 { | |
515 DataType id = unarchiveReference(key); | |
516 | |
517 if (auto reference = getUnarchivedReference!(T)(id)) | |
518 { | |
519 callDelegate = false; | |
520 return *reference; | |
521 } | |
18
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
522 |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
523 auto element = getElement(Tags.pointerTag, key); |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
524 |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
525 if (!element.isValid) |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
526 return T.init; |
0 | 527 |
18
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
528 lastElement = element; |
0 | 529 id = getValueOfAttribute(Attributes.idAttribute); |
21
51f05fd6a626
Merged changes from dsource repository.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
530 |
51f05fd6a626
Merged changes from dsource repository.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
531 if (!id) |
51f05fd6a626
Merged changes from dsource repository.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
532 return T.init; |
0 | 533 |
534 T result = new BaseTypeOfPointer!(T); | |
535 | |
536 addUnarchivedReference(result, id); | |
537 | |
538 return result; | |
539 } | |
540 | |
541 private T unarchiveEnum (T) (DataType key) | |
542 { | |
18
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
543 auto element = getElement(Tags.enumTag, key); |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
544 |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
545 if (!element.isValid) |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
546 return T.init; |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
547 |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
548 return fromDataType!(T)(element.value); |
0 | 549 } |
550 | |
551 private T unarchivePrimitive (T) (DataType key) | |
552 { | |
18
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
553 auto element = getElement(toDataType(T.stringof), key); |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
554 |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
555 if (!element.isValid) |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
556 return T.init; |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
557 |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
558 return fromDataType!(T)(element.value); |
0 | 559 } |
560 | |
561 private T unarchiveTypeDef (T) (DataType key) | |
562 { | |
18
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
563 auto element = getElement(Tags.typedefTag, key); |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
564 |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
565 if (element.isValid) |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
566 lastElement = element; |
0 | 567 |
568 return T.init; | |
569 } | |
570 | |
571 public AssociativeArrayVisitor!(KeyTypeOfAssociativeArray!(T), ValueTypeOfAssociativeArray!(T)) unarchiveAssociativeArrayVisitor (T) () | |
572 { | |
573 return AssociativeArrayVisitor!(KeyTypeOfAssociativeArray!(T), ValueTypeOfAssociativeArray!(T))(this); | |
574 } | |
575 | |
576 public void archiveBaseClass (T : Object) (DataType key) | |
577 { | |
9
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
578 lastElement = lastElement.element(Tags.baseTag) |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
579 .attribute(Attributes.typeAttribute, toDataType(T.stringof)) |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
580 .attribute(Attributes.keyAttribute, key); |
0 | 581 } |
582 | |
583 public void unarchiveBaseClass (T : Object) (DataType key) | |
584 { | |
18
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
585 auto element = getElement(Tags.baseTag, key); |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
586 |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
587 if (element.isValid) |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
588 lastElement = element; |
0 | 589 } |
590 | |
9
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
591 version (Tango) |
0 | 592 { |
9
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
593 template errorMessage (ArchiveMode mode = ArchiveMode.archiving) |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
594 { |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
595 static if (mode == ArchiveMode.archiving) |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
596 const errorMessage = "Could not continue archiving due to unrecognized data format: "; |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
597 |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
598 else static if (mode == ArchiveMode.unarchiving) |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
599 const errorMessage = "Could not continue unarchiving due to unrecognized data format: "; |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
600 } |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
601 } |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
602 |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
603 else |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
604 { |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
605 mixin( |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
606 `template errorMessage (ArchiveMode mode = ArchiveMode.archiving) |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
607 { |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
608 static if (mode == ArchiveMode.archiving) |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
609 enum errorMessage = "Could not continue archiving due to unrecognized data format: "; |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
610 |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
611 else static if (mode == ArchiveMode.unarchiving) |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
612 enum errorMessage = "Could not continue unarchiving due to unrecognized data format: "; |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
613 }` |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
614 ); |
0 | 615 } |
616 | |
617 private doc.Node getElement (DataType tag, DataType key, DataType attribute = Attributes.keyAttribute, bool throwOnError = true) | |
11
27c5b6c5425f
Deserialization now works as well using D2. Compiles again with D1 and Tango. Cleaned up orange.util.io a bit.
Jacob Carlborg <doob@me.com>
parents:
10
diff
changeset
|
618 { |
9
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
619 auto set = lastElement.query[tag].attribute((doc.Node node) { |
0 | 620 if (node.name == attribute && node.value == key) |
621 return true; | |
622 | |
623 return false; | |
624 }); | |
625 | |
626 if (set.nodes.length == 1) | |
627 return set.nodes[0].parent; | |
628 | |
629 else | |
630 { | |
18
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
631 if (throwOnError && errorCallback) |
0 | 632 { |
9
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
633 if (set.nodes.length == 0) |
18
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
634 errorCallback(new ArchiveException(`Could not find an element "` ~ to!(string)(tag) ~ `" with the attribute "` ~ to!(string)(Attributes.keyAttribute) ~ `" with the value "` ~ to!(string)(key) ~ `".`, __FILE__, __LINE__), [tag, Attributes.keyAttribute, key]); |
0 | 635 |
636 else | |
18
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
637 errorCallback(new ArchiveException(`Could not unarchive the value with the key "` ~ to!(string)(key) ~ `" due to malformed data.`, __FILE__, __LINE__), [tag, Attributes.keyAttribute, key]); |
0 | 638 } |
11
27c5b6c5425f
Deserialization now works as well using D2. Compiles again with D1 and Tango. Cleaned up orange.util.io a bit.
Jacob Carlborg <doob@me.com>
parents:
10
diff
changeset
|
639 |
9
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
640 return doc.Node.invalid; |
21
51f05fd6a626
Merged changes from dsource repository.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
641 } |
0 | 642 } |
643 | |
20
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
644 private DataType getValueOfAttribute (DataType attribute, doc.Node element = doc.Node.invalid) |
0 | 645 { |
20
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
646 if (!element.isValid) element = lastElement; |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
647 |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
648 auto set = element.query.attribute(attribute); |
0 | 649 |
650 if (set.nodes.length == 1) | |
651 return set.nodes[0].value; | |
652 | |
653 else | |
18
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
654 { |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
655 if (errorCallback) |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
656 { |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
657 if (set.nodes.length == 0) |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
658 errorCallback(new ArchiveException(`Could not find the attribute "` ~ to!(string)(attribute) ~ `".`, __FILE__, __LINE__), [attribute]); |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
659 |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
660 else |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
661 errorCallback(new ArchiveException(`Could not unarchive the value of the attribute "` ~ to!(string)(attribute) ~ `" due to malformed data.`, __FILE__, __LINE__), [attribute]); |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
662 } |
21
51f05fd6a626
Merged changes from dsource repository.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
663 } |
22 | 664 |
21
51f05fd6a626
Merged changes from dsource repository.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
665 return null; |
0 | 666 } |
667 | |
668 private void addArchivedReference (T) (T value, DataType id) | |
669 { | |
670 static assert(isReference!(T), format!(`The given type "`, T, `" is not a reference type, i.e. object or pointer.`)); | |
671 | |
672 archivedReferences[cast(void*) value] = id; | |
673 } | |
674 | |
675 private void addUnarchivedReference (T) (T value, DataType id) | |
676 { | |
677 static assert(isReference!(T), format!(`The given type "`, T, `" is not a reference type, i.e. object or pointer.`)); | |
678 | |
679 unarchivedReferences[id] = cast(void*) value; | |
680 } | |
681 | |
20
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
682 private void addUnarchivedSlice (T) (T value, DataType id) |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
683 { |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
684 static assert(isArray!(T) || isString!(T), format!(`The given type "`, T, `" is not a slice type, i.e. array or string.`)); |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
685 |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
686 unarchivedSlices[id] = value; |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
687 } |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
688 |
0 | 689 private DataType getArchivedReference (T) (T value) |
690 { | |
691 if (auto tmp = cast(void*) value in archivedReferences) | |
692 return *tmp; | |
693 | |
694 return null; | |
695 } | |
696 | |
697 private T* getUnarchivedReference (T) (DataType id) | |
698 { | |
699 if (auto reference = id in unarchivedReferences) | |
700 return cast(T*) reference; | |
701 | |
702 return null; | |
703 } | |
704 | |
20
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
705 private T* getUnarchivedSlice (T) (Slice slice) |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
706 { |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
707 if (auto array = slice.id in unarchivedSlices) |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
708 return &(cast(T) *array)[slice.offset .. slice.length + 1]; // dereference the array, cast it to the right type, |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
709 // slice it and then return a pointer to the result |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
710 return null; |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
711 } |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
712 |
0 | 713 private DataType nextId () |
714 { | |
715 return toDataType(idCounter++); | |
716 } | |
717 | |
718 private void archiveReference (DataType key, DataType id) | |
719 { | |
9
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
720 lastElement.element(Tags.referenceTag, id) |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
721 .attribute(Attributes.keyAttribute, key); |
0 | 722 } |
723 | |
724 private DataType unarchiveReference (DataType key) | |
725 { | |
726 auto element = getElement(Tags.referenceTag, key, Attributes.keyAttribute, false); | |
727 | |
9
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
728 if (element.isValid) |
0 | 729 return element.value; |
730 | |
731 return cast(DataType) null; | |
732 } | |
733 | |
20
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
734 private Slice unarchiveSlice (DataType key) |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
735 { |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
736 auto element = getElement(Tags.sliceTag, key, Attributes.keyAttribute, false); |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
737 |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
738 if (element.isValid) |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
739 { |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
740 auto length = fromDataType!(size_t)(getValueOfAttribute(Attributes.lengthAttribute, element)); |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
741 auto offset = fromDataType!(size_t)(getValueOfAttribute(Attributes.offsetAttribute, element)); |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
742 |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
743 return Slice(length, offset, element.value); |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
744 } |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
745 |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
746 return Slice.init; |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
747 } |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
748 |
6 | 749 private struct AssociativeArrayVisitor (Key, Value) |
0 | 750 { |
751 private XMLArchive archive; | |
752 | |
753 static AssociativeArrayVisitor opCall (XMLArchive archive) | |
754 { | |
755 AssociativeArrayVisitor aai; | |
756 aai.archive = archive; | |
757 | |
758 return aai; | |
759 } | |
760 | |
761 int opApply(int delegate(ref Key, ref Value) dg) | |
762 { | |
763 int result; | |
764 | |
765 foreach (node ; archive.lastElement.children) | |
766 { | |
767 restore(archive.lastElement) in { | |
768 archive.lastElement = node; | |
769 | |
770 if (node.attributes.exist) | |
771 { | |
772 Key key = to!(Key)(archive.getValueOfAttribute(Attributes.keyAttribute)); | |
773 Value value = to!(Value)(node.value); | |
774 | |
775 result = dg(key, value); | |
776 } | |
777 }; | |
778 | |
779 if (result) | |
780 break; | |
781 } | |
782 | |
783 return result; | |
784 } | |
785 } | |
20
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
786 |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
787 public void postProcess () |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
788 { |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
789 bool foundSlice = true; |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
790 |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
791 foreach (slice, sliceNode ; arraysToBeArchived) |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
792 { |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
793 foreach (array, arrayNode ; arraysToBeArchived) |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
794 { |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
795 if (slice.isSliceOf(array) && slice != array) |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
796 { |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
797 sliceNode.parent.element(Tags.sliceTag, arrayNode.id) |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
798 .attribute(Attributes.keyAttribute, sliceNode.key) |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
799 .attribute(Attributes.offsetAttribute, toDataType((slice.ptr - array.ptr) / slice.elementSize)) |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
800 .attribute(Attributes.lengthAttribute, toDataType(slice.length)); |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
801 |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
802 foundSlice = true; |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
803 break; |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
804 } |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
805 |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
806 else |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
807 foundSlice = false; |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
808 } |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
809 |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
810 if (!foundSlice) |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
811 sliceNode.parent.attach(sliceNode.node); |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
812 } |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
813 } |
0 | 814 } |