Mercurial > projects > orange
annotate orange/serialization/archives/XMLArchive.d @ 21:51f05fd6a626
Merged changes from dsource repository.
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Mon, 04 Oct 2010 20:18:02 +0200 |
parents | 9a575087b961 |
children | 963b756ed579 |
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) |
51f05fd6a626
Merged changes from dsource repository.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
421 return T.init; |
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; |
51f05fd6a626
Merged changes from dsource repository.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
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 |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
461 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
|
462 |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
463 return value; |
0 | 464 } |
465 | |
20
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
466 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
|
467 { |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
468 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
|
469 |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
470 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
|
471 { |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
472 callDelegate = false; |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
473 return *tmp; |
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 |
0 | 476 T value; |
477 | |
18
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
478 auto element = getElement(Tags.arrayTag, key); |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
479 |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
480 if (!element.isValid) |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
481 return T.init; |
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 lastElement = element; |
21
51f05fd6a626
Merged changes from dsource repository.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
484 auto length = getValueOfAttribute(Attributes.lengthAttribute); |
51f05fd6a626
Merged changes from dsource repository.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
485 |
51f05fd6a626
Merged changes from dsource repository.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
486 if (!length) |
51f05fd6a626
Merged changes from dsource repository.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
487 return T.init; |
51f05fd6a626
Merged changes from dsource repository.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
488 |
0 | 489 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
|
490 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
|
491 |
21
51f05fd6a626
Merged changes from dsource repository.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
492 if (!slice.id) |
51f05fd6a626
Merged changes from dsource repository.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
493 return T.init; |
51f05fd6a626
Merged changes from dsource repository.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
494 |
20
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
495 addUnarchivedSlice(value, slice.id); |
0 | 496 |
497 return value; | |
498 } | |
499 | |
500 private T unarchiveAssociativeArray (T) (DataType key) | |
501 { | |
18
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
502 auto element = getElement(Tags.associativeArrayTag, key); |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
503 |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
504 if (element.isValid) |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
505 lastElement = element; |
0 | 506 |
507 return T.init; | |
508 } | |
509 | |
510 private T unarchivePointer (T) (DataType key, ref bool callDelegate) | |
511 { | |
512 DataType id = unarchiveReference(key); | |
513 | |
514 if (auto reference = getUnarchivedReference!(T)(id)) | |
515 { | |
516 callDelegate = false; | |
517 return *reference; | |
518 } | |
18
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
519 |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
520 auto element = getElement(Tags.pointerTag, key); |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
521 |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
522 if (!element.isValid) |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
523 return T.init; |
0 | 524 |
18
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
525 lastElement = element; |
0 | 526 id = getValueOfAttribute(Attributes.idAttribute); |
21
51f05fd6a626
Merged changes from dsource repository.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
527 |
51f05fd6a626
Merged changes from dsource repository.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
528 if (!id) |
51f05fd6a626
Merged changes from dsource repository.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
529 return T.init; |
0 | 530 |
531 T result = new BaseTypeOfPointer!(T); | |
532 | |
533 addUnarchivedReference(result, id); | |
534 | |
535 return result; | |
536 } | |
537 | |
538 private T unarchiveEnum (T) (DataType key) | |
539 { | |
18
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
540 auto element = getElement(Tags.enumTag, key); |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
541 |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
542 if (!element.isValid) |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
543 return T.init; |
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 return fromDataType!(T)(element.value); |
0 | 546 } |
547 | |
548 private T unarchivePrimitive (T) (DataType key) | |
549 { | |
18
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
550 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
|
551 |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
552 if (!element.isValid) |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
553 return T.init; |
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 return fromDataType!(T)(element.value); |
0 | 556 } |
557 | |
558 private T unarchiveTypeDef (T) (DataType key) | |
559 { | |
18
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
560 auto element = getElement(Tags.typedefTag, key); |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
561 |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
562 if (element.isValid) |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
563 lastElement = element; |
0 | 564 |
565 return T.init; | |
566 } | |
567 | |
568 public AssociativeArrayVisitor!(KeyTypeOfAssociativeArray!(T), ValueTypeOfAssociativeArray!(T)) unarchiveAssociativeArrayVisitor (T) () | |
569 { | |
570 return AssociativeArrayVisitor!(KeyTypeOfAssociativeArray!(T), ValueTypeOfAssociativeArray!(T))(this); | |
571 } | |
572 | |
573 public void archiveBaseClass (T : Object) (DataType key) | |
574 { | |
9
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
575 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
|
576 .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
|
577 .attribute(Attributes.keyAttribute, key); |
0 | 578 } |
579 | |
580 public void unarchiveBaseClass (T : Object) (DataType key) | |
581 { | |
18
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
582 auto element = getElement(Tags.baseTag, key); |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
583 |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
584 if (element.isValid) |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
585 lastElement = element; |
0 | 586 } |
587 | |
9
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
588 version (Tango) |
0 | 589 { |
9
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
590 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
|
591 { |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
592 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
|
593 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
|
594 |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
595 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
|
596 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
|
597 } |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
598 } |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
599 |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
600 else |
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 mixin( |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
603 `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
|
604 { |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
605 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
|
606 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
|
607 |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
608 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
|
609 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
|
610 }` |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
611 ); |
0 | 612 } |
613 | |
614 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
|
615 { |
9
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
616 auto set = lastElement.query[tag].attribute((doc.Node node) { |
0 | 617 if (node.name == attribute && node.value == key) |
618 return true; | |
619 | |
620 return false; | |
621 }); | |
622 | |
623 if (set.nodes.length == 1) | |
624 return set.nodes[0].parent; | |
625 | |
626 else | |
627 { | |
18
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
628 if (throwOnError && errorCallback) |
0 | 629 { |
9
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
630 if (set.nodes.length == 0) |
18
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
631 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 | 632 |
633 else | |
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 unarchive the value with the key "` ~ to!(string)(key) ~ `" due to malformed data.`, __FILE__, __LINE__), [tag, Attributes.keyAttribute, key]); |
0 | 635 } |
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
|
636 |
9
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
637 return doc.Node.invalid; |
21
51f05fd6a626
Merged changes from dsource repository.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
638 } |
0 | 639 } |
640 | |
20
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
641 private DataType getValueOfAttribute (DataType attribute, doc.Node element = doc.Node.invalid) |
0 | 642 { |
20
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
643 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
|
644 |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
645 auto set = element.query.attribute(attribute); |
0 | 646 |
647 if (set.nodes.length == 1) | |
648 return set.nodes[0].value; | |
649 | |
650 else | |
18
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
651 { |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
652 if (errorCallback) |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
653 { |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
654 if (set.nodes.length == 0) |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
655 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
|
656 |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
657 else |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
658 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
|
659 } |
21
51f05fd6a626
Merged changes from dsource repository.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
660 } |
51f05fd6a626
Merged changes from dsource repository.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
661 |
51f05fd6a626
Merged changes from dsource repository.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
662 return null; |
0 | 663 } |
664 | |
665 private void addArchivedReference (T) (T value, DataType id) | |
666 { | |
667 static assert(isReference!(T), format!(`The given type "`, T, `" is not a reference type, i.e. object or pointer.`)); | |
668 | |
669 archivedReferences[cast(void*) value] = id; | |
670 } | |
671 | |
672 private void addUnarchivedReference (T) (T value, DataType id) | |
673 { | |
674 static assert(isReference!(T), format!(`The given type "`, T, `" is not a reference type, i.e. object or pointer.`)); | |
675 | |
676 unarchivedReferences[id] = cast(void*) value; | |
677 } | |
678 | |
20
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
679 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
|
680 { |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
681 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
|
682 |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
683 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
|
684 } |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
685 |
0 | 686 private DataType getArchivedReference (T) (T value) |
687 { | |
688 if (auto tmp = cast(void*) value in archivedReferences) | |
689 return *tmp; | |
690 | |
691 return null; | |
692 } | |
693 | |
694 private T* getUnarchivedReference (T) (DataType id) | |
695 { | |
696 if (auto reference = id in unarchivedReferences) | |
697 return cast(T*) reference; | |
698 | |
699 return null; | |
700 } | |
701 | |
20
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
702 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
|
703 { |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
704 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
|
705 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
|
706 // 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
|
707 return null; |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
708 } |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
709 |
0 | 710 private DataType nextId () |
711 { | |
712 return toDataType(idCounter++); | |
713 } | |
714 | |
715 private void archiveReference (DataType key, DataType id) | |
716 { | |
9
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
717 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
|
718 .attribute(Attributes.keyAttribute, key); |
0 | 719 } |
720 | |
721 private DataType unarchiveReference (DataType key) | |
722 { | |
723 auto element = getElement(Tags.referenceTag, key, Attributes.keyAttribute, false); | |
724 | |
9
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
725 if (element.isValid) |
0 | 726 return element.value; |
727 | |
728 return cast(DataType) null; | |
729 } | |
730 | |
20
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
731 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
|
732 { |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
733 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
|
734 |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
735 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
|
736 { |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
737 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
|
738 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
|
739 |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
740 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
|
741 } |
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.init; |
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 |
6 | 746 private struct AssociativeArrayVisitor (Key, Value) |
0 | 747 { |
748 private XMLArchive archive; | |
749 | |
750 static AssociativeArrayVisitor opCall (XMLArchive archive) | |
751 { | |
752 AssociativeArrayVisitor aai; | |
753 aai.archive = archive; | |
754 | |
755 return aai; | |
756 } | |
757 | |
758 int opApply(int delegate(ref Key, ref Value) dg) | |
759 { | |
760 int result; | |
761 | |
762 foreach (node ; archive.lastElement.children) | |
763 { | |
764 restore(archive.lastElement) in { | |
765 archive.lastElement = node; | |
766 | |
767 if (node.attributes.exist) | |
768 { | |
769 Key key = to!(Key)(archive.getValueOfAttribute(Attributes.keyAttribute)); | |
770 Value value = to!(Value)(node.value); | |
771 | |
772 result = dg(key, value); | |
773 } | |
774 }; | |
775 | |
776 if (result) | |
777 break; | |
778 } | |
779 | |
780 return result; | |
781 } | |
782 } | |
20
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
783 |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
784 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
|
785 { |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
786 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
|
787 |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
788 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
|
789 { |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
790 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
|
791 { |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
792 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
|
793 { |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
794 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
|
795 .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
|
796 .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
|
797 .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
|
798 |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
799 foundSlice = true; |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
800 break; |
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 |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
803 else |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
804 foundSlice = false; |
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 |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
807 if (!foundSlice) |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
808 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
|
809 } |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
810 } |
0 | 811 } |