annotate orange/serialization/Serializer.d @ 26:78e5fef4bbf2 experimental

Third step in refactoring the API. Stating to add unit tests.
author Jacob Carlborg <doob@me.com>
date Tue, 19 Oct 2010 10:22:10 +0200
parents b51e953f79eb
children fc315d786f24
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1 /**
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
2 * Copyright: Copyright (c) 2010 Jacob Carlborg.
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
3 * Authors: Jacob Carlborg
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
4 * Version: Initial created: Jan 26, 2010
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0)
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
6 */
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
7 module orange.serialization.Serializer;
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
8
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
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
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
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;
99c52d46822a Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents: 8
diff changeset
15 alias ConvError ConversionException;
0
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
16 }
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
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
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
19 import orange.serialization._;
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
20 import orange.serialization.archives._;
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
21 import orange.util._;
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
22
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
23 private
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
24 {
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
25 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
26
9a575087b961 Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 18
diff changeset
27 enum Mode
0
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
28 {
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
29 serializing,
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
30 deserializing
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
31 }
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
32
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
33 alias Mode.serializing serializing;
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
34 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
35
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
36 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
37 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
38 if (c >= 'a' && c <= 'z')
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
39 return c - 32;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
40
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
41 return c;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
42 }
0
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
43 }
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
44
25
b51e953f79eb Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents: 20
diff changeset
45 class Serializer
0
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
46 {
26
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
47 alias void delegate (ArchiveException exception, string[] data) ErrorCallback;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
48 alias UntypedData Data;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
49 alias size_t Id;
18
3d42ea434d46 Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents: 17
diff changeset
50
0
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
51 private
26
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
52 {
25
b51e953f79eb Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents: 20
diff changeset
53 ErrorCallback errorCallback_;
b51e953f79eb Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents: 20
diff changeset
54 IArchive archive;
b51e953f79eb Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents: 20
diff changeset
55
b51e953f79eb Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents: 20
diff changeset
56 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
57 Id idCounter;
0
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
58
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
59 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
60 RegisterBase[string] deserializers;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
61
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
62 Id[void*] serializedReferences;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
63 void*[Id] deserializedReferences;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
64
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
65 Array[Id] serializedArrays;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
66 void[][Id] deserializedSlices;
0
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
67
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
68 bool hasBegunSerializing;
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
69 bool hasBegunDeserializing;
18
3d42ea434d46 Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents: 17
diff changeset
70
26
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
71 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
72 void delegate (ArchiveException exception, string[] data) doNothingOnErrorCallback;
0
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
73 }
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
74
25
b51e953f79eb Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents: 20
diff changeset
75 this (IArchive archive)
0
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
76 {
25
b51e953f79eb Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents: 20
diff changeset
77 this.archive = archive;
18
3d42ea434d46 Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents: 17
diff changeset
78
26
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
79 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
80 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
81
3d42ea434d46 Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents: 17
diff changeset
82 setThrowOnErrorCallback();
0
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
83 }
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
84
18
3d42ea434d46 Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents: 17
diff changeset
85 ErrorCallback errorCallback ()
3d42ea434d46 Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents: 17
diff changeset
86 {
25
b51e953f79eb Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents: 20
diff changeset
87 return errorCallback_;
18
3d42ea434d46 Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents: 17
diff changeset
88 }
3d42ea434d46 Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents: 17
diff changeset
89
3d42ea434d46 Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents: 17
diff changeset
90 ErrorCallback errorCallback (ErrorCallback errorCallback)
3d42ea434d46 Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents: 17
diff changeset
91 {
25
b51e953f79eb Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents: 20
diff changeset
92 return errorCallback_ = errorCallback;
18
3d42ea434d46 Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents: 17
diff changeset
93 }
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 void setThrowOnErrorCallback ()
3d42ea434d46 Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents: 17
diff changeset
96 {
3d42ea434d46 Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents: 17
diff changeset
97 errorCallback = throwOnErrorCallback;
3d42ea434d46 Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents: 17
diff changeset
98 }
3d42ea434d46 Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents: 17
diff changeset
99
3d42ea434d46 Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents: 17
diff changeset
100 void setDoNothingOnErrorCallback ()
3d42ea434d46 Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents: 17
diff changeset
101 {
3d42ea434d46 Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents: 17
diff changeset
102 errorCallback = doNothingOnErrorCallback;
3d42ea434d46 Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents: 17
diff changeset
103 }
3d42ea434d46 Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents: 17
diff changeset
104
26
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
105 void reset ()
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
106 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
107 resetCounters();
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
108
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
109 serializers = null;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
110 deserializers = null;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
111
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
112 serializedReferences = null;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
113 deserializedReferences = null;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
114
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
115 serializedArrays = null;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
116 deserializedSlices = null;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
117
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
118 hasBegunSerializing = false;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
119 hasBegunDeserializing = false;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
120
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
121 archive.reset;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
122 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
123
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
124 Data serialize (T) (T value, string key = null)
0
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
125 {
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
126 if (!hasBegunSerializing)
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
127 hasBegunSerializing = true;
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
128
20
9a575087b961 Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 18
diff changeset
129 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
130 postProcess;
20
9a575087b961 Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 18
diff changeset
131
26
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
132 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
133 }
9a575087b961 Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 18
diff changeset
134
25
b51e953f79eb Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents: 20
diff changeset
135 private void serializeInternal (T) (T value, string key = null)
20
9a575087b961 Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 18
diff changeset
136 {
0
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
137 if (!key)
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
138 key = nextKey;
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
139
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
140 archive.beginArchiving();
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
141
26
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
142 static if ( is(T == typedef) )
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
143 serializeTypedef(value, key);
0
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
144
26
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
145 else static if (isObject!(T))
0
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
146 serializeObject(value, key);
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
147
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
148 else static if (isStruct!(T))
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
149 serializeStruct(value, key);
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
150
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
151 else static if (isString!(T))
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
152 serializeString(value, key);
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
153
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
154 else static if (isArray!(T))
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
155 serializeArray(value, key);
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
156
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
157 else static if (isAssociativeArray!(T))
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
158 serializeAssociativeArray(value, key);
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
159
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
160 else static if (isPrimitive!(T))
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
161 serializePrimitive(value, key);
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
162
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
163 else static if (isPointer!(T))
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
164 {
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
165 static if (isFunctionPointer!(T))
2
ea37a9470e3e Fixed multiple NonSerialized
Jacob Carlborg <doob@me.com>
parents: 0
diff changeset
166 goto error;
0
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
167
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
168 else
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
169 serializePointer(value, key);
2
ea37a9470e3e Fixed multiple NonSerialized
Jacob Carlborg <doob@me.com>
parents: 0
diff changeset
170 }
0
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
171
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
172 else static if (isEnum!(T))
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
173 serializeEnum(value, key);
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
174
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
175 else
2
ea37a9470e3e Fixed multiple NonSerialized
Jacob Carlborg <doob@me.com>
parents: 0
diff changeset
176 {
ea37a9470e3e Fixed multiple NonSerialized
Jacob Carlborg <doob@me.com>
parents: 0
diff changeset
177 error:
ea37a9470e3e Fixed multiple NonSerialized
Jacob Carlborg <doob@me.com>
parents: 0
diff changeset
178 throw new SerializationException(format!(`The type "`, T, `" cannot be serialized.`), __FILE__, __LINE__);
ea37a9470e3e Fixed multiple NonSerialized
Jacob Carlborg <doob@me.com>
parents: 0
diff changeset
179 }
0
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
180 }
25
b51e953f79eb Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents: 20
diff changeset
181
b51e953f79eb Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents: 20
diff changeset
182 private void serializeObject (T) (T value, string key)
b51e953f79eb Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents: 20
diff changeset
183 {
26
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
184 if (!value)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
185 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
186
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
187 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
188
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
189 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
190 return archive.archiveReference(key, reference);
25
b51e953f79eb Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents: 20
diff changeset
191
26
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
192 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
193
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
194 Id id = nextId;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
195 addSerializedReference(value, id);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
196
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
197 triggerEvents(serializing, value, {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
198 archive.archiveObject(runtimeType, T.stringof, key, id, {
0
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
199 if (runtimeType in serializers)
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
200 {
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
201 auto wrapper = getSerializerWrapper!(T)(runtimeType);
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
202 wrapper(value, this, key);
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
203 }
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
204
17
c4e7e64ffb67 Changed toData/fromData to take an instance of the serializer instead of the archive.
Jacob Carlborg <doob@me.com>
parents: 16
diff changeset
205 else static if (isSerializable!(T, Serializer))
0
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
206 value.toData(this, key);
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
207
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
208 else
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
209 {
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
210 if (isBaseClass(value))
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
211 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
212
2
ea37a9470e3e Fixed multiple NonSerialized
Jacob Carlborg <doob@me.com>
parents: 0
diff changeset
213 objectStructSerializeHelper(value);
0
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
214 }
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
215 });
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
216 });
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
217 }
25
b51e953f79eb Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents: 20
diff changeset
218
26
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
219 private void serializeStruct (T) (T value, string key)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
220 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
221 string type = T.stringof;
25
b51e953f79eb Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents: 20
diff changeset
222
0
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
223 triggerEvents(serializing, value, {
26
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
224 archive.archiveStruct(type, key, nextId, {
0
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
225 if (type in serializers)
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
226 {
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
227 auto wrapper = getSerializerWrapper!(T)(type);
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
228 wrapper(value, this, key);
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
229 }
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
230
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
231 else
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
232 {
17
c4e7e64ffb67 Changed toData/fromData to take an instance of the serializer instead of the archive.
Jacob Carlborg <doob@me.com>
parents: 16
diff changeset
233 static if (isSerializable!(T, Serializer))
0
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
234 value.toData(this, key);
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
235
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
236 else
2
ea37a9470e3e Fixed multiple NonSerialized
Jacob Carlborg <doob@me.com>
parents: 0
diff changeset
237 objectStructSerializeHelper(value);
0
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
238 }
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
239 });
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
240 });
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
241 }
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
242
25
b51e953f79eb Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents: 20
diff changeset
243 private void serializeString (T) (T value, string key)
0
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
244 {
26
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
245 auto id = nextId;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
246 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
247
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
248 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
249 addSerializedArray(array, id);
0
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
250 }
25
b51e953f79eb Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents: 20
diff changeset
251
b51e953f79eb Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents: 20
diff changeset
252 private void serializeArray (T) (T value, string key)
20
9a575087b961 Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents: 18
diff changeset
253 {
26
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
254 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
255 auto id = nextId;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
256
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
257 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
258 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
259 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
260 });
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
261
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
262 addSerializedArray(array, id);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
263 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
264
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
265 private void serializeAssociativeArray (T) (T value, string key)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
266 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
267 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
268 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
269
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
270 archive.archiveAssociativeArray(keyType, valueType, value.length, key, nextId, {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
271 size_t i;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
272
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
273 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
274 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
275 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
276 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
277 });
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
278
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
279 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
280 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
281 });
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
282
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
283 i++;
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 });
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
286 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
287
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
288 private void serializePointer (T) (T value, string key)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
289 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
290 if (!value)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
291 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
292
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
293 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
294
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
295 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
296 return archive.archiveReference(key, reference);
25
b51e953f79eb Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents: 20
diff changeset
297
26
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
298 Id id = nextId;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
299
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
300 addSerializedReference(value, id);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
301
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
302 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
303 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
304 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
305 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
306 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
307 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
308
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
309 else static if (isSerializable!(T, Serializer))
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
310 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
311
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
312 else
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 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
315 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
316
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
317 else
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
318 serializeInternal(*value, nextKey);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
319 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
320 });
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
321 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
322
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
323 private void serializeEnum (T) (T value, string key)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
324 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
325 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
326 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
327 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
328
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
329 archive.archiveEnum(val, type, key, nextId);
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
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
332 private void serializePrimitive (T) (T value, string 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 archive.archive(value, key, nextId);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
335 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
336
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
337 private void serializeTypedef (T) (T value, string key)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
338 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
339 archive.archiveTypedef(T.stringof, key, nextId, {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
340 serializeInternal!(BaseTypeOfTypedef!(T))(value, nextKey);
0
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
341 });
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
342 }
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
343
26
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
344 T deserialize (T) (Data data, string key = null)
0
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
345 {
26
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
346 if (hasBegunSerializing && !hasBegunDeserializing)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
347 resetCounters();
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
348
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
349 if (!hasBegunDeserializing)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
350 hasBegunDeserializing = true;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
351
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
352 if (!key)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
353 key = nextKey;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
354
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
355 archive.beginUnarchiving(data);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
356 return deserializeInternal!(T)(key);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
357 }
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 private T deserializeInternal (T) (string key)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
360 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
361 static if (isTypedef!(T))
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
362 return deserializeTypedef!(T)(key);
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 else static if (isObject!(T))
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
365 return deserializeObject!(T)(key);
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 else static if (isStruct!(T))
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
368 return deserializeStruct!(T)(key);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
369
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
370 else static if (isString!(T))
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
371 return deserializeString!(T)(key);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
372
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
373 else static if (isArray!(T))
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
374 return deserializeArray!(T)(key);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
375
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
376 else static if (isAssociativeArray!(T))
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
377 return deserializeAssociativeArray!(T)(key);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
378
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
379 else static if (isPrimitive!(T))
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
380 return deserializePrimitive!(T)(key);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
381
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
382 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
383 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
384 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
385 goto error;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
386
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
387 return deserializePointer!(T)(key);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
388 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
389
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
390 else static if (isEnum!(T))
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
391 return deserializeEnum!(T)(key);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
392
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
393 else
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
394 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
395 error:
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
396 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
397 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
398 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
399
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
400 private T deserializeObject (T) (string key)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
401 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
402 auto id = deserializeReference(key);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
403
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
404 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
405 return *reference;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
406
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
407 T value;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
408 Object val = value;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
409
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
410 archive.unarchiveObject(key, id, val, {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
411 triggerEvents(deserializing, value, {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
412 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
413 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
414
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
415 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
416 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
417 auto wrapper = getDeserializerWrapper!(T)(runtimeType);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
418 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
419 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
420
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
421 else static if (isSerializable!(T, Serializer))
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
422 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
423
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
424 else
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 if (isBaseClass(value))
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
427 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
428
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
429 objectStructDeserializeHelper(value);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
430 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
431 });
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
432 });
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
433
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
434 addDeserializedReference(value, id);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
435
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
436 return value;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
437 }
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 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
440 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
441 T value;
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 archive.unarchiveStruct(key, {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
444 triggerEvents(deserializing, value, {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
445 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
446
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
447 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
448 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
449 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
450 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
451 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
452
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
453 else
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
454 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
455 static if (isSerializable!(T, Serializer))
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
456 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
457
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
458 else
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
459 objectStructDeserializeHelper(value);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
460 }
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 });
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
463
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
464 return value;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
465 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
466
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
467 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
468 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
469 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
470
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
471 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
472 return *tmp;
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 T 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 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
477 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
478 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
479 value = archive.unarchiveString(slice.id).toSlice(slice);
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 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
482 value = archive.unarchiveWstring(slice.id).toSlice(slice);
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 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
485 value = archive.unarchiveDstring(slice.id).toSlice(slice);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
486 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
487
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
488 else
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
489 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
490 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
491 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
492
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
493 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
494 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
495
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
496 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
497 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
498 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
499
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
500 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
501
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
502 return value;
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
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
505 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
506 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
507 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
508
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
509 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
510 return *tmp;
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 T value;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
513
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
514 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
515 value.length = length;
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 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
518 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
519 };
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
520
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
521 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
522 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
523 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
524 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
525
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
526 return value.toSlice(slice);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
527 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
528
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
529 else
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
530 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
531 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
532
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
533 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
534 return cast(T) *a;
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 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
537
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
538 return value;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
539 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
540 }
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 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
543 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
544 T value;
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 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
547 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
548
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
549 archive.unarchiveAssociativeArray(key, (size_t length) {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
550 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
551 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
552 Key aaKey;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
553 Value aaValue;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
554 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
555
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
556 archive.unarchiveAssociativeArrayKey(k, {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
557 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
558 });
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
559
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
560 archive.unarchiveAssociativeArrayValue(k, {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
561 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
562 });
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
563
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
564 value[aaKey] = aaValue;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
565 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
566 });
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
567
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
568 return value;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
569 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
570
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
571 /* auto id = deserializeReference(key);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
572
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
573 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
574 return *reference;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
575
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
576 T value;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
577 Object val = value;
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 archive.unarchiveObject(key, id, val, {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
580 triggerEvents(deserializing, value, {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
581 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
582 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
583
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
584 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
585 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
586 auto wrapper = getDeserializerWrapper!(T)(runtimeType);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
587 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
588 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
589
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
590 else static if (isSerializable!(T, Serializer))
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
591 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
592
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
593 else
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
594 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
595 if (isBaseClass(value))
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
596 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
597
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
598 objectStructDeserializeHelper(value);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
599 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
600 });
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
601 });
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 addDeserializedReference(value, id);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
604
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
605 return value;
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
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
608 private T deserializePointer (T) (string key)
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 auto id = deserializeReference(key);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
611
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
612 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
613 return *reference;
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 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
616
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
617 id = archive.unarchivePointer(key, {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
618 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
619 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
620 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
621 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
622 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
623
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
624 else static if (isSerializable!(T, Serializer))
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
625 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
626
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
627 else
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
628 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
629 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
630 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
631
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
632 else
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
633 *value = deserializeInternal!(BaseTypeOfPointer!(T))(nextKey);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
634 }
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
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
637 addDeserializedReference(value, id);
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 return value;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
640 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
641
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
642 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
643 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
644 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
645
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
646 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
647 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
648 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
649
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
650 private T deserializePrimitive (T) (string key)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
651 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
652 const functionName = toUpper(T.stringof[0]) ~ T.stringof[1 .. $];
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
653 mixin("return archive.unarchive" ~ functionName ~ "(key);");
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
654 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
655
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
656 private T deserializeTypedef (T) (string key)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
657 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
658 T value;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
659
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
660 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
661 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
662 });
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
663
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
664 return value;
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
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
667 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
668 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
669 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
670 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
671
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
672 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
673 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
674 return archive.unarchiveSlice(key);
0
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
675 }
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
676
3
3c155e4c3d56 Fixed structs
Jacob Carlborg <doob@me.com>
parents: 2
diff changeset
677 private void objectStructSerializeHelper (T) (ref T value)
3c155e4c3d56 Fixed structs
Jacob Carlborg <doob@me.com>
parents: 2
diff changeset
678 {
3c155e4c3d56 Fixed structs
Jacob Carlborg <doob@me.com>
parents: 2
diff changeset
679 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.`));
8
613a0bb20207 Now works with dmd 1.062
Jacob Carlborg <doob@me.com>
parents: 4
diff changeset
680 const nonSerializedFields = collectAnnotations!(nonSerializedField, T);
3
3c155e4c3d56 Fixed structs
Jacob Carlborg <doob@me.com>
parents: 2
diff changeset
681
3c155e4c3d56 Fixed structs
Jacob Carlborg <doob@me.com>
parents: 2
diff changeset
682 foreach (i, dummy ; typeof(T.tupleof))
3c155e4c3d56 Fixed structs
Jacob Carlborg <doob@me.com>
parents: 2
diff changeset
683 {
3c155e4c3d56 Fixed structs
Jacob Carlborg <doob@me.com>
parents: 2
diff changeset
684 const field = nameOfFieldAt!(T, i);
3c155e4c3d56 Fixed structs
Jacob Carlborg <doob@me.com>
parents: 2
diff changeset
685
3c155e4c3d56 Fixed structs
Jacob Carlborg <doob@me.com>
parents: 2
diff changeset
686 static if (!internalFields.ctfeContains(field) && !nonSerializedFields.ctfeContains(field))
3c155e4c3d56 Fixed structs
Jacob Carlborg <doob@me.com>
parents: 2
diff changeset
687 {
3c155e4c3d56 Fixed structs
Jacob Carlborg <doob@me.com>
parents: 2
diff changeset
688 alias typeof(T.tupleof[i]) Type;
3c155e4c3d56 Fixed structs
Jacob Carlborg <doob@me.com>
parents: 2
diff changeset
689 Type v = value.tupleof[i];
26
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
690 serializeInternal(v, toData(field));
3
3c155e4c3d56 Fixed structs
Jacob Carlborg <doob@me.com>
parents: 2
diff changeset
691 }
3c155e4c3d56 Fixed structs
Jacob Carlborg <doob@me.com>
parents: 2
diff changeset
692 }
2
ea37a9470e3e Fixed multiple NonSerialized
Jacob Carlborg <doob@me.com>
parents: 0
diff changeset
693
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
694 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
695 serializeBaseTypes(value);
3
3c155e4c3d56 Fixed structs
Jacob Carlborg <doob@me.com>
parents: 2
diff changeset
696 }
3c155e4c3d56 Fixed structs
Jacob Carlborg <doob@me.com>
parents: 2
diff changeset
697
3c155e4c3d56 Fixed structs
Jacob Carlborg <doob@me.com>
parents: 2
diff changeset
698 private void objectStructDeserializeHelper (T) (ref T value)
3c155e4c3d56 Fixed structs
Jacob Carlborg <doob@me.com>
parents: 2
diff changeset
699 {
3c155e4c3d56 Fixed structs
Jacob Carlborg <doob@me.com>
parents: 2
diff changeset
700 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.`));
8
613a0bb20207 Now works with dmd 1.062
Jacob Carlborg <doob@me.com>
parents: 4
diff changeset
701 const nonSerializedFields = collectAnnotations!(nonSerializedField, T);
3
3c155e4c3d56 Fixed structs
Jacob Carlborg <doob@me.com>
parents: 2
diff changeset
702
3c155e4c3d56 Fixed structs
Jacob Carlborg <doob@me.com>
parents: 2
diff changeset
703 foreach (i, dummy ; typeof(T.tupleof))
3c155e4c3d56 Fixed structs
Jacob Carlborg <doob@me.com>
parents: 2
diff changeset
704 {
3c155e4c3d56 Fixed structs
Jacob Carlborg <doob@me.com>
parents: 2
diff changeset
705 const field = nameOfFieldAt!(T, i);
3c155e4c3d56 Fixed structs
Jacob Carlborg <doob@me.com>
parents: 2
diff changeset
706
3c155e4c3d56 Fixed structs
Jacob Carlborg <doob@me.com>
parents: 2
diff changeset
707 static if (!internalFields.ctfeContains(field) && !nonSerializedFields.ctfeContains(field))
3c155e4c3d56 Fixed structs
Jacob Carlborg <doob@me.com>
parents: 2
diff changeset
708 {
3c155e4c3d56 Fixed structs
Jacob Carlborg <doob@me.com>
parents: 2
diff changeset
709 alias TypeOfField!(T, field) Type;
26
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
710 auto fieldValue = deserializeInternal!(Type)(toData(field));
3
3c155e4c3d56 Fixed structs
Jacob Carlborg <doob@me.com>
parents: 2
diff changeset
711 value.tupleof[i] = fieldValue;
3c155e4c3d56 Fixed structs
Jacob Carlborg <doob@me.com>
parents: 2
diff changeset
712 }
3c155e4c3d56 Fixed structs
Jacob Carlborg <doob@me.com>
parents: 2
diff changeset
713 }
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
714
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
715 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
716 deserializeBaseTypes(value);
0
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
717 }
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
718
2
ea37a9470e3e Fixed multiple NonSerialized
Jacob Carlborg <doob@me.com>
parents: 0
diff changeset
719 private void serializeBaseTypes (T : Object) (T value)
0
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
720 {
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
721 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
722
0
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
723 static if (!is(Base == Object))
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
724 {
25
b51e953f79eb Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents: 20
diff changeset
725 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
726 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
727 objectStructSerializeHelper(base);
0
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
728 }
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
729 }
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
730
2
ea37a9470e3e Fixed multiple NonSerialized
Jacob Carlborg <doob@me.com>
parents: 0
diff changeset
731 private void deserializeBaseTypes (T : Object) (T value)
0
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
732 {
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
733 alias BaseTypeTupleOf!(T)[0] Base;
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
734
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
735 static if (!is(Base == Object))
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
736 {
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
737 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
738 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
739 objectStructDeserializeHelper(base);
0
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
740 }
26
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
741 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
742
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
743 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
744 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
745 static assert(isReference!(T), format!(`The given type "`, T, `" is not a reference type, i.e. object or pointer.`));
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
746
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
747 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
748 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
749
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
750 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
751 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
752 static assert(isReference!(T), format!(`The given type "`, T, `" is not a reference type, i.e. object or pointer.`));
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
753
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
754 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
755 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
756
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
757 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
758 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
759 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
760
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
761 deserializedSlices[id] = value;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
762 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
763
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
764 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
765 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
766 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
767 return *tmp;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
768
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
769 return Id.max;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
770 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
771
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
772 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
773 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
774 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
775 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
776
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
777 return null;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
778 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
779
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
780 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
781 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
782 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
783 return &(cast(T) *array)[slice.offset .. slice.offset + slice.length]; // dereference the array, cast it to the right type,
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
784 // slice it and then return a pointer to the result }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
785 return null;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
786 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
787
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
788 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
789 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
790 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
791 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
792 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
793
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
794 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
795 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
796 return array[slice.offset .. slice.offset + slice.length];
0
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
797 }
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
798
15
9f6064f9505a Changed from archive to serializer in the register wrappers.
Jacob Carlborg <doob@me.com>
parents: 14
diff changeset
799 private SerializeRegisterWrapper!(T, Serializer) getSerializerWrapper (T) (string type)
0
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
800 {
15
9f6064f9505a Changed from archive to serializer in the register wrappers.
Jacob Carlborg <doob@me.com>
parents: 14
diff changeset
801 auto wrapper = cast(SerializeRegisterWrapper!(T, Serializer)) serializers[type];
0
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
802
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
803 if (wrapper)
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
804 return wrapper;
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
805
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
806 assert(false, "throw exception here");
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
807 }
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
808
15
9f6064f9505a Changed from archive to serializer in the register wrappers.
Jacob Carlborg <doob@me.com>
parents: 14
diff changeset
809 private DeserializeRegisterWrapper!(T, Serializer) getDeserializerWrapper (T) (string type)
0
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
810 {
15
9f6064f9505a Changed from archive to serializer in the register wrappers.
Jacob Carlborg <doob@me.com>
parents: 14
diff changeset
811 auto wrapper = cast(DeserializeRegisterWrapper!(T, Serializer)) deserializers[type];
0
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
812
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
813 if (wrapper)
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
814 return wrapper;
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
815
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
816 assert(false, "throw exception here");
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
817 }
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
818
25
b51e953f79eb Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents: 20
diff changeset
819 private SerializeRegisterWrapper!(T, Serializer) toSerializeRegisterWrapper (T) (void delegate (T, Serializer, string) dg)
0
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
820 {
16
091ff1b263db Missed some in the previous commit.
Jacob Carlborg <doob@me.com>
parents: 15
diff changeset
821 return new SerializeRegisterWrapper!(T, Serializer)(dg);
0
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
822 }
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
823
25
b51e953f79eb Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents: 20
diff changeset
824 private SerializeRegisterWrapper!(T, Serializer) toSerializeRegisterWrapper (T) (void function (T, Serializer, string) func)
0
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
825 {
16
091ff1b263db Missed some in the previous commit.
Jacob Carlborg <doob@me.com>
parents: 15
diff changeset
826 return new SerializeRegisterWrapper!(T, Serializer)(func);
0
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
827 }
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
828
25
b51e953f79eb Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents: 20
diff changeset
829 private DeserializeRegisterWrapper!(T, Serializer) toDeserializeRegisterWrapper (T) (void delegate (ref T, Serializer, string) dg)
0
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
830 {
16
091ff1b263db Missed some in the previous commit.
Jacob Carlborg <doob@me.com>
parents: 15
diff changeset
831 return new DeserializeRegisterWrapper!(T, Serializer)(dg);
0
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
832 }
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
833
25
b51e953f79eb Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents: 20
diff changeset
834 private DeserializeRegisterWrapper!(T, Serializer) toDeserializeRegisterWrapper (T) (void function (ref T, Serializer, string) func)
0
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
835 {
16
091ff1b263db Missed some in the previous commit.
Jacob Carlborg <doob@me.com>
parents: 15
diff changeset
836 return new DeserializeRegisterWrapper!(T, Serializer)(func);
0
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
837 }
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
838
26
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
839 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
840 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
841 serializedArrays[id] = array;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
842 }
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 private void postProcessArrays ()
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
845 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
846 bool foundSlice = true;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
847
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
848 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
849 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
850 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
851 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
852 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
853 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
854 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
855 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
856 foundSlice = true;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
857 break;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
858 }
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 else
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
861 foundSlice = false;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
862 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
863
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
864 if (!foundSlice)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
865 archive.postProcessArray(sliceKey);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
866 }
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
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
869 private void postProcess ()
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 postProcessArrays();
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
872 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
873
25
b51e953f79eb Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents: 20
diff changeset
874 private template arrayToString (T)
0
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
875 {
26
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
876 const arrayToString = ElementTypeOfArray!(T).stringof;
0
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
877 }
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
878
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
879 private bool isBaseClass (T) (T value)
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
880 {
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
881 auto name = value.classinfo.name;
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
882 auto index = name.lastIndexOf('.');
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
883
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
884 return T.stringof != name[index + 1 .. $];
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
885 }
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
886
26
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
887 private Id nextId ()
25
b51e953f79eb Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents: 20
diff changeset
888 {
b51e953f79eb Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents: 20
diff changeset
889 return idCounter++;
b51e953f79eb Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents: 20
diff changeset
890 }
b51e953f79eb Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents: 20
diff changeset
891
b51e953f79eb Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents: 20
diff changeset
892 private string nextKey ()
0
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
893 {
26
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
894 return toData(keyCounter++);
0
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
895 }
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
896
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
897 private void resetCounters ()
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
898 {
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
899 keyCounter = 0;
25
b51e953f79eb Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents: 20
diff changeset
900 idCounter = 0;
b51e953f79eb Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents: 20
diff changeset
901 }
b51e953f79eb Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents: 20
diff changeset
902
26
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
903 private string toData (T) (T value)
25
b51e953f79eb Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents: 20
diff changeset
904 {
b51e953f79eb Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents: 20
diff changeset
905 return to!(string)(value);
0
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
906 }
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
907
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
908 private void triggerEvent (string name, T) (T value)
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
909 {
3
3c155e4c3d56 Fixed structs
Jacob Carlborg <doob@me.com>
parents: 2
diff changeset
910 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
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
911
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
912 foreach (i, dummy ; typeof(T.tupleof))
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
913 {
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
914 const field = nameOfFieldAt!(T, i);
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
915
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
916 static if (field == name)
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
917 {
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
918 alias TypeOfField!(T, field) Type;
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
919 auto event = getValueOfField!(T, Type, field)(value);
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
920 event(value);
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
921 }
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
922 }
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
923 }
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
924
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
925 private void triggerEvents (T) (Mode mode, T value, void delegate () dg)
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
926 {
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
927 if (mode == serializing)
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
928 triggerEvent!(onSerializingField)(value);
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
929
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
930 else
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
931 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
932
0
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
933 dg();
26
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
934
0
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
935 if (mode == serializing)
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
936 triggerEvent!(onSerializedField)(value);
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
937
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
938 else
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
939 triggerEvent!(onDeserializedField)(value);
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
940 }
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
941
8
613a0bb20207 Now works with dmd 1.062
Jacob Carlborg <doob@me.com>
parents: 4
diff changeset
942 private static string[] collectAnnotations (string name, T) ()
0
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
943 {
3
3c155e4c3d56 Fixed structs
Jacob Carlborg <doob@me.com>
parents: 2
diff changeset
944 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
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
945
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
946 string[] annotations;
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
947
8
613a0bb20207 Now works with dmd 1.062
Jacob Carlborg <doob@me.com>
parents: 4
diff changeset
948 foreach (i, type ; typeof(T.tupleof))
0
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
949 {
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
950 const field = nameOfFieldAt!(T, i);
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
951
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
952 static if (field == name)
8
613a0bb20207 Now works with dmd 1.062
Jacob Carlborg <doob@me.com>
parents: 4
diff changeset
953 annotations ~= type.field;
0
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
954 }
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
955
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
956 return annotations;
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
957 }
26
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
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
961
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
962 debug (OrangeUnitTest)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
963 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
964 import orange.serialization.archives.XMLArchive;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
965
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
966 enum Foo { a, b, c }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
967 typedef int Int;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
968
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
969 class A {}
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
970 struct B {}
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
971 class C { string str; }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
972 class D { int[] arr; }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
973 class E { int[int] aa; }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
974 class F { int value; int* ptr; }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
975 class G { Foo foo; }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
976
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
977 class H
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
978 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
979 bool bool_;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
980 byte byte_;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
981 //cdouble cdouble_; // currently not suppported by to!()
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
982 //cent cent_; // currently not implemented but a reserved keyword
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
983 //cfloat cfloat_; // currently not suppported by to!()
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
984 char char_;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
985 //creal creal_; // currently not suppported by to!()
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
986 dchar dchar_;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
987 double double_;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
988 float float_;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
989 //idouble idouble_; // currently not suppported by to!()
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
990 //ifloat ifloat_; // currently not suppported by to!()
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
991 int int_;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
992 //ireal ireal_; // currently not suppported by to!()
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
993 long long_;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
994 real real_;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
995 short short_;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
996 ubyte ubyte_;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
997 //ucent ucent_; // currently not implemented but a reserved keyword
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
998 uint uint_;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
999 ulong ulong_;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1000 ushort ushort_;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1001 wchar wchar_;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1002
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1003 equals_t opEquals (Object other)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1004 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1005 if (auto o = cast(H) other)
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1006 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1007 return bool_ == o.bool_ &&
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1008 byte_ == o.byte_ &&
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1009 //cdouble_ == o.cdouble_ && // currently not suppported by to!()
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1010 //cent_ == o.cent_ && // currently not implemented but a reserved keyword
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1011 //cfloat_ == o.cfloat_ && // currently not suppported by to!()
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1012 char_ == o.char_ &&
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1013 //creal_ == o.creal_ && // currently not suppported by to!()
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1014 dchar_ == o.dchar_ &&
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1015 double_ == o.double_ &&
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1016 float_ == o.float_ &&
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1017 //idouble_ == o.idouble_ && // currently not suppported by to!()
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1018 //ifloat_ == o.ifloat_ && // currently not suppported by to!()
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1019 int_ == o.int_ &&
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1020 //ireal_ == o.ireal_ && // currently not suppported by to!()
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1021 long_ == o.long_ &&
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1022 real_ == o.real_ &&
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1023 short_ == o.short_ &&
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1024 ubyte_ == o.ubyte_ &&
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1025 //ucent_ == o.ucent_ && // currently not implemented but a reserved keyword
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1026 uint_ == o.uint_ &&
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1027 ulong_ == o.ulong_ &&
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1028 ushort_ == o.ushort_ &&
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1029 wchar_ == o.wchar_;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1030 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1031
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1032 return false;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1033 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1034 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1035
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1036 class I
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1037 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1038 Int a;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1039 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1040
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1041 void main ()
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1042 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1043 auto archive = new XMLArchive!(char);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1044 auto serializer = new Serializer(archive);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1045 string data;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1046
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1047 void serializeObject ()
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1048 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1049 serializer.reset;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1050 data = `<?xml version="1.0" encoding="UTF-8"?>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1051 <archive type="org.dsource.orange.xml" version="1.0.0">
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1052 <data>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1053 <struct type="B" key="0"/>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1054 </data>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1055 </archive>`;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1056
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1057 serializer.serialize(B());
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1058 assert(archive.data == data);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1059 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1060
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1061 void serializeStruct ()
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1062 {
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1063 serializer.reset;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1064 data = `<?xml version="1.0" encoding="UTF-8"?>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1065 <archive type="org.dsource.orange.xml" version="1.0.0">
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1066 <data>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1067 <struct type="B" key="0"/>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1068 </data>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1069 </archive>`;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1070
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1071 serializer.serialize(B());
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1072 assert(archive.data == data);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1073 }
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1074
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1075 // Struct
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1076
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1077
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1078
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1079 // String
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1080
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1081 serializer.reset;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1082 data = `<?xml version="1.0" encoding="UTF-8"?>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1083 <archive type="org.dsource.orange.xml" version="1.0.0">
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1084 <data>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1085 <object runtimeType="orange.serialization.Serializer.C" type="C" key="0" id="0">
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1086 <string type="char" length="3" key="str" id="1">foo</string>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1087 </object>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1088 </data>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1089 </archive>`;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1090
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1091 auto c = new C;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1092 c.str = "foo";
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1093 serializer.serialize(c);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1094 assert(archive.data == data);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1095
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1096 // Deserializing
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1097
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1098 auto cDeserialized = serializer.deserialize!(C)(data);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1099 assert(c.str == cDeserialized.str);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1100
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1101 // Array
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1102
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1103 serializer.reset;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1104 data = `<?xml version="1.0" encoding="UTF-8"?>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1105 <archive type="org.dsource.orange.xml" version="1.0.0">
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1106 <data>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1107 <object runtimeType="orange.serialization.Serializer.D" type="D" key="0" id="0">
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1108 <array type="int" length="6" key="arr" id="1">
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1109 <int key="0">27</int>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1110 <int key="1">382</int>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1111 <int key="2">283</int>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1112 <int key="3">3820</int>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1113 <int key="4">32</int>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1114 <int key="5">832</int>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1115 </array>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1116 </object>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1117 </data>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1118 </archive>`;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1119
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1120 auto d = new D;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1121 d.arr = [27, 382, 283, 3820, 32, 832];
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1122 serializer.serialize(d);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1123 assert(archive.data == data);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1124
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1125 // Deserializing
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1126
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1127 auto dDeserialized = serializer.deserialize!(D)(data);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1128 assert(d.arr == dDeserialized.arr);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1129
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1130 // Associative Array
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1131
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1132 serializer.reset();
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1133 data = `<?xml version="1.0" encoding="UTF-8"?>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1134 <archive type="org.dsource.orange.xml" version="1.0.0">
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1135 <data>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1136 <object runtimeType="orange.serialization.Serializer.E" type="E" key="0" id="0">
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1137 <associativeArray keyType="int" valueType="int" length="4" key="aa">
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1138 <key key="0">
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1139 <int key="0">1</int>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1140 </key>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1141 <value key="0">
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1142 <int key="0">2</int>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1143 </value>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1144 <key key="1">
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1145 <int key="1">3</int>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1146 </key>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1147 <value key="1">
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1148 <int key="1">4</int>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1149 </value>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1150 <key key="2">
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1151 <int key="2">6</int>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1152 </key>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1153 <value key="2">
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1154 <int key="2">7</int>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1155 </value>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1156 <key key="3">
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1157 <int key="3">39</int>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1158 </key>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1159 <value key="3">
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1160 <int key="3">472</int>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1161 </value>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1162 </associativeArray>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1163 </object>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1164 </data>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1165 </archive>`;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1166
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1167 auto e = new E;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1168 e.aa = [3 : 4, 1 : 2, 39 : 472, 6 : 7];
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1169 serializer.serialize(e);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1170 assert(archive.data == data);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1171
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1172 // Deserializing
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1173
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1174 auto eDeserialized = serializer.deserialize!(E)(data);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1175 //assert(e.aa == eDeserialized.aa); // cannot compare associative array
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1176
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1177 // Pointer
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1178
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1179 serializer.reset();
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1180 data = `<?xml version="1.0" encoding="UTF-8"?>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1181 <archive type="org.dsource.orange.xml" version="1.0.0">
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1182 <data>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1183 <object runtimeType="orange.serialization.Serializer.F" type="F" key="0" id="0">
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1184 <pointer key="ptr" id="2">
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1185 <int key="1">9</int>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1186 </pointer>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1187 <int key="value">9</int>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1188 </object>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1189 </data>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1190 </archive>`;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1191
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1192 auto f = new F;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1193 f.value = 9;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1194 f.ptr = &f.value;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1195 serializer.serialize(f);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1196 //assert(archive.data == data); // this is not a reliable comparison, the order of int and pointer is not reliable
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1197
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1198 // Deserializing
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1199
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1200 auto fDeserialized = serializer.deserialize!(F)(data);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1201 assert(*f.ptr == *fDeserialized.ptr);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1202
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1203 // Enum
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1204
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1205 serializer.reset();
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1206 data = `<?xml version="1.0" encoding="UTF-8"?>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1207 <archive type="org.dsource.orange.xml" version="1.0.0">
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1208 <data>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1209 <object runtimeType="orange.serialization.Serializer.G" type="G" key="0" id="0">
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1210 <enum type="Foo" baseType="int" key="foo">1</enum>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1211 </object>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1212 </data>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1213 </archive>`;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1214
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1215 auto g = new G;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1216 g.foo = Foo.b;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1217 serializer.serialize(g);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1218 assert(archive.data == data);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1219
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1220 // Deserializing
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1221
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1222 auto gDeserialized = serializer.deserialize!(G)(data);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1223 assert(g.foo == gDeserialized.foo);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1224
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1225 // Primitives
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1226
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1227 serializer.reset;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1228 data = `<?xml version="1.0" encoding="UTF-8"?>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1229 <archive type="org.dsource.orange.xml" version="1.0.0">
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1230 <data>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1231 <object runtimeType="orange.serialization.Serializer.H" type="H" key="0" id="0">
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1232 <byte key="byte_">1</byte>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1233 <char key="char_">a</char>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1234 <dchar key="dchar_">b</dchar>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1235 <double key="double_">0</double>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1236 <float key="float_">0</float>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1237 <int key="int_">1</int>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1238 <long key="long_">1</long>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1239 <real key="real_">0</real>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1240 <short key="short_">1</short>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1241 <ubyte key="ubyte_">1</ubyte>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1242 <uint key="uint_">1</uint>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1243 <ulong key="ulong_">1</ulong>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1244 <ushort key="ushort_">1</ushort>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1245 <wchar key="wchar_">c</wchar>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1246 <bool key="bool_">true</bool>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1247 </object>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1248 </data>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1249 </archive>`;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1250
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1251 auto h = new H;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1252
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1253 h.bool_ = true;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1254 h.byte_ = 1;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1255 h.char_ = 'a';
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1256 //h.cdouble_ = 0.0 + 0.0 * 1.0i; // currently not suppported by to!()
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1257 //h.cfloat_ = 0.0f + 0.0f * 1.0i; // currently not suppported by to!()
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1258 //h.creal_ = 0.0 + 0.0 * 1.0i; // currently not suppported by to!()
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1259 h.dchar_ = 'b';
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1260 h.double_ = 0.0;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1261 h.float_ = 0.0f;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1262 //h.idouble_ = 0.0 * 1.0i; // currently not suppported by to!()
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1263 //h.ifloat_ = 0.0f * 1.0i; // currently not suppported by to!()
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1264 h.int_ = 1;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1265 //h.ireal_ = 0.0 * 1.0i; // currently not suppported by to!()
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1266 h.long_ = 1L;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1267 h.real_ = 0.0;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1268 h.short_ = 1;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1269 h.ubyte_ = 1U;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1270 h.uint_ = 1U;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1271 h.ulong_ = 1LU;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1272 h.ushort_ = 1U;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1273 h.wchar_ = 'c';
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1274
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1275 serializer.serialize(h);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1276 //assert(archive.data == data); // this is not a reliable comparison
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1277
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1278 // Deserializing
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1279
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1280 auto hDeserialized = serializer.deserialize!(H)(data);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1281 assert(h == hDeserialized);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1282
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1283 // Typedef
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1284
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1285 serializer.reset();
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1286 data = `<?xml version="1.0" encoding="UTF-8"?>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1287 <archive type="org.dsource.orange.xml" version="1.0.0">
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1288 <data>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1289 <object runtimeType="orange.serialization.Serializer.I" type="I" key="0" id="0">
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1290 <typedef type="Int" key="a">
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1291 <int key="1">1</int>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1292 </typedef>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1293 </object>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1294 </data>
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1295 </archive>`;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1296
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1297 auto i = new I;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1298 i.a = 1;
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1299 serializer.serialize(i);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1300 assert(archive.data == data);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1301
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1302 // Deserializing
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1303
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1304 auto iDeserialized = serializer.deserialize!(I)(data);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1305 assert(i.a == iDeserialized.a);
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1306
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1307 println("unit tests successful");
78e5fef4bbf2 Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents: 25
diff changeset
1308 }
0
f7b078e85f7f First commit
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1309 }