Mercurial > projects > orange
annotate orange/serialization/Serializer.d @ 46:d6fbd0b3586e
Issue 8: Wrong results for array of arrays. (Temporary fix).
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Tue, 09 Aug 2011 11:38:50 +0200 |
parents | 8b9409423740 |
children | 9c9bbef6bf5e |
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.Serializer; | |
8 | |
9 version (Tango) | |
9
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
8
diff
changeset
|
10 import tango.util.Convert : to, ConversionException; |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
8
diff
changeset
|
11 |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
8
diff
changeset
|
12 else |
0 | 13 { |
9
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
8
diff
changeset
|
14 import std.conv; |
34
068e853b9c07
Cleaned up. Updated to latest D2 compiler.
Jacob Carlborg <doob@me.com>
parents:
33
diff
changeset
|
15 alias ConvException ConversionException; |
0 | 16 } |
17 | |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
18 import orange.core._; |
0 | 19 import orange.serialization._; |
34
068e853b9c07
Cleaned up. Updated to latest D2 compiler.
Jacob Carlborg <doob@me.com>
parents:
33
diff
changeset
|
20 import orange.serialization.archives.Archive; |
068e853b9c07
Cleaned up. Updated to latest D2 compiler.
Jacob Carlborg <doob@me.com>
parents:
33
diff
changeset
|
21 import orange.serialization.archives.ArchiveException; |
0 | 22 import orange.util._; |
23 | |
24 private | |
25 { | |
26 alias orange.util.CTFE.contains ctfeContains; | |
20
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
27 |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
28 enum Mode |
0 | 29 { |
30 serializing, | |
31 deserializing | |
32 } | |
33 | |
34 alias Mode.serializing serializing; | |
35 alias Mode.deserializing deserializing; | |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
36 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
37 private char toUpper (char c) |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
38 { |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
39 if (c >= 'a' && c <= 'z') |
34
068e853b9c07
Cleaned up. Updated to latest D2 compiler.
Jacob Carlborg <doob@me.com>
parents:
33
diff
changeset
|
40 return cast(char) (c - 32); |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
41 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
42 return c; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
43 } |
0 | 44 } |
45 | |
25
b51e953f79eb
Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
46 class Serializer |
0 | 47 { |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
48 alias void delegate (ArchiveException exception, string[] data) ErrorCallback; |
34
068e853b9c07
Cleaned up. Updated to latest D2 compiler.
Jacob Carlborg <doob@me.com>
parents:
33
diff
changeset
|
49 alias Archive.UntypedData Data; |
068e853b9c07
Cleaned up. Updated to latest D2 compiler.
Jacob Carlborg <doob@me.com>
parents:
33
diff
changeset
|
50 alias Archive.Id Id; |
18
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
17
diff
changeset
|
51 |
0 | 52 private |
33
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
53 { |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
54 struct ValueMeta |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
55 { |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
56 Id id; |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
57 string key; |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
58 } |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
59 |
25
b51e953f79eb
Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
60 ErrorCallback errorCallback_; |
39 | 61 Archive archive_; |
25
b51e953f79eb
Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
62 |
b51e953f79eb
Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
63 size_t keyCounter; |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
64 Id idCounter; |
0 | 65 |
66 RegisterBase[string] serializers; | |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
67 RegisterBase[string] deserializers; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
68 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
69 Id[void*] serializedReferences; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
70 void*[Id] deserializedReferences; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
71 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
72 Array[Id] serializedArrays; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
73 void[][Id] deserializedSlices; |
0 | 74 |
31
c68d29967c9f
Fixed some bugs in the handling of pointers.
Jacob Carlborg <doob@me.com>
parents:
30
diff
changeset
|
75 void*[Id] serializedPointers; |
33
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
76 void**[Id] deserializedPointers; |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
77 |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
78 ValueMeta[void*] serializedValues; |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
79 void*[Id] deserializedValues; |
29
c422ff6477dd
Better handling of serializing pointers.
Jacob Carlborg <doob@me.com>
parents:
28
diff
changeset
|
80 |
0 | 81 bool hasBegunSerializing; |
82 bool hasBegunDeserializing; | |
18
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
17
diff
changeset
|
83 |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
84 void delegate (ArchiveException exception, string[] data) throwOnErrorCallback; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
85 void delegate (ArchiveException exception, string[] data) doNothingOnErrorCallback; |
0 | 86 } |
87 | |
28
bffcbc8c392b
Associative arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
27
diff
changeset
|
88 this (Archive archive) |
0 | 89 { |
39 | 90 this.archive_ = archive; |
18
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
17
diff
changeset
|
91 |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
92 throwOnErrorCallback = (ArchiveException exception, string[] data) { throw exception; }; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
93 doNothingOnErrorCallback = (ArchiveException exception, string[] data) { /* do nothing */ }; |
18
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
17
diff
changeset
|
94 |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
17
diff
changeset
|
95 setThrowOnErrorCallback(); |
0 | 96 } |
97 | |
39 | 98 Archive archive () |
99 { | |
100 return archive_; | |
101 } | |
102 | |
18
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
17
diff
changeset
|
103 ErrorCallback errorCallback () |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
17
diff
changeset
|
104 { |
25
b51e953f79eb
Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
105 return errorCallback_; |
18
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
17
diff
changeset
|
106 } |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
17
diff
changeset
|
107 |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
17
diff
changeset
|
108 ErrorCallback errorCallback (ErrorCallback errorCallback) |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
17
diff
changeset
|
109 { |
25
b51e953f79eb
Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
110 return errorCallback_ = errorCallback; |
18
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
17
diff
changeset
|
111 } |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
17
diff
changeset
|
112 |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
17
diff
changeset
|
113 void setThrowOnErrorCallback () |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
17
diff
changeset
|
114 { |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
17
diff
changeset
|
115 errorCallback = throwOnErrorCallback; |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
17
diff
changeset
|
116 } |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
17
diff
changeset
|
117 |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
17
diff
changeset
|
118 void setDoNothingOnErrorCallback () |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
17
diff
changeset
|
119 { |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
17
diff
changeset
|
120 errorCallback = doNothingOnErrorCallback; |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
17
diff
changeset
|
121 } |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
17
diff
changeset
|
122 |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
123 void reset () |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
124 { |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
125 resetCounters(); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
126 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
127 serializers = null; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
128 deserializers = null; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
129 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
130 serializedReferences = null; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
131 deserializedReferences = null; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
132 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
133 serializedArrays = null; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
134 deserializedSlices = null; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
135 |
29
c422ff6477dd
Better handling of serializing pointers.
Jacob Carlborg <doob@me.com>
parents:
28
diff
changeset
|
136 serializedValues = null; |
c422ff6477dd
Better handling of serializing pointers.
Jacob Carlborg <doob@me.com>
parents:
28
diff
changeset
|
137 serializedPointers = null; |
c422ff6477dd
Better handling of serializing pointers.
Jacob Carlborg <doob@me.com>
parents:
28
diff
changeset
|
138 |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
139 hasBegunSerializing = false; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
140 hasBegunDeserializing = false; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
141 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
142 archive.reset; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
143 } |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
144 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
145 Data serialize (T) (T value, string key = null) |
0 | 146 { |
147 if (!hasBegunSerializing) | |
148 hasBegunSerializing = true; | |
149 | |
20
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
150 serializeInternal(value, key); |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
151 postProcess; |
20
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
152 |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
153 return archive.untypedData; |
20
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
154 } |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
155 |
30
9d1a8023bb89
Added IDs to every serialized value.
Jacob Carlborg <doob@me.com>
parents:
29
diff
changeset
|
156 private void serializeInternal (T) (T value, string key = null, Id id = Id.max) |
20
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
157 { |
0 | 158 if (!key) |
159 key = nextKey; | |
33
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
160 |
30
9d1a8023bb89
Added IDs to every serialized value.
Jacob Carlborg <doob@me.com>
parents:
29
diff
changeset
|
161 if (id == Id.max) |
9d1a8023bb89
Added IDs to every serialized value.
Jacob Carlborg <doob@me.com>
parents:
29
diff
changeset
|
162 id = nextId; |
33
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
163 |
0 | 164 archive.beginArchiving(); |
33
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
165 |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
166 static if ( is(T == typedef) ) |
30
9d1a8023bb89
Added IDs to every serialized value.
Jacob Carlborg <doob@me.com>
parents:
29
diff
changeset
|
167 serializeTypedef(value, key, id); |
0 | 168 |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
169 else static if (isObject!(T)) |
30
9d1a8023bb89
Added IDs to every serialized value.
Jacob Carlborg <doob@me.com>
parents:
29
diff
changeset
|
170 serializeObject(value, key, id); |
0 | 171 |
172 else static if (isStruct!(T)) | |
30
9d1a8023bb89
Added IDs to every serialized value.
Jacob Carlborg <doob@me.com>
parents:
29
diff
changeset
|
173 serializeStruct(value, key, id); |
0 | 174 |
175 else static if (isString!(T)) | |
30
9d1a8023bb89
Added IDs to every serialized value.
Jacob Carlborg <doob@me.com>
parents:
29
diff
changeset
|
176 serializeString(value, key, id); |
0 | 177 |
178 else static if (isArray!(T)) | |
30
9d1a8023bb89
Added IDs to every serialized value.
Jacob Carlborg <doob@me.com>
parents:
29
diff
changeset
|
179 serializeArray(value, key, id); |
0 | 180 |
181 else static if (isAssociativeArray!(T)) | |
30
9d1a8023bb89
Added IDs to every serialized value.
Jacob Carlborg <doob@me.com>
parents:
29
diff
changeset
|
182 serializeAssociativeArray(value, key, id); |
0 | 183 |
184 else static if (isPrimitive!(T)) | |
30
9d1a8023bb89
Added IDs to every serialized value.
Jacob Carlborg <doob@me.com>
parents:
29
diff
changeset
|
185 serializePrimitive(value, key, id); |
0 | 186 |
187 else static if (isPointer!(T)) | |
188 { | |
189 static if (isFunctionPointer!(T)) | |
2 | 190 goto error; |
0 | 191 |
192 else | |
30
9d1a8023bb89
Added IDs to every serialized value.
Jacob Carlborg <doob@me.com>
parents:
29
diff
changeset
|
193 serializePointer(value, key, id); |
33
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
194 } |
0 | 195 |
196 else static if (isEnum!(T)) | |
30
9d1a8023bb89
Added IDs to every serialized value.
Jacob Carlborg <doob@me.com>
parents:
29
diff
changeset
|
197 serializeEnum(value, key, id); |
0 | 198 |
199 else | |
2 | 200 { |
201 error: | |
202 throw new SerializationException(format!(`The type "`, T, `" cannot be serialized.`), __FILE__, __LINE__); | |
203 } | |
0 | 204 } |
25
b51e953f79eb
Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
205 |
30
9d1a8023bb89
Added IDs to every serialized value.
Jacob Carlborg <doob@me.com>
parents:
29
diff
changeset
|
206 private void serializeObject (T) (T value, string key, Id id) |
25
b51e953f79eb
Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
207 { |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
208 if (!value) |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
209 return archive.archiveNull(T.stringof, key); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
210 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
211 auto reference = getSerializedReference(value); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
212 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
213 if (reference != Id.max) |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
214 return archive.archiveReference(key, reference); |
25
b51e953f79eb
Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
215 |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
216 auto runtimeType = value.classinfo.name; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
217 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
218 addSerializedReference(value, id); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
219 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
220 triggerEvents(serializing, value, { |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
221 archive.archiveObject(runtimeType, T.stringof, key, id, { |
0 | 222 if (runtimeType in serializers) |
223 { | |
224 auto wrapper = getSerializerWrapper!(T)(runtimeType); | |
225 wrapper(value, this, key); | |
226 } | |
227 | |
39 | 228 else static if (isSerializable!(T)) |
0 | 229 value.toData(this, key); |
230 | |
231 else | |
232 { | |
233 if (isBaseClass(value)) | |
234 throw new SerializationException(`The object of the static type "` ~ T.stringof ~ `" have a different runtime type (` ~ runtimeType ~ `) and therefore needs to register a serializer for its type "` ~ runtimeType ~ `".`, __FILE__, __LINE__); | |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
235 |
2 | 236 objectStructSerializeHelper(value); |
0 | 237 } |
238 }); | |
239 }); | |
240 } | |
25
b51e953f79eb
Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
241 |
30
9d1a8023bb89
Added IDs to every serialized value.
Jacob Carlborg <doob@me.com>
parents:
29
diff
changeset
|
242 private void serializeStruct (T) (T value, string key, Id id) |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
243 { |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
244 string type = T.stringof; |
25
b51e953f79eb
Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
245 |
0 | 246 triggerEvents(serializing, value, { |
30
9d1a8023bb89
Added IDs to every serialized value.
Jacob Carlborg <doob@me.com>
parents:
29
diff
changeset
|
247 archive.archiveStruct(type, key, id, { |
0 | 248 if (type in serializers) |
249 { | |
250 auto wrapper = getSerializerWrapper!(T)(type); | |
251 wrapper(value, this, key); | |
252 } | |
253 | |
254 else | |
255 { | |
40
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
39
diff
changeset
|
256 static if (isSerializable!(T)) |
0 | 257 value.toData(this, key); |
258 | |
259 else | |
2 | 260 objectStructSerializeHelper(value); |
0 | 261 } |
262 }); | |
263 }); | |
264 } | |
265 | |
30
9d1a8023bb89
Added IDs to every serialized value.
Jacob Carlborg <doob@me.com>
parents:
29
diff
changeset
|
266 private void serializeString (T) (T value, string key, Id id) |
0 | 267 { |
35
511d1ef4e299
Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents:
34
diff
changeset
|
268 auto array = Array(cast(void*) value.ptr, value.length, ElementTypeOfArray!(T).sizeof); |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
269 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
270 archive.archive(value, key, id); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
271 addSerializedArray(array, id); |
0 | 272 } |
25
b51e953f79eb
Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
273 |
30
9d1a8023bb89
Added IDs to every serialized value.
Jacob Carlborg <doob@me.com>
parents:
29
diff
changeset
|
274 private void serializeArray (T) (T value, string key, Id id) |
20
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
275 { |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
276 auto array = Array(value.ptr, value.length, ElementTypeOfArray!(T).sizeof); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
277 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
278 archive.archiveArray(array, arrayToString!(T), key, id, { |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
279 foreach (i, e ; value) |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
280 serializeInternal(e, toData(i)); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
281 }); |
35
511d1ef4e299
Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents:
34
diff
changeset
|
282 |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
283 addSerializedArray(array, id); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
284 } |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
285 |
30
9d1a8023bb89
Added IDs to every serialized value.
Jacob Carlborg <doob@me.com>
parents:
29
diff
changeset
|
286 private void serializeAssociativeArray (T) (T value, string key, Id id) |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
287 { |
28
bffcbc8c392b
Associative arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
27
diff
changeset
|
288 auto reference = getSerializedReference(value); |
bffcbc8c392b
Associative arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
27
diff
changeset
|
289 |
bffcbc8c392b
Associative arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
27
diff
changeset
|
290 if (reference != Id.max) |
bffcbc8c392b
Associative arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
27
diff
changeset
|
291 return archive.archiveReference(key, reference); |
30
9d1a8023bb89
Added IDs to every serialized value.
Jacob Carlborg <doob@me.com>
parents:
29
diff
changeset
|
292 |
28
bffcbc8c392b
Associative arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
27
diff
changeset
|
293 addSerializedReference(value, id); |
bffcbc8c392b
Associative arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
27
diff
changeset
|
294 |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
295 string keyType = KeyTypeOfAssociativeArray!(T).stringof; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
296 string valueType = ValueTypeOfAssociativeArray!(T).stringof; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
297 |
28
bffcbc8c392b
Associative arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
27
diff
changeset
|
298 archive.archiveAssociativeArray(keyType, valueType, value.length, key, id, { |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
299 size_t i; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
300 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
301 foreach(k, v ; value) |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
302 { |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
303 archive.archiveAssociativeArrayKey(toData(i), { |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
304 serializeInternal(k, toData(i)); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
305 }); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
306 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
307 archive.archiveAssociativeArrayValue(toData(i), { |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
308 serializeInternal(v, toData(i)); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
309 }); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
310 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
311 i++; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
312 } |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
313 }); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
314 } |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
315 |
30
9d1a8023bb89
Added IDs to every serialized value.
Jacob Carlborg <doob@me.com>
parents:
29
diff
changeset
|
316 private void serializePointer (T) (T value, string key, Id id) |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
317 { |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
318 if (!value) |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
319 return archive.archiveNull(T.stringof, key); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
320 |
33
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
321 auto reference = getSerializedReference(value); |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
322 |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
323 if (reference != Id.max) |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
324 return archive.archiveReference(key, reference); |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
325 |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
326 addSerializedReference(value, id); |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
327 |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
328 archive.archivePointer(key, id, { |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
329 if (key in serializers) |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
330 { |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
331 auto wrapper = getSerializerWrapper!(T)(key); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
332 wrapper(value, this, key); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
333 } |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
334 |
39 | 335 else static if (isSerializable!(T)) |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
336 value.toData(this, key); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
337 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
338 else |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
339 { |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
340 static if (isVoid!(BaseTypeOfPointer!(T))) |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
341 throw new SerializationException(`The value with the key "` ~ to!(string)(key) ~ `"` ~ format!(` of the type "`, T, `" cannot be serialized on its own, either implement orange.serialization.Serializable.isSerializable or register a serializer.`), __FILE__, __LINE__); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
342 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
343 else |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
344 serializeInternal(*value, nextKey); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
345 } |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
346 }); |
29
c422ff6477dd
Better handling of serializing pointers.
Jacob Carlborg <doob@me.com>
parents:
28
diff
changeset
|
347 |
c422ff6477dd
Better handling of serializing pointers.
Jacob Carlborg <doob@me.com>
parents:
28
diff
changeset
|
348 addSerializedPointer(value, id); |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
349 } |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
350 |
30
9d1a8023bb89
Added IDs to every serialized value.
Jacob Carlborg <doob@me.com>
parents:
29
diff
changeset
|
351 private void serializeEnum (T) (T value, string key, Id id) |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
352 { |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
353 alias BaseTypeOfEnum!(T) EnumBaseType; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
354 auto val = cast(EnumBaseType) value; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
355 string type = T.stringof; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
356 |
30
9d1a8023bb89
Added IDs to every serialized value.
Jacob Carlborg <doob@me.com>
parents:
29
diff
changeset
|
357 archive.archiveEnum(val, type, key, id); |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
358 } |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
359 |
30
9d1a8023bb89
Added IDs to every serialized value.
Jacob Carlborg <doob@me.com>
parents:
29
diff
changeset
|
360 private void serializePrimitive (T) (T value, string key, Id id) |
33
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
361 { |
30
9d1a8023bb89
Added IDs to every serialized value.
Jacob Carlborg <doob@me.com>
parents:
29
diff
changeset
|
362 archive.archive(value, key, id); |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
363 } |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
364 |
30
9d1a8023bb89
Added IDs to every serialized value.
Jacob Carlborg <doob@me.com>
parents:
29
diff
changeset
|
365 private void serializeTypedef (T) (T value, string key, Id id) |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
366 { |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
367 archive.archiveTypedef(T.stringof, key, nextId, { |
32
9df3b7a46a51
Updated the unit test with the latest changes.
Jacob Carlborg <doob@me.com>
parents:
31
diff
changeset
|
368 serializeInternal!(BaseTypeOfTypedef!(T))(value, nextKey); |
0 | 369 }); |
370 } | |
371 | |
39 | 372 T deserialize (T) (Data data, string key = "") |
373 { | |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
374 if (hasBegunSerializing && !hasBegunDeserializing) |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
375 resetCounters(); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
376 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
377 if (!hasBegunDeserializing) |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
378 hasBegunDeserializing = true; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
379 |
39 | 380 if (key.empty()) |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
381 key = nextKey; |
33
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
382 |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
383 archive.beginUnarchiving(data); |
33
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
384 auto value = deserializeInternal!(T)(key); |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
385 deserializingPostProcess; |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
386 |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
387 return value; |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
388 } |
39 | 389 |
390 T deserialize (T) (string key) | |
391 { | |
392 if (!hasBegunDeserializing) | |
40
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
39
diff
changeset
|
393 throw new SerializationException("Cannot deserialize without any data, this method should only be called after deserialization has begun.", __FILE__, __LINE__); |
39 | 394 |
395 return deserialize!(T)(archive.untypedData, key); | |
396 } | |
397 | |
398 T deserialize (T) () | |
399 { | |
400 return deserialize!(T)(""); | |
401 } | |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
402 |
33
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
403 private T deserializeInternal (T, U) (U keyOrId) |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
404 { |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
405 static if (isTypedef!(T)) |
33
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
406 return deserializeTypedef!(T)(keyOrId); |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
407 |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
408 else static if (isObject!(T)) |
33
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
409 return deserializeObject!(T)(keyOrId); |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
410 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
411 else static if (isStruct!(T)) |
33
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
412 return deserializeStruct!(T)(keyOrId); |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
413 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
414 else static if (isString!(T)) |
33
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
415 return deserializeString!(T)(keyOrId); |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
416 |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
417 else static if (isArray!(T)) |
33
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
418 return deserializeArray!(T)(keyOrId); |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
419 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
420 else static if (isAssociativeArray!(T)) |
33
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
421 return deserializeAssociativeArray!(T)(keyOrId); |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
422 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
423 else static if (isPrimitive!(T)) |
33
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
424 return deserializePrimitive!(T)(keyOrId); |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
425 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
426 else static if (isPointer!(T)) |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
427 { |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
428 static if (isFunctionPointer!(T)) |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
429 goto error; |
33
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
430 Id id; |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
431 return deserializePointer!(T)(keyOrId, id); |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
432 } |
33
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
433 |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
434 else static if (isEnum!(T)) |
33
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
435 return deserializeEnum!(T)(keyOrId); |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
436 |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
437 else |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
438 { |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
439 error: |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
440 throw new SerializationException(format!(`The type "`, T, `" cannot be deserialized.`), __FILE__, __LINE__); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
441 } |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
442 } |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
443 |
33
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
444 private T deserializeObject (T, U) (U keyOrId) |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
445 { |
33
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
446 auto id = deserializeReference(keyOrId); |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
447 |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
448 if (auto reference = getDeserializedReference!(T)(id)) |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
449 return *reference; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
450 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
451 T value; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
452 Object val = value; |
33
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
453 nextId; |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
454 |
33
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
455 archive.unarchiveObject(keyOrId, id, val, { |
42
8b9409423740
Added unit tests for (de)serializing events.
Jacob Carlborg <doob@me.com>
parents:
40
diff
changeset
|
456 triggerEvents(deserializing, cast(T) val, { |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
457 value = cast(T) val; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
458 auto runtimeType = value.classinfo.name; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
459 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
460 if (runtimeType in deserializers) |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
461 { |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
462 auto wrapper = getDeserializerWrapper!(T)(runtimeType); |
33
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
463 wrapper(value, this, keyOrId); |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
464 } |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
465 |
39 | 466 else static if (isSerializable!(T)) |
33
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
467 value.fromData(this, keyOrId); |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
468 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
469 else |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
470 { |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
471 if (isBaseClass(value)) |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
472 throw new SerializationException(`The object of the static type "` ~ T.stringof ~ `" have a different runtime type (` ~ runtimeType ~ `) and therefore needs to register a deserializer for its type "` ~ runtimeType ~ `".`, __FILE__, __LINE__); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
473 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
474 objectStructDeserializeHelper(value); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
475 } |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
476 }); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
477 }); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
478 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
479 addDeserializedReference(value, id); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
480 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
481 return value; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
482 } |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
483 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
484 private T deserializeStruct (T) (string key) |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
485 { |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
486 T value; |
33
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
487 nextId; |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
488 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
489 archive.unarchiveStruct(key, { |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
490 triggerEvents(deserializing, value, { |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
491 auto type = toData(T.stringof); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
492 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
493 if (type in deserializers) |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
494 { |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
495 auto wrapper = getDeserializerWrapper!(T)(type); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
496 wrapper(value, this, key); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
497 } |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
498 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
499 else |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
500 { |
40
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
39
diff
changeset
|
501 static if (isSerializable!(T)) |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
502 value.fromData(this, key); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
503 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
504 else |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
505 objectStructDeserializeHelper(value); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
506 } |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
507 }); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
508 }); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
509 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
510 return value; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
511 } |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
512 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
513 private T deserializeString (T) (string key) |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
514 { |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
515 auto slice = deserializeSlice(key); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
516 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
517 if (auto tmp = getDeserializedSlice!(T)(slice)) |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
518 return *tmp; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
519 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
520 T value; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
521 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
522 if (slice.id != size_t.max) |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
523 { |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
524 static if (is(T == string)) |
35
511d1ef4e299
Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents:
34
diff
changeset
|
525 value = toSlice(archive.unarchiveString(slice.id), slice); |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
526 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
527 else static if (is(T == wstring)) |
35
511d1ef4e299
Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents:
34
diff
changeset
|
528 value = toSlice(archive.unarchiveWstring(slice.id), slice); |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
529 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
530 else static if (is(T == dstring)) |
35
511d1ef4e299
Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents:
34
diff
changeset
|
531 value = toSlice(archive.unarchiveDstring(slice.id), slice); |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
532 } |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
533 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
534 else |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
535 { |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
536 static if (is(T == string)) |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
537 value = archive.unarchiveString(key, slice.id); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
538 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
539 else static if (is(T == wstring)) |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
540 value = archive.unarchiveWstring(key, slice.id); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
541 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
542 else static if (is(T == dstring)) |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
543 value = archive.unarchiveDstring(key, slice.id); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
544 } |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
545 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
546 addDeserializedSlice(value, slice.id); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
547 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
548 return value; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
549 } |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
550 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
551 private T deserializeArray (T) (string key) |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
552 { |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
553 auto slice = deserializeSlice(key); |
46
d6fbd0b3586e
Issue 8: Wrong results for array of arrays. (Temporary fix).
Jacob Carlborg <doob@me.com>
parents:
42
diff
changeset
|
554 |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
555 if (auto tmp = getDeserializedSlice!(T)(slice)) |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
556 return *tmp; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
557 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
558 T value; |
35
511d1ef4e299
Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents:
34
diff
changeset
|
559 |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
560 auto dg = (size_t length) { |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
561 value.length = length; |
35
511d1ef4e299
Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents:
34
diff
changeset
|
562 |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
563 foreach (i, ref e ; value) |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
564 e = deserializeInternal!(typeof(e))(toData(i)); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
565 }; |
46
d6fbd0b3586e
Issue 8: Wrong results for array of arrays. (Temporary fix).
Jacob Carlborg <doob@me.com>
parents:
42
diff
changeset
|
566 |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
567 if (slice.id != size_t.max) |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
568 { |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
569 archive.unarchiveArray(slice.id, dg); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
570 addDeserializedSlice(value, slice.id); |
35
511d1ef4e299
Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents:
34
diff
changeset
|
571 |
511d1ef4e299
Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents:
34
diff
changeset
|
572 return toSlice(value, slice); |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
573 } |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
574 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
575 else |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
576 { |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
577 slice.id = archive.unarchiveArray(key, dg); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
578 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
579 if (auto a = slice.id in deserializedSlices) |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
580 return cast(T) *a; |
46
d6fbd0b3586e
Issue 8: Wrong results for array of arrays. (Temporary fix).
Jacob Carlborg <doob@me.com>
parents:
42
diff
changeset
|
581 |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
582 addDeserializedSlice(value, slice.id); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
583 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
584 return value; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
585 } |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
586 } |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
587 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
588 private T deserializeAssociativeArray (T) (string key) |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
589 { |
28
bffcbc8c392b
Associative arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
27
diff
changeset
|
590 auto id = deserializeReference(key); |
bffcbc8c392b
Associative arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
27
diff
changeset
|
591 |
bffcbc8c392b
Associative arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
27
diff
changeset
|
592 if (auto reference = getDeserializedReference!(T)(id)) |
bffcbc8c392b
Associative arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
27
diff
changeset
|
593 return *reference; |
bffcbc8c392b
Associative arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
27
diff
changeset
|
594 |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
595 T value; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
596 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
597 alias KeyTypeOfAssociativeArray!(T) Key; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
598 alias ValueTypeOfAssociativeArray!(T) Value; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
599 |
28
bffcbc8c392b
Associative arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
27
diff
changeset
|
600 id = archive.unarchiveAssociativeArray(key, (size_t length) { |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
601 for (size_t i = 0; i < length; i++) |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
602 { |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
603 Key aaKey; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
604 Value aaValue; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
605 auto k = toData(i); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
606 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
607 archive.unarchiveAssociativeArrayKey(k, { |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
608 aaKey = deserializeInternal!(Key)(k); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
609 }); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
610 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
611 archive.unarchiveAssociativeArrayValue(k, { |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
612 aaValue = deserializeInternal!(Value)(k); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
613 }); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
614 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
615 value[aaKey] = aaValue; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
616 } |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
617 }); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
618 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
619 addDeserializedReference(value, id); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
620 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
621 return value; |
28
bffcbc8c392b
Associative arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
27
diff
changeset
|
622 } |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
623 |
33
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
624 private T deserializePointer (T) (string key, out Id id) |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
625 { |
33
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
626 id = deserializeReference(key); |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
627 |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
628 if (auto reference = getDeserializedReference!(T)(id)) |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
629 return *reference; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
630 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
631 T value = new BaseTypeOfPointer!(T); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
632 |
33
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
633 auto pointerId = archive.unarchivePointer(key, { |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
634 if (key in deserializers) |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
635 { |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
636 auto wrapper = getDeserializerWrapper!(T)(key); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
637 wrapper(value, this, key); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
638 } |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
639 |
40
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
39
diff
changeset
|
640 else static if (isSerializable!(T)) |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
641 value.fromData(this, key); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
642 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
643 else |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
644 { |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
645 static if (isVoid!(BaseTypeOfPointer!(T))) |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
646 throw new SerializationException(`The value with the key "` ~ to!(string)(key) ~ `"` ~ format!(` of the type "`, T, `" cannot be deserialized on its own, either implement orange.serialization.Serializable.isSerializable or register a deserializer.`), __FILE__, __LINE__); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
647 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
648 else |
33
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
649 { |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
650 auto k = nextKey; |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
651 id = deserializeReference(k); |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
652 |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
653 if (id != Id.max) |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
654 return; |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
655 |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
656 *value = deserializeInternal!(BaseTypeOfPointer!(T))(k); |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
657 } |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
658 } |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
659 }); |
33
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
660 |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
661 addDeserializedReference(value, pointerId); |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
662 |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
663 return value; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
664 } |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
665 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
666 private T deserializeEnum (T) (string key) |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
667 { |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
668 alias BaseTypeOfEnum!(T) Enum; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
669 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
670 const functionName = toUpper(Enum.stringof[0]) ~ Enum.stringof[1 .. $]; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
671 mixin("return cast(T) archive.unarchiveEnum" ~ functionName ~ "(key);"); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
672 } |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
673 |
33
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
674 private T deserializePrimitive (T, U) (U keyOrId) |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
675 { |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
676 const functionName = toUpper(T.stringof[0]) ~ T.stringof[1 .. $]; |
33
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
677 mixin("return archive.unarchive" ~ functionName ~ "(keyOrId);"); |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
678 } |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
679 |
33
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
680 private T deserializeTypedef (T, U) (U keyOrId) |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
681 { |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
682 T value; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
683 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
684 archive.unarchiveTypedef!(T)(key, { |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
685 value = cast(T) deserializeInternal!(BaseTypeOfTypedef!(T))(nextKey); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
686 }); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
687 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
688 return value; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
689 } |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
690 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
691 private Id deserializeReference (string key) |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
692 { |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
693 return archive.unarchiveReference(key); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
694 } |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
695 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
696 private Slice deserializeSlice (string key) |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
697 { |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
698 return archive.unarchiveSlice(key); |
0 | 699 } |
700 | |
3 | 701 private void objectStructSerializeHelper (T) (ref T value) |
702 { | |
703 static assert(isStruct!(T) || isObject!(T), format!(`The given value of the type "`, T, `" is not a valid type, the only valid types for this method are objects and structs.`)); | |
35
511d1ef4e299
Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents:
34
diff
changeset
|
704 |
511d1ef4e299
Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents:
34
diff
changeset
|
705 version (Tango) |
511d1ef4e299
Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents:
34
diff
changeset
|
706 const nonSerializedFields = collectAnnotations!(nonSerializedField, T); |
511d1ef4e299
Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents:
34
diff
changeset
|
707 |
511d1ef4e299
Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents:
34
diff
changeset
|
708 else |
511d1ef4e299
Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents:
34
diff
changeset
|
709 mixin(`enum nonSerializedFields = collectAnnotations!(nonSerializedField, T);`); |
3 | 710 |
711 foreach (i, dummy ; typeof(T.tupleof)) | |
712 { | |
35
511d1ef4e299
Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents:
34
diff
changeset
|
713 version (Tango) |
511d1ef4e299
Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents:
34
diff
changeset
|
714 const field = nameOfFieldAt!(T, i); |
511d1ef4e299
Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents:
34
diff
changeset
|
715 |
511d1ef4e299
Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents:
34
diff
changeset
|
716 else |
511d1ef4e299
Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents:
34
diff
changeset
|
717 mixin(`enum field = nameOfFieldAt!(T, i);`); |
3 | 718 |
35
511d1ef4e299
Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents:
34
diff
changeset
|
719 static if (!ctfeContains!(string)(internalFields, field) && !ctfeContains!(string)(nonSerializedFields, field)) |
3 | 720 { |
721 alias typeof(T.tupleof[i]) Type; | |
30
9d1a8023bb89
Added IDs to every serialized value.
Jacob Carlborg <doob@me.com>
parents:
29
diff
changeset
|
722 Type v = value.tupleof[i]; |
9d1a8023bb89
Added IDs to every serialized value.
Jacob Carlborg <doob@me.com>
parents:
29
diff
changeset
|
723 auto id = nextId; |
33
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
724 |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
725 addSerializedValue(value.tupleof[i], id, toData(keyCounter)); |
30
9d1a8023bb89
Added IDs to every serialized value.
Jacob Carlborg <doob@me.com>
parents:
29
diff
changeset
|
726 serializeInternal(v, toData(field), id); |
9d1a8023bb89
Added IDs to every serialized value.
Jacob Carlborg <doob@me.com>
parents:
29
diff
changeset
|
727 } |
3 | 728 } |
2 | 729 |
4
470ab5270d0c
Simplified the implementation of RegisterWrapper. Fixed: the base class of an object was not serialized
Jacob Carlborg <doob@me.com>
parents:
3
diff
changeset
|
730 static if (isObject!(T) && !is(T == Object)) |
470ab5270d0c
Simplified the implementation of RegisterWrapper. Fixed: the base class of an object was not serialized
Jacob Carlborg <doob@me.com>
parents:
3
diff
changeset
|
731 serializeBaseTypes(value); |
3 | 732 } |
733 | |
734 private void objectStructDeserializeHelper (T) (ref T value) | |
735 { | |
736 static assert(isStruct!(T) || isObject!(T), format!(`The given value of the type "`, T, `" is not a valid type, the only valid types for this method are objects and structs.`)); | |
35
511d1ef4e299
Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents:
34
diff
changeset
|
737 |
511d1ef4e299
Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents:
34
diff
changeset
|
738 version (Tango) |
511d1ef4e299
Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents:
34
diff
changeset
|
739 const nonSerializedFields = collectAnnotations!(nonSerializedField, T); |
511d1ef4e299
Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents:
34
diff
changeset
|
740 |
511d1ef4e299
Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents:
34
diff
changeset
|
741 else |
511d1ef4e299
Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents:
34
diff
changeset
|
742 mixin(`enum nonSerializedFields = collectAnnotations!(nonSerializedField, T);`); |
3 | 743 |
744 foreach (i, dummy ; typeof(T.tupleof)) | |
745 { | |
35
511d1ef4e299
Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents:
34
diff
changeset
|
746 version (Tango) |
511d1ef4e299
Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents:
34
diff
changeset
|
747 const field = nameOfFieldAt!(T, i); |
511d1ef4e299
Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents:
34
diff
changeset
|
748 |
511d1ef4e299
Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents:
34
diff
changeset
|
749 else |
511d1ef4e299
Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents:
34
diff
changeset
|
750 mixin(`enum field = nameOfFieldAt!(T, i);`); |
3 | 751 |
35
511d1ef4e299
Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents:
34
diff
changeset
|
752 static if (!ctfeContains!(string)(internalFields, field) && !ctfeContains!(string)(nonSerializedFields, field)) |
3 | 753 { |
754 alias TypeOfField!(T, field) Type; | |
33
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
755 |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
756 static if (isPointer!(Type)) |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
757 { |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
758 Id id; |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
759 value.tupleof[i] = deserializePointer!(Type)(toData(field), id); |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
760 addDeserializedPointer(value.tupleof[i], id); |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
761 } |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
762 |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
763 else |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
764 { |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
765 auto fieldValue = deserializeInternal!(Type)(toData(field)); |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
766 value.tupleof[i] = fieldValue; |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
767 } |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
768 |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
769 addDeserializedValue(value.tupleof[i], nextId); |
3 | 770 } |
771 } | |
33
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
772 |
4
470ab5270d0c
Simplified the implementation of RegisterWrapper. Fixed: the base class of an object was not serialized
Jacob Carlborg <doob@me.com>
parents:
3
diff
changeset
|
773 static if (isObject!(T) && !is(T == Object)) |
470ab5270d0c
Simplified the implementation of RegisterWrapper. Fixed: the base class of an object was not serialized
Jacob Carlborg <doob@me.com>
parents:
3
diff
changeset
|
774 deserializeBaseTypes(value); |
0 | 775 } |
776 | |
2 | 777 private void serializeBaseTypes (T : Object) (T value) |
0 | 778 { |
779 alias BaseTypeTupleOf!(T)[0] Base; | |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
780 |
0 | 781 static if (!is(Base == Object)) |
782 { | |
25
b51e953f79eb
Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
783 archive.archiveBaseClass(Base.stringof, nextKey, nextId); |
4
470ab5270d0c
Simplified the implementation of RegisterWrapper. Fixed: the base class of an object was not serialized
Jacob Carlborg <doob@me.com>
parents:
3
diff
changeset
|
784 Base base = value; |
470ab5270d0c
Simplified the implementation of RegisterWrapper. Fixed: the base class of an object was not serialized
Jacob Carlborg <doob@me.com>
parents:
3
diff
changeset
|
785 objectStructSerializeHelper(base); |
0 | 786 } |
787 } | |
788 | |
2 | 789 private void deserializeBaseTypes (T : Object) (T value) |
0 | 790 { |
791 alias BaseTypeTupleOf!(T)[0] Base; | |
792 | |
793 static if (!is(Base == Object)) | |
794 { | |
795 archive.unarchiveBaseClass!(Base)(nextKey); | |
4
470ab5270d0c
Simplified the implementation of RegisterWrapper. Fixed: the base class of an object was not serialized
Jacob Carlborg <doob@me.com>
parents:
3
diff
changeset
|
796 Base base = value; |
470ab5270d0c
Simplified the implementation of RegisterWrapper. Fixed: the base class of an object was not serialized
Jacob Carlborg <doob@me.com>
parents:
3
diff
changeset
|
797 objectStructDeserializeHelper(base); |
0 | 798 } |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
799 } |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
800 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
801 private void addSerializedReference (T) (T value, Id id) |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
802 { |
28
bffcbc8c392b
Associative arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
27
diff
changeset
|
803 static assert(isReference!(T) || isAssociativeArray!(T), format!(`The given type "`, T, `" is not a reference type, i.e. object, pointer or associative array.`)); |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
804 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
805 serializedReferences[cast(void*) value] = id; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
806 } |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
807 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
808 private void addDeserializedReference (T) (T value, Id id) |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
809 { |
28
bffcbc8c392b
Associative arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
27
diff
changeset
|
810 static assert(isReference!(T) || isAssociativeArray!(T), format!(`The given type "`, T, `" is not a reference type, i.e. object, pointer or associative array.`)); |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
811 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
812 deserializedReferences[id] = cast(void*) value; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
813 } |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
814 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
815 private void addDeserializedSlice (T) (T value, Id id) |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
816 { |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
817 static assert(isArray!(T) || isString!(T), format!(`The given type "`, T, `" is not a slice type, i.e. array or string.`)); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
818 |
35
511d1ef4e299
Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents:
34
diff
changeset
|
819 deserializedSlices[id] = cast(void[]) value; |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
820 } |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
821 |
33
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
822 private void addSerializedValue (T) (ref T value, Id id, string key) |
29
c422ff6477dd
Better handling of serializing pointers.
Jacob Carlborg <doob@me.com>
parents:
28
diff
changeset
|
823 { |
33
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
824 serializedValues[&value] = ValueMeta(id, key); |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
825 } |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
826 |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
827 private void addDeserializedValue (T) (ref T value, Id id) |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
828 { |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
829 deserializedValues[id] = &value; |
29
c422ff6477dd
Better handling of serializing pointers.
Jacob Carlborg <doob@me.com>
parents:
28
diff
changeset
|
830 } |
c422ff6477dd
Better handling of serializing pointers.
Jacob Carlborg <doob@me.com>
parents:
28
diff
changeset
|
831 |
c422ff6477dd
Better handling of serializing pointers.
Jacob Carlborg <doob@me.com>
parents:
28
diff
changeset
|
832 private void addSerializedPointer (T) (T value, Id id) |
c422ff6477dd
Better handling of serializing pointers.
Jacob Carlborg <doob@me.com>
parents:
28
diff
changeset
|
833 { |
31
c68d29967c9f
Fixed some bugs in the handling of pointers.
Jacob Carlborg <doob@me.com>
parents:
30
diff
changeset
|
834 serializedPointers[id] = value; |
29
c422ff6477dd
Better handling of serializing pointers.
Jacob Carlborg <doob@me.com>
parents:
28
diff
changeset
|
835 } |
c422ff6477dd
Better handling of serializing pointers.
Jacob Carlborg <doob@me.com>
parents:
28
diff
changeset
|
836 |
33
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
837 private void addDeserializedPointer (T) (ref T value, Id id) |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
838 { |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
839 deserializedPointers[id] = cast(void**) &value; |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
840 } |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
841 |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
842 private Id getSerializedReference (T) (T value) |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
843 { |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
844 if (auto tmp = cast(void*) value in serializedReferences) |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
845 return *tmp; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
846 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
847 return Id.max; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
848 } |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
849 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
850 private T* getDeserializedReference (T) (Id id) |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
851 { |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
852 if (auto reference = id in deserializedReferences) |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
853 return cast(T*) reference; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
854 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
855 return null; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
856 } |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
857 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
858 private T* getDeserializedSlice (T) (Slice slice) |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
859 { |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
860 if (auto array = slice.id in deserializedSlices) |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
861 return &(cast(T) *array)[slice.offset .. slice.offset + slice.length]; // dereference the array, cast it to the right type, |
28
bffcbc8c392b
Associative arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
27
diff
changeset
|
862 // slice it and then return a pointer to the result |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
863 return null; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
864 } |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
865 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
866 private T* getDeserializedArray (T) (Id id) |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
867 { |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
868 if (auto array = id in deserializedSlices) |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
869 return cast(T*) array; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
870 } |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
871 |
33
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
872 private T* getDeserializedValue (T) (Id id) |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
873 { |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
874 if (auto value = id in deserializedValues) |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
875 return cast(T*) value; |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
876 |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
877 return null; |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
878 } |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
879 |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
880 private T[] toSlice (T) (T[] array, Slice slice) |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
881 { |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
882 return array[slice.offset .. slice.offset + slice.length]; |
0 | 883 } |
884 | |
15
9f6064f9505a
Changed from archive to serializer in the register wrappers.
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
885 private SerializeRegisterWrapper!(T, Serializer) getSerializerWrapper (T) (string type) |
0 | 886 { |
15
9f6064f9505a
Changed from archive to serializer in the register wrappers.
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
887 auto wrapper = cast(SerializeRegisterWrapper!(T, Serializer)) serializers[type]; |
0 | 888 |
889 if (wrapper) | |
890 return wrapper; | |
891 | |
892 assert(false, "throw exception here"); | |
893 } | |
894 | |
15
9f6064f9505a
Changed from archive to serializer in the register wrappers.
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
895 private DeserializeRegisterWrapper!(T, Serializer) getDeserializerWrapper (T) (string type) |
0 | 896 { |
15
9f6064f9505a
Changed from archive to serializer in the register wrappers.
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
897 auto wrapper = cast(DeserializeRegisterWrapper!(T, Serializer)) deserializers[type]; |
0 | 898 |
899 if (wrapper) | |
900 return wrapper; | |
901 | |
902 assert(false, "throw exception here"); | |
903 } | |
904 | |
25
b51e953f79eb
Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
905 private SerializeRegisterWrapper!(T, Serializer) toSerializeRegisterWrapper (T) (void delegate (T, Serializer, string) dg) |
0 | 906 { |
16
091ff1b263db
Missed some in the previous commit.
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
907 return new SerializeRegisterWrapper!(T, Serializer)(dg); |
0 | 908 } |
909 | |
25
b51e953f79eb
Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
910 private SerializeRegisterWrapper!(T, Serializer) toSerializeRegisterWrapper (T) (void function (T, Serializer, string) func) |
0 | 911 { |
16
091ff1b263db
Missed some in the previous commit.
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
912 return new SerializeRegisterWrapper!(T, Serializer)(func); |
0 | 913 } |
914 | |
25
b51e953f79eb
Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
915 private DeserializeRegisterWrapper!(T, Serializer) toDeserializeRegisterWrapper (T) (void delegate (ref T, Serializer, string) dg) |
0 | 916 { |
16
091ff1b263db
Missed some in the previous commit.
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
917 return new DeserializeRegisterWrapper!(T, Serializer)(dg); |
0 | 918 } |
919 | |
25
b51e953f79eb
Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
920 private DeserializeRegisterWrapper!(T, Serializer) toDeserializeRegisterWrapper (T) (void function (ref T, Serializer, string) func) |
0 | 921 { |
16
091ff1b263db
Missed some in the previous commit.
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
922 return new DeserializeRegisterWrapper!(T, Serializer)(func); |
0 | 923 } |
924 | |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
925 private void addSerializedArray (Array array, Id id) |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
926 { |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
927 serializedArrays[id] = array; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
928 } |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
929 |
29
c422ff6477dd
Better handling of serializing pointers.
Jacob Carlborg <doob@me.com>
parents:
28
diff
changeset
|
930 private void postProcess () |
c422ff6477dd
Better handling of serializing pointers.
Jacob Carlborg <doob@me.com>
parents:
28
diff
changeset
|
931 { |
c422ff6477dd
Better handling of serializing pointers.
Jacob Carlborg <doob@me.com>
parents:
28
diff
changeset
|
932 postProcessArrays(); |
c422ff6477dd
Better handling of serializing pointers.
Jacob Carlborg <doob@me.com>
parents:
28
diff
changeset
|
933 postProcessPointers(); |
c422ff6477dd
Better handling of serializing pointers.
Jacob Carlborg <doob@me.com>
parents:
28
diff
changeset
|
934 } |
c422ff6477dd
Better handling of serializing pointers.
Jacob Carlborg <doob@me.com>
parents:
28
diff
changeset
|
935 |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
936 private void postProcessArrays () |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
937 { |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
938 bool foundSlice = true; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
939 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
940 foreach (sliceKey, slice ; serializedArrays) |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
941 { |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
942 foreach (arrayKey, array ; serializedArrays) |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
943 { |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
944 if (slice.isSliceOf(array) && slice != array) |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
945 { |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
946 auto s = Slice(slice.length, (slice.ptr - array.ptr) / slice.elementSize); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
947 archive.archiveSlice(s, sliceKey, arrayKey); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
948 foundSlice = true; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
949 break; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
950 } |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
951 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
952 else |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
953 foundSlice = false; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
954 } |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
955 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
956 if (!foundSlice) |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
957 archive.postProcessArray(sliceKey); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
958 } |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
959 } |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
960 |
29
c422ff6477dd
Better handling of serializing pointers.
Jacob Carlborg <doob@me.com>
parents:
28
diff
changeset
|
961 private void postProcessPointers () |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
962 { |
31
c68d29967c9f
Fixed some bugs in the handling of pointers.
Jacob Carlborg <doob@me.com>
parents:
30
diff
changeset
|
963 foreach (pointerId, value ; serializedPointers) |
29
c422ff6477dd
Better handling of serializing pointers.
Jacob Carlborg <doob@me.com>
parents:
28
diff
changeset
|
964 { |
33
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
965 if (auto valueMeta = value in serializedValues) |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
966 archive.archivePointer(valueMeta.id, valueMeta.key, pointerId); |
29
c422ff6477dd
Better handling of serializing pointers.
Jacob Carlborg <doob@me.com>
parents:
28
diff
changeset
|
967 |
c422ff6477dd
Better handling of serializing pointers.
Jacob Carlborg <doob@me.com>
parents:
28
diff
changeset
|
968 else |
c422ff6477dd
Better handling of serializing pointers.
Jacob Carlborg <doob@me.com>
parents:
28
diff
changeset
|
969 archive.postProcessPointer(pointerId); |
c422ff6477dd
Better handling of serializing pointers.
Jacob Carlborg <doob@me.com>
parents:
28
diff
changeset
|
970 } |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
971 } |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
972 |
33
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
973 private void deserializingPostProcess () |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
974 { |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
975 deserializingPostProcessPointers; |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
976 } |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
977 |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
978 private void deserializingPostProcessPointers () |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
979 { |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
980 foreach (pointeeId, pointee ; deserializedValues) |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
981 { |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
982 if (auto pointer = pointeeId in deserializedPointers) |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
983 **pointer = pointee; |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
984 } |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
985 } |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
986 |
25
b51e953f79eb
Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
987 private template arrayToString (T) |
0 | 988 { |
35
511d1ef4e299
Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents:
34
diff
changeset
|
989 version (Tango) |
511d1ef4e299
Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents:
34
diff
changeset
|
990 const arrayToString = ElementTypeOfArray!(T).stringof; |
511d1ef4e299
Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents:
34
diff
changeset
|
991 |
511d1ef4e299
Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents:
34
diff
changeset
|
992 else |
511d1ef4e299
Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents:
34
diff
changeset
|
993 mixin(`enum arrayToString = ElementTypeOfArray!(T).stringof;`); |
0 | 994 } |
995 | |
996 private bool isBaseClass (T) (T value) | |
997 { | |
998 auto name = value.classinfo.name; | |
999 auto index = name.lastIndexOf('.'); | |
1000 | |
1001 return T.stringof != name[index + 1 .. $]; | |
1002 } | |
1003 | |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
1004 private Id nextId () |
25
b51e953f79eb
Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
1005 { |
b51e953f79eb
Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
1006 return idCounter++; |
b51e953f79eb
Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
1007 } |
b51e953f79eb
Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
1008 |
b51e953f79eb
Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
1009 private string nextKey () |
0 | 1010 { |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
1011 return toData(keyCounter++); |
0 | 1012 } |
1013 | |
33
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
1014 private string prevKey () |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
1015 { |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
1016 return toData(--keyCounter); |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
1017 } |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
32
diff
changeset
|
1018 |
0 | 1019 private void resetCounters () |
1020 { | |
1021 keyCounter = 0; | |
25
b51e953f79eb
Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
1022 idCounter = 0; |
b51e953f79eb
Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
1023 } |
b51e953f79eb
Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
1024 |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
1025 private string toData (T) (T value) |
25
b51e953f79eb
Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
1026 { |
b51e953f79eb
Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
1027 return to!(string)(value); |
0 | 1028 } |
1029 | |
1030 private void triggerEvent (string name, T) (T value) | |
1031 { | |
3 | 1032 static assert (isObject!(T) || isStruct!(T), format!(`The given value of the type "`, T, `" is not a valid type, the only valid types for this method are objects and structs.`)); |
0 | 1033 |
1034 foreach (i, dummy ; typeof(T.tupleof)) | |
1035 { | |
1036 const field = nameOfFieldAt!(T, i); | |
1037 | |
1038 static if (field == name) | |
1039 { | |
1040 alias TypeOfField!(T, field) Type; | |
1041 auto event = getValueOfField!(T, Type, field)(value); | |
1042 event(value); | |
1043 } | |
1044 } | |
1045 } | |
1046 | |
1047 private void triggerEvents (T) (Mode mode, T value, void delegate () dg) | |
1048 { | |
1049 if (mode == serializing) | |
1050 triggerEvent!(onSerializingField)(value); | |
1051 | |
1052 else | |
1053 triggerEvent!(onDeserializingField)(value); | |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
1054 |
0 | 1055 dg(); |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
1056 |
0 | 1057 if (mode == serializing) |
1058 triggerEvent!(onSerializedField)(value); | |
1059 | |
1060 else | |
1061 triggerEvent!(onDeserializedField)(value); | |
1062 } | |
1063 | |
8 | 1064 private static string[] collectAnnotations (string name, T) () |
0 | 1065 { |
3 | 1066 static assert (isObject!(T) || isStruct!(T), format!(`The given value of the type "`, T, `" is not a valid type, the only valid types for this method are objects and structs.`)); |
0 | 1067 |
1068 string[] annotations; | |
1069 | |
8 | 1070 foreach (i, type ; typeof(T.tupleof)) |
0 | 1071 { |
1072 const field = nameOfFieldAt!(T, i); | |
1073 | |
1074 static if (field == name) | |
8 | 1075 annotations ~= type.field; |
0 | 1076 } |
1077 | |
1078 return annotations; | |
1079 } | |
28
bffcbc8c392b
Associative arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
27
diff
changeset
|
1080 } |