Mercurial > projects > orange
annotate orange/serialization/archives/XMLArchive.d @ 19:8ab9588b92bf
getValueOfAtrribute has no return at end of method. Fixes #5.
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Sat, 14 Aug 2010 17:24:42 +0200 |
parents | 3d42ea434d46 |
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"; | |
43 static const DataType enumTag = "enum"; | |
44 } | |
45 | |
46 private struct Attributes | |
47 { | |
48 static const DataType typeAttribute = "type"; | |
49 static const DataType versionAttribute = "version"; | |
50 static const DataType lengthAttribute = "length"; | |
51 static const DataType keyAttribute = "key"; | |
52 static const DataType runtimeTypeAttribute = "runtimeType"; | |
53 static const DataType idAttribute = "id"; | |
54 static const DataType keyTypeAttribute = "keyType"; | |
55 static const DataType valueTypeAttribute = "valueType"; | |
56 } | |
57 | |
58 private | |
59 { | |
60 DataType archiveType = "org.dsource.orange.xml"; | |
61 DataType archiveVersion = "0.1"; | |
62 | |
9
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
63 XMLDocument!(U) doc; |
0 | 64 doc.Node lastElement; |
9
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
65 //DocPrinter!(U) printer; |
0 | 66 doc.Node lastElementSaved; |
67 | |
68 bool hasBegunArchiving; | |
69 bool hasBegunUnarchiving; | |
70 | |
71 DataType[void*] archivedReferences; | |
72 void*[DataType] unarchivedReferences; | |
73 | |
74 size_t idCounter; | |
75 } | |
76 | |
77 this () | |
78 { | |
9
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
79 doc = new XMLDocument!(U); |
0 | 80 } |
81 | |
82 public void beginArchiving () | |
83 { | |
84 if (!hasBegunArchiving) | |
85 { | |
86 doc.header; | |
9
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
87 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
|
88 .attribute(Attributes.typeAttribute, archiveType) |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
89 .attribute(Attributes.versionAttribute, archiveVersion); |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
90 lastElement = lastElement.element(Tags.dataTag); |
0 | 91 |
92 hasBegunArchiving = true; | |
93 } | |
94 } | |
95 | |
96 public void beginUnarchiving (DataType data) | |
97 { | |
98 if (!hasBegunUnarchiving) | |
99 { | |
100 doc.parse(data); | |
101 hasBegunUnarchiving = true; | |
102 | |
103 auto set = doc.query[Tags.archiveTag][Tags.dataTag]; | |
104 | |
105 if (set.nodes.length == 1) | |
106 lastElement = set.nodes[0]; | |
107 | |
108 else | |
18
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
109 { |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
110 if (errorCallback) |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
111 { |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
112 if (set.nodes.length == 0) |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
113 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
|
114 |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
115 else |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
116 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
|
117 } |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
118 } |
0 | 119 } |
120 } | |
121 | |
122 public DataType data () | |
123 { | |
9
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
124 /*if (!printer) |
0 | 125 printer = new DocPrinter!(U); |
126 | |
9
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
127 return printer.print(doc);*/ |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
128 |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
129 return doc.toString(); |
0 | 130 } |
131 | |
132 public void reset () | |
133 { | |
134 hasBegunArchiving = false; | |
135 hasBegunUnarchiving = false; | |
136 idCounter = 0; | |
137 doc.reset; | |
138 } | |
139 | |
140 private void begin () | |
141 { | |
142 lastElementSaved = lastElement; | |
143 } | |
144 | |
145 private void end () | |
146 { | |
147 lastElement = lastElementSaved; | |
148 } | |
149 | |
150 public void archive (T) (T value, DataType key, void delegate () dg = null) | |
151 { | |
152 if (!hasBegunArchiving) | |
153 beginArchiving(); | |
154 | |
155 restore(lastElement) in { | |
156 bool callDelegate = true; | |
157 | |
158 static if (isTypeDef!(T)) | |
159 archiveTypeDef(value, key); | |
160 | |
161 else static if (isObject!(T)) | |
162 archiveObject(value, key, callDelegate); | |
163 | |
164 else static if (isStruct!(T)) | |
165 archiveStruct(value, key); | |
166 | |
167 else static if (isString!(T)) | |
168 archiveString(value, key); | |
169 | |
170 else static if (isArray!(T)) | |
171 archiveArray(value, key); | |
172 | |
173 else static if (isAssociativeArray!(T)) | |
174 archiveAssociativeArray(value, key); | |
175 | |
176 else static if (isPrimitive!(T)) | |
177 archivePrimitive(value, key); | |
178 | |
179 else static if (isPointer!(T)) | |
180 archivePointer(value, key, callDelegate); | |
181 | |
182 else static if (isEnum!(T)) | |
183 archiveEnum(value, key); | |
184 | |
185 else | |
186 static assert(false, format!(`The type "`, T, `" cannot be archived.`)); | |
187 | |
188 if (callDelegate && dg) | |
189 dg(); | |
190 }; | |
191 } | |
192 | |
193 private void archiveObject (T) (T value, DataType key, ref bool callDelegate) | |
194 { | |
195 if (!value) | |
196 { | |
9
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
197 lastElement.element(Tags.nullTag) |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
198 .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
|
199 .attribute(Attributes.keyAttribute, key); |
0 | 200 callDelegate = false; |
201 } | |
202 | |
203 else if (auto reference = getArchivedReference(value)) | |
204 { | |
205 archiveReference(key, reference); | |
206 callDelegate = false; | |
207 } | |
208 | |
209 else | |
210 { | |
211 DataType id = nextId; | |
212 | |
9
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
213 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
|
214 .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
|
215 .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
|
216 .attribute(Attributes.keyAttribute, key) |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
217 .attribute(Attributes.idAttribute, id); |
0 | 218 |
219 addArchivedReference(value, id); | |
220 } | |
221 } | |
222 | |
223 private void archiveStruct (T) (T value, DataType key) | |
224 { | |
9
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
225 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
|
226 .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
|
227 .attribute(Attributes.keyAttribute, key); |
0 | 228 } |
229 | |
230 private void archiveString (T) (T value, DataType key) | |
231 { | |
9
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
232 lastElement.element(Tags.stringTag, toDataType(value)) |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
233 .attribute(Attributes.typeAttribute, toDataType(BaseTypeOfArray!(T).stringof)) |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
234 .attribute(Attributes.keyAttribute, key); |
0 | 235 } |
236 | |
237 private void archiveArray (T) (T value, DataType key) | |
238 { | |
9
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
239 lastElement = lastElement.element(Tags.arrayTag) |
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(BaseTypeOfArray!(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.lengthAttribute, toDataType(value.length)) |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
242 .attribute(Attributes.keyAttribute, key); |
0 | 243 } |
244 | |
245 private void archiveAssociativeArray (T) (T value, DataType key) | |
246 { | |
9
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
247 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
|
248 .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
|
249 .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
|
250 .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
|
251 .attribute(Attributes.keyAttribute, key); |
0 | 252 } |
253 | |
254 private void archivePointer (T) (T value, DataType key, ref bool callDelegate) | |
255 { | |
256 if (auto reference = getArchivedReference(value)) | |
257 { | |
258 archiveReference(key, reference); | |
259 callDelegate = false; | |
260 } | |
261 | |
262 else | |
263 { | |
264 DataType id = nextId; | |
265 | |
9
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
266 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
|
267 .attribute(Attributes.keyAttribute, key) |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
268 .attribute(Attributes.idAttribute, id); |
0 | 269 |
270 addArchivedReference(value, id); | |
271 } | |
272 } | |
273 | |
274 private void archiveEnum (T) (T value, DataType key) | |
275 { | |
9
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
276 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
|
277 .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
|
278 .attribute(Attributes.keyAttribute, key); |
0 | 279 } |
280 | |
281 private void archivePrimitive (T) (T value, DataType key) | |
282 { | |
9
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
283 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
|
284 .attribute(Attributes.keyAttribute, key); |
0 | 285 } |
286 | |
287 private void archiveTypeDef (T) (T value, DataType key) | |
288 { | |
9
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
289 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
|
290 .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
|
291 .attribute(Attributes.key, key); |
0 | 292 } |
293 | |
294 public T unarchive (T) (DataType key, T delegate (T) dg = null) | |
295 { | |
296 if (!hasBegunUnarchiving) | |
297 beginUnarchiving(data); | |
298 | |
299 return restore!(T)(lastElement) in { | |
300 T value; | |
301 | |
302 bool callDelegate = true; | |
303 | |
304 static if (isTypeDef!(T)) | |
305 value = unarchiveTypeDef!(T)(key); | |
306 | |
307 else static if (isObject!(T)) | |
308 value = unarchiveObject!(T)(key, callDelegate); | |
309 | |
310 else static if (isStruct!(T)) | |
311 value = unarchiveStruct!(T)(key); | |
312 | |
313 else static if (isString!(T)) | |
314 value = unarchiveString!(T)(key); | |
315 | |
316 else static if (isArray!(T)) | |
317 value = unarchiveArray!(T)(key); | |
318 | |
319 else static if (isAssociativeArray!(T)) | |
320 value = unarchiveAssociativeArray!(T)(key); | |
321 | |
322 else static if (isPrimitive!(T)) | |
323 value = unarchivePrimitive!(T)(key); | |
324 | |
325 else static if (isPointer!(T)) | |
326 value = unarchivePointer!(T)(key, callDelegate); | |
327 | |
328 else static if (isEnum!(T)) | |
329 value = unarchiveEnum!(T)(key); | |
330 | |
331 else | |
332 static assert(false, format!(`The type "`, T, `" cannot be unarchived.`)); | |
333 | |
334 if (callDelegate && dg) | |
335 return dg(value); | |
336 | |
337 return value; | |
338 }; | |
339 } | |
340 | |
341 private T unarchiveObject (T) (DataType key, ref bool callDelegate) | |
342 { | |
343 DataType id = unarchiveReference(key); | |
344 | |
345 if (auto reference = getUnarchivedReference!(T)(id)) | |
346 { | |
347 callDelegate = false; | |
348 return *reference; | |
349 } | |
350 | |
351 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
|
352 |
9
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
353 if (!tmp.isValid) |
0 | 354 { |
355 lastElement = getElement(Tags.nullTag, key); | |
356 callDelegate = false; | |
357 return null; | |
358 } | |
18
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
359 |
0 | 360 lastElement = tmp; |
361 | |
362 auto runtimeType = getValueOfAttribute(Attributes.runtimeTypeAttribute); | |
19
8ab9588b92bf
getValueOfAtrribute has no return at end of method. Fixes #5.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
363 |
8ab9588b92bf
getValueOfAtrribute has no return at end of method. Fixes #5.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
364 if (!runtimeType) |
8ab9588b92bf
getValueOfAtrribute has no return at end of method. Fixes #5.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
365 return T.init; |
8ab9588b92bf
getValueOfAtrribute has no return at end of method. Fixes #5.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
366 |
0 | 367 auto name = fromDataType!(string)(runtimeType); |
368 id = getValueOfAttribute(Attributes.idAttribute); | |
19
8ab9588b92bf
getValueOfAtrribute has no return at end of method. Fixes #5.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
369 |
8ab9588b92bf
getValueOfAtrribute has no return at end of method. Fixes #5.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
370 if (!id) |
8ab9588b92bf
getValueOfAtrribute has no return at end of method. Fixes #5.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
371 return T.init; |
0 | 372 |
373 T result; | |
374 | |
9
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
375 /*static if (is(typeof(T._ctor))) |
0 | 376 { |
377 ParameterTupleOf!(typeof(T._ctor)) params; | |
378 result = factory!(T, typeof(params))(name, params); | |
379 } | |
380 | |
9
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
381 else*/ |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
382 result = cast(T) newInstance(name); |
0 | 383 |
384 addUnarchivedReference(result, id); | |
385 | |
386 return result; | |
387 } | |
388 | |
389 private T unarchiveStruct (T) (DataType key) | |
390 { | |
18
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
391 auto element = getElement(Tags.structTag, key); |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
392 |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
393 if (element.isValid) |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
394 lastElement = element; |
0 | 395 |
396 return T.init; | |
397 } | |
398 | |
399 private T unarchiveString (T) (DataType key) | |
400 { | |
18
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
401 auto element = getElement(Tags.stringTag, key); |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
402 |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
403 if (!element.isValid) |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
404 return T.init; |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
405 |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
406 return fromDataType!(T)(element.value); |
0 | 407 } |
408 | |
409 private T unarchiveArray (T) (DataType key) | |
410 { | |
411 T value; | |
412 | |
18
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
413 auto element = getElement(Tags.arrayTag, key); |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
414 |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
415 if (!element.isValid) |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
416 return T.init; |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
417 |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
418 lastElement = element; |
0 | 419 auto length = getValueOfAttribute(Attributes.lengthAttribute); |
19
8ab9588b92bf
getValueOfAtrribute has no return at end of method. Fixes #5.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
420 |
8ab9588b92bf
getValueOfAtrribute has no return at end of method. Fixes #5.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
421 if (!length) |
8ab9588b92bf
getValueOfAtrribute has no return at end of method. Fixes #5.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
422 return T.init; |
8ab9588b92bf
getValueOfAtrribute has no return at end of method. Fixes #5.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
423 |
0 | 424 value.length = fromDataType!(size_t)(length); |
425 | |
426 return value; | |
427 } | |
428 | |
429 private T unarchiveAssociativeArray (T) (DataType key) | |
430 { | |
18
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
431 auto element = getElement(Tags.associativeArrayTag, key); |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
432 |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
433 if (element.isValid) |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
434 lastElement = element; |
0 | 435 |
436 return T.init; | |
437 } | |
438 | |
439 private T unarchivePointer (T) (DataType key, ref bool callDelegate) | |
440 { | |
441 DataType id = unarchiveReference(key); | |
442 | |
443 if (auto reference = getUnarchivedReference!(T)(id)) | |
444 { | |
445 callDelegate = false; | |
446 return *reference; | |
447 } | |
18
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
448 |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
449 auto element = getElement(Tags.pointerTag, key); |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
450 |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
451 if (!element.isValid) |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
452 return T.init; |
0 | 453 |
18
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
454 lastElement = element; |
0 | 455 id = getValueOfAttribute(Attributes.idAttribute); |
19
8ab9588b92bf
getValueOfAtrribute has no return at end of method. Fixes #5.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
456 |
8ab9588b92bf
getValueOfAtrribute has no return at end of method. Fixes #5.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
457 if (!id) |
8ab9588b92bf
getValueOfAtrribute has no return at end of method. Fixes #5.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
458 return T.init; |
0 | 459 |
460 T result = new BaseTypeOfPointer!(T); | |
461 | |
462 addUnarchivedReference(result, id); | |
463 | |
464 return result; | |
465 } | |
466 | |
467 private T unarchiveEnum (T) (DataType key) | |
468 { | |
18
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
469 auto element = getElement(Tags.enumTag, key); |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
470 |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
471 if (!element.isValid) |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
472 return T.init; |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
473 |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
474 return fromDataType!(T)(element.value); |
0 | 475 } |
476 | |
477 private T unarchivePrimitive (T) (DataType key) | |
478 { | |
18
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
479 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
|
480 |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
481 if (!element.isValid) |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
482 return T.init; |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
483 |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
484 return fromDataType!(T)(element.value); |
0 | 485 } |
486 | |
487 private T unarchiveTypeDef (T) (DataType key) | |
488 { | |
18
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
489 auto element = getElement(Tags.typedefTag, key); |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
490 |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
491 if (element.isValid) |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
492 lastElement = element; |
0 | 493 |
494 return T.init; | |
495 } | |
496 | |
497 public AssociativeArrayVisitor!(KeyTypeOfAssociativeArray!(T), ValueTypeOfAssociativeArray!(T)) unarchiveAssociativeArrayVisitor (T) () | |
498 { | |
499 return AssociativeArrayVisitor!(KeyTypeOfAssociativeArray!(T), ValueTypeOfAssociativeArray!(T))(this); | |
500 } | |
501 | |
502 public void archiveBaseClass (T : Object) (DataType key) | |
503 { | |
9
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
504 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
|
505 .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
|
506 .attribute(Attributes.keyAttribute, key); |
0 | 507 } |
508 | |
509 public void unarchiveBaseClass (T : Object) (DataType key) | |
510 { | |
18
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
511 auto element = getElement(Tags.baseTag, key); |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
512 |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
513 if (element.isValid) |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
514 lastElement = element; |
0 | 515 } |
516 | |
9
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
517 version (Tango) |
0 | 518 { |
9
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
519 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
|
520 { |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
521 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
|
522 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
|
523 |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
524 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
|
525 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
|
526 } |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
527 } |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
528 |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
529 else |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
530 { |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
531 mixin( |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
532 `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
|
533 { |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
534 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
|
535 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
|
536 |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
537 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
|
538 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
|
539 }` |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
540 ); |
0 | 541 } |
542 | |
543 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
|
544 { |
9
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
545 auto set = lastElement.query[tag].attribute((doc.Node node) { |
0 | 546 if (node.name == attribute && node.value == key) |
547 return true; | |
548 | |
549 return false; | |
550 }); | |
551 | |
552 if (set.nodes.length == 1) | |
553 return set.nodes[0].parent; | |
554 | |
555 else | |
556 { | |
18
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
557 if (throwOnError && errorCallback) |
0 | 558 { |
9
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
559 if (set.nodes.length == 0) |
18
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
560 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 | 561 |
562 else | |
18
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
563 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 | 564 } |
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
|
565 |
9
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
566 return doc.Node.invalid; |
0 | 567 } |
568 } | |
569 | |
570 private DataType getValueOfAttribute (DataType attribute) | |
571 { | |
572 auto set = lastElement.query.attribute(attribute); | |
573 | |
574 if (set.nodes.length == 1) | |
575 return set.nodes[0].value; | |
576 | |
577 else | |
18
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
578 { |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
579 if (errorCallback) |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
580 { |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
581 if (set.nodes.length == 0) |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
582 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
|
583 |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
584 else |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
11
diff
changeset
|
585 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
|
586 } |
19
8ab9588b92bf
getValueOfAtrribute has no return at end of method. Fixes #5.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
587 } |
8ab9588b92bf
getValueOfAtrribute has no return at end of method. Fixes #5.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
588 |
8ab9588b92bf
getValueOfAtrribute has no return at end of method. Fixes #5.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
589 return null; |
0 | 590 } |
591 | |
592 private void addArchivedReference (T) (T value, DataType id) | |
593 { | |
594 static assert(isReference!(T), format!(`The given type "`, T, `" is not a reference type, i.e. object or pointer.`)); | |
595 | |
596 archivedReferences[cast(void*) value] = id; | |
597 } | |
598 | |
599 private void addUnarchivedReference (T) (T value, DataType id) | |
600 { | |
601 static assert(isReference!(T), format!(`The given type "`, T, `" is not a reference type, i.e. object or pointer.`)); | |
602 | |
603 unarchivedReferences[id] = cast(void*) value; | |
604 } | |
605 | |
606 private DataType getArchivedReference (T) (T value) | |
607 { | |
608 if (auto tmp = cast(void*) value in archivedReferences) | |
609 return *tmp; | |
610 | |
611 return null; | |
612 } | |
613 | |
614 private T* getUnarchivedReference (T) (DataType id) | |
615 { | |
616 if (auto reference = id in unarchivedReferences) | |
617 return cast(T*) reference; | |
618 | |
619 return null; | |
620 } | |
621 | |
622 private DataType nextId () | |
623 { | |
624 return toDataType(idCounter++); | |
625 } | |
626 | |
627 private void archiveReference (DataType key, DataType id) | |
628 { | |
9
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
629 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
|
630 .attribute(Attributes.keyAttribute, key); |
0 | 631 } |
632 | |
633 private DataType unarchiveReference (DataType key) | |
634 { | |
635 auto element = getElement(Tags.referenceTag, key, Attributes.keyAttribute, false); | |
636 | |
9
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
6
diff
changeset
|
637 if (element.isValid) |
0 | 638 return element.value; |
639 | |
640 return cast(DataType) null; | |
641 } | |
642 | |
6 | 643 private struct AssociativeArrayVisitor (Key, Value) |
0 | 644 { |
645 private XMLArchive archive; | |
646 | |
647 static AssociativeArrayVisitor opCall (XMLArchive archive) | |
648 { | |
649 AssociativeArrayVisitor aai; | |
650 aai.archive = archive; | |
651 | |
652 return aai; | |
653 } | |
654 | |
655 int opApply(int delegate(ref Key, ref Value) dg) | |
656 { | |
657 int result; | |
658 | |
659 foreach (node ; archive.lastElement.children) | |
660 { | |
661 restore(archive.lastElement) in { | |
662 archive.lastElement = node; | |
663 | |
664 if (node.attributes.exist) | |
665 { | |
666 Key key = to!(Key)(archive.getValueOfAttribute(Attributes.keyAttribute)); | |
667 Value value = to!(Value)(node.value); | |
668 | |
669 result = dg(key, value); | |
670 } | |
671 }; | |
672 | |
673 if (result) | |
674 break; | |
675 } | |
676 | |
677 return result; | |
678 } | |
679 } | |
680 } |