Mercurial > projects > orange
annotate orange/serialization/archives/Archive.d @ 51:70df72d2299a default tip
Added unit tests for events.
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Sat, 13 Aug 2011 17:06:35 +0200 |
parents | 9c9bbef6bf5e |
children |
rev | line source |
---|---|
0 | 1 /** |
2 * Copyright: Copyright (c) 2010 Jacob Carlborg. | |
3 * Authors: Jacob Carlborg | |
4 * Version: Initial created: Feb 6, 2010 | |
5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0) | |
6 */ | |
7 module orange.serialization.archives.Archive; | |
8 | |
9 version (Tango) | |
10 import tango.util.Convert; | |
11 | |
9
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
0
diff
changeset
|
12 else |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
0
diff
changeset
|
13 { |
44
1fef41162966
Fixed deserialization of whcar for D2. Fixed events for D2.
Jacob Carlborg <doob@me.com>
parents:
35
diff
changeset
|
14 import std.array; |
9
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
0
diff
changeset
|
15 import std.conv; |
44
1fef41162966
Fixed deserialization of whcar for D2. Fixed events for D2.
Jacob Carlborg <doob@me.com>
parents:
35
diff
changeset
|
16 import std.utf; |
1fef41162966
Fixed deserialization of whcar for D2. Fixed events for D2.
Jacob Carlborg <doob@me.com>
parents:
35
diff
changeset
|
17 |
34
068e853b9c07
Cleaned up. Updated to latest D2 compiler.
Jacob Carlborg <doob@me.com>
parents:
33
diff
changeset
|
18 alias ConvException ConversionException; |
9
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
0
diff
changeset
|
19 } |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
0
diff
changeset
|
20 |
0 | 21 import orange.serialization.archives.ArchiveException; |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
22 import orange.core.string; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
23 |
25
b51e953f79eb
Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
24
diff
changeset
|
24 private enum ArchiveMode |
b51e953f79eb
Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
24
diff
changeset
|
25 { |
b51e953f79eb
Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
24
diff
changeset
|
26 archiving, |
b51e953f79eb
Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
24
diff
changeset
|
27 unarchiving |
b51e953f79eb
Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
24
diff
changeset
|
28 } |
b51e953f79eb
Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
24
diff
changeset
|
29 |
24
55f0a9d5df8d
First step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
30 struct Array |
55f0a9d5df8d
First step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
31 { |
35
511d1ef4e299
Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents:
34
diff
changeset
|
32 version (Tango) |
511d1ef4e299
Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents:
34
diff
changeset
|
33 void* ptr; |
511d1ef4e299
Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents:
34
diff
changeset
|
34 |
511d1ef4e299
Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents:
34
diff
changeset
|
35 else |
511d1ef4e299
Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents:
34
diff
changeset
|
36 mixin(`const(void)* ptr;`); |
34
068e853b9c07
Cleaned up. Updated to latest D2 compiler.
Jacob Carlborg <doob@me.com>
parents:
33
diff
changeset
|
37 |
24
55f0a9d5df8d
First step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
38 size_t length; |
55f0a9d5df8d
First step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
39 size_t elementSize; |
55f0a9d5df8d
First step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
40 |
55f0a9d5df8d
First step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
41 bool isSliceOf (Array b) |
55f0a9d5df8d
First step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
42 { |
55f0a9d5df8d
First step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
43 return ptr >= b.ptr && ptr + length * elementSize <= b.ptr + b.length * b.elementSize; |
55f0a9d5df8d
First step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
44 } |
55f0a9d5df8d
First step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
45 } |
0 | 46 |
20
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
47 struct Slice |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
48 { |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
49 size_t length; |
24
55f0a9d5df8d
First step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
50 size_t offset; |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
51 size_t id = size_t.max; |
20
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
52 } |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
53 |
28
bffcbc8c392b
Associative arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
26
diff
changeset
|
54 interface Archive |
0 | 55 { |
34
068e853b9c07
Cleaned up. Updated to latest D2 compiler.
Jacob Carlborg <doob@me.com>
parents:
33
diff
changeset
|
56 alias size_t Id; |
068e853b9c07
Cleaned up. Updated to latest D2 compiler.
Jacob Carlborg <doob@me.com>
parents:
33
diff
changeset
|
57 |
068e853b9c07
Cleaned up. Updated to latest D2 compiler.
Jacob Carlborg <doob@me.com>
parents:
33
diff
changeset
|
58 version (Tango) alias void[] UntypedData; |
068e853b9c07
Cleaned up. Updated to latest D2 compiler.
Jacob Carlborg <doob@me.com>
parents:
33
diff
changeset
|
59 else mixin ("alias immutable(void)[] UntypedData;"); |
24
55f0a9d5df8d
First step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
60 |
0 | 61 void beginArchiving (); |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
62 void beginUnarchiving (UntypedData data); |
24
55f0a9d5df8d
First step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
63 |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
64 UntypedData untypedData (); |
0 | 65 void reset (); |
24
55f0a9d5df8d
First step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
66 |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
67 void archiveArray (Array array, string type, string key, Id id, void delegate () dg); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
68 void archiveAssociativeArray (string keyType, string valueType, size_t length, string key, Id id, void delegate () dg); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
69 void archiveAssociativeArrayKey (string key, void delegate () dg); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
70 void archiveAssociativeArrayValue (string key, void delegate () dg); |
24
55f0a9d5df8d
First step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
71 |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
72 void archiveEnum (bool value, string baseType, string key, Id id); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
73 void archiveEnum (byte value, string baseType, string key, Id id); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
74 void archiveEnum (char value, string baseType, string key, Id id); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
75 void archiveEnum (dchar value, string baseType, string key, Id id); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
76 void archiveEnum (int value, string baseType, string key, Id id); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
77 void archiveEnum (long value, string baseType, string key, Id id); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
78 void archiveEnum (short value, string baseType, string key, Id id); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
79 void archiveEnum (ubyte value, string baseType, string key, Id id); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
80 void archiveEnum (uint value, string baseType, string key, Id id); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
81 void archiveEnum (ulong value, string baseType, string key, Id id); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
82 void archiveEnum (ushort value, string baseType, string key, Id id); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
83 void archiveEnum (wchar value, string baseType, string key, Id id); |
24
55f0a9d5df8d
First step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
84 |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
85 void archiveBaseClass (string type, string key, Id id); |
24
55f0a9d5df8d
First step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
86 void archiveNull (string type, string key); |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
87 void archiveObject (string runtimeType, string type, string key, Id id, void delegate () dg); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
88 void archivePointer (string key, Id id, void delegate () dg); |
33
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
29
diff
changeset
|
89 void archivePointer (Id pointeeId, string key, Id id); |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
90 void archiveReference (string key, Id id); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
91 void archiveSlice (Slice slice, Id sliceId, Id arrayId); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
92 void archiveStruct (string type, string key, Id id, void delegate () dg); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
93 void archiveTypedef (string type, string key, Id id, void delegate () dg); |
24
55f0a9d5df8d
First step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
94 |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
95 void archive (string value, string key, Id id); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
96 void archive (wstring value, string key, Id id); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
97 void archive (dstring value, string key, Id id); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
98 void archive (bool value, string key, Id id); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
99 void archive (byte value, string key, Id id); |
33
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
29
diff
changeset
|
100 //void archive (cdouble value, string key, Id id); // currently not supported by to!() |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
101 //void archive (cent value, string key, Id id); |
33
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
29
diff
changeset
|
102 //void archive (cfloat value, string key, Id id); // currently not supported by to!() |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
103 void archive (char value, string key, Id id); // currently not implemented but a reserved keyword |
33
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
29
diff
changeset
|
104 //void archive (creal value, string key, Id id); // currently not supported by to!() |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
105 void archive (dchar value, string key, Id id); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
106 void archive (double value, string key, Id id); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
107 void archive (float value, string key, Id id); |
33
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
29
diff
changeset
|
108 //void archive (idouble value, string key, Id id); // currently not supported by to!() |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
29
diff
changeset
|
109 //void archive (ifloat value, string key, Id id); // currently not supported by to!() |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
110 void archive (int value, string key, Id id); |
33
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
29
diff
changeset
|
111 //void archive (ireal value, string key, Id id); // currently not supported by to!() |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
112 void archive (long value, string key, Id id); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
113 void archive (real value, string key, Id id); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
114 void archive (short value, string key, Id id); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
115 void archive (ubyte value, string key, Id id); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
116 //void archive (ucent value, string key, Id id); // 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
|
117 void archive (uint value, string key, Id id); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
118 void archive (ulong value, string key, Id id); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
119 void archive (ushort value, string key, Id id); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
120 void archive (wchar value, string key, Id id); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
121 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
122 Id unarchiveArray (string key, void delegate (size_t length) dg); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
123 void unarchiveArray (Id id, void delegate (size_t length) dg); |
28
bffcbc8c392b
Associative arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
26
diff
changeset
|
124 Id unarchiveAssociativeArray (string type, void delegate (size_t length) dg); |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
125 void unarchiveAssociativeArrayKey (string key, void delegate () dg); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
126 void unarchiveAssociativeArrayValue (string key, void delegate () dg); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
127 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
128 bool unarchiveEnumBool (string key); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
129 byte unarchiveEnumByte (string key); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
130 char unarchiveEnumChar (string key); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
131 dchar unarchiveEnumDchar (string key); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
132 int unarchiveEnumInt (string key); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
133 long unarchiveEnumLong (string key); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
134 short unarchiveEnumShort (string key); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
135 ubyte unarchiveEnumUbyte (string key); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
136 uint unarchiveEnumUint (string key); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
137 ulong unarchiveEnumUlong (string key); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
138 ushort unarchiveEnumUshort (string key); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
139 wchar unarchiveEnumWchar (string key); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
140 |
47
9c9bbef6bf5e
Implemented unarchiveBaseClass. Enabled the unit tests for deserialize subclasses.
Jacob Carlborg <doob@me.com>
parents:
44
diff
changeset
|
141 void unarchiveBaseClass (string key); |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
142 // void unarchiveNull (string key); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
143 void unarchiveObject (string key, out Id id, out Object result, void delegate () dg); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
144 Id unarchivePointer (string key, void delegate () dg); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
145 Id unarchiveReference (string key); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
146 Slice unarchiveSlice (string key); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
147 void unarchiveStruct (string key, void delegate () dg); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
148 void unarchiveTypedef (string key, void delegate () dg); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
149 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
150 string unarchiveString (string key, out Id id); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
151 wstring unarchiveWstring (string key, out Id id); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
152 dstring unarchiveDstring (string key, out Id id); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
153 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
154 string unarchiveString (Id id); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
155 wstring unarchiveWstring (Id id); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
156 dstring unarchiveDstring (Id id); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
157 bool unarchiveBool (string key); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
158 byte unarchiveByte (string key); |
33
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
29
diff
changeset
|
159 //cdouble unarchiveCdouble (string key); // currently not supported by to!() |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
160 //cent unarchiveCent (string key); // currently not implemented but a reserved keyword |
33
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
29
diff
changeset
|
161 //cfloat unarchiveCfloat (string key); // currently not supported by to!() |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
162 char unarchiveChar (string key); // currently not implemented but a reserved keyword |
33
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
29
diff
changeset
|
163 //creal unarchiveCreal (string key); // currently not supported by to!() |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
164 dchar unarchiveDchar (string key); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
165 double unarchiveDouble (string key); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
166 float unarchiveFloat (string key); |
33
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
29
diff
changeset
|
167 //idouble unarchiveIdouble (string key); // currently not supported by to!() |
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
29
diff
changeset
|
168 //ifloat unarchiveIfloat (string key); // currently not supported by to!()*/ |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
169 int unarchiveInt (string key); |
34
068e853b9c07
Cleaned up. Updated to latest D2 compiler.
Jacob Carlborg <doob@me.com>
parents:
33
diff
changeset
|
170 //int unarchiveInt (Id id); |
33
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
29
diff
changeset
|
171 //ireal unarchiveIreal (string key); // currently not supported by to!() |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
172 long unarchiveLong (string key); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
173 real unarchiveReal (string key); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
174 short unarchiveShort (string key); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
175 ubyte unarchiveUbyte (string key); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
176 //ucent unarchiveCcent (string key); // 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
|
177 uint unarchiveUint (string key); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
178 ulong unarchiveUlong (string key); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
179 ushort unarchiveUshort (string key); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
180 wchar unarchiveWchar (string key); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
181 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
182 void postProcessArray (Id id); |
29
c422ff6477dd
Better handling of serializing pointers.
Jacob Carlborg <doob@me.com>
parents:
28
diff
changeset
|
183 void postProcessPointer (Id id); |
0 | 184 } |
185 | |
28
bffcbc8c392b
Associative arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
26
diff
changeset
|
186 abstract class Base (U) : Archive |
0 | 187 { |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
188 version (Tango) alias U[] Data; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
189 else mixin ("alias immutable(U)[] Data;"); |
0 | 190 |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
191 alias void delegate (ArchiveException exception, string[] data) ErrorCallback; |
18
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
9
diff
changeset
|
192 |
25
b51e953f79eb
Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
24
diff
changeset
|
193 protected ErrorCallback errorCallback; |
b51e953f79eb
Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
24
diff
changeset
|
194 |
b51e953f79eb
Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
24
diff
changeset
|
195 protected this (ErrorCallback errorCallback) |
b51e953f79eb
Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
24
diff
changeset
|
196 { |
b51e953f79eb
Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
24
diff
changeset
|
197 this.errorCallback = errorCallback; |
b51e953f79eb
Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
24
diff
changeset
|
198 } |
18
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
9
diff
changeset
|
199 |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
200 protected Data toData (T) (T value) |
0 | 201 { |
202 try | |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
203 return to!(Data)(value); |
0 | 204 |
205 catch (ConversionException e) | |
206 throw new ArchiveException(e); | |
207 } | |
208 | |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
209 protected T fromData (T) (Data value) |
0 | 210 { |
211 try | |
44
1fef41162966
Fixed deserialization of whcar for D2. Fixed events for D2.
Jacob Carlborg <doob@me.com>
parents:
35
diff
changeset
|
212 { |
1fef41162966
Fixed deserialization of whcar for D2. Fixed events for D2.
Jacob Carlborg <doob@me.com>
parents:
35
diff
changeset
|
213 static if (is(T == wchar)) |
1fef41162966
Fixed deserialization of whcar for D2. Fixed events for D2.
Jacob Carlborg <doob@me.com>
parents:
35
diff
changeset
|
214 return toWchar(value); |
1fef41162966
Fixed deserialization of whcar for D2. Fixed events for D2.
Jacob Carlborg <doob@me.com>
parents:
35
diff
changeset
|
215 |
1fef41162966
Fixed deserialization of whcar for D2. Fixed events for D2.
Jacob Carlborg <doob@me.com>
parents:
35
diff
changeset
|
216 else |
1fef41162966
Fixed deserialization of whcar for D2. Fixed events for D2.
Jacob Carlborg <doob@me.com>
parents:
35
diff
changeset
|
217 return to!(T)(value); |
1fef41162966
Fixed deserialization of whcar for D2. Fixed events for D2.
Jacob Carlborg <doob@me.com>
parents:
35
diff
changeset
|
218 } |
1fef41162966
Fixed deserialization of whcar for D2. Fixed events for D2.
Jacob Carlborg <doob@me.com>
parents:
35
diff
changeset
|
219 |
0 | 220 catch (ConversionException e) |
221 throw new ArchiveException(e); | |
20
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
222 } |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
223 |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
224 protected Id toId (Data value) |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
225 { |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
226 return fromData!(Id)(value); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
227 } |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
228 |
20
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
229 protected bool isSliceOf (T, U = T) (T[] a, U[] b) |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
230 { |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
231 void* aPtr = a.ptr; |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
232 void* bPtr = b.ptr; |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
233 |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
234 return aPtr >= bPtr && aPtr + a.length * T.sizeof <= bPtr + b.length * U.sizeof; |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
235 } |
44
1fef41162966
Fixed deserialization of whcar for D2. Fixed events for D2.
Jacob Carlborg <doob@me.com>
parents:
35
diff
changeset
|
236 |
1fef41162966
Fixed deserialization of whcar for D2. Fixed events for D2.
Jacob Carlborg <doob@me.com>
parents:
35
diff
changeset
|
237 private wchar toWchar (Data value) |
1fef41162966
Fixed deserialization of whcar for D2. Fixed events for D2.
Jacob Carlborg <doob@me.com>
parents:
35
diff
changeset
|
238 { |
1fef41162966
Fixed deserialization of whcar for D2. Fixed events for D2.
Jacob Carlborg <doob@me.com>
parents:
35
diff
changeset
|
239 version (Tango) |
1fef41162966
Fixed deserialization of whcar for D2. Fixed events for D2.
Jacob Carlborg <doob@me.com>
parents:
35
diff
changeset
|
240 return to!(wchar)(value); |
1fef41162966
Fixed deserialization of whcar for D2. Fixed events for D2.
Jacob Carlborg <doob@me.com>
parents:
35
diff
changeset
|
241 |
1fef41162966
Fixed deserialization of whcar for D2. Fixed events for D2.
Jacob Carlborg <doob@me.com>
parents:
35
diff
changeset
|
242 else |
1fef41162966
Fixed deserialization of whcar for D2. Fixed events for D2.
Jacob Carlborg <doob@me.com>
parents:
35
diff
changeset
|
243 { |
1fef41162966
Fixed deserialization of whcar for D2. Fixed events for D2.
Jacob Carlborg <doob@me.com>
parents:
35
diff
changeset
|
244 auto c = value.front; |
1fef41162966
Fixed deserialization of whcar for D2. Fixed events for D2.
Jacob Carlborg <doob@me.com>
parents:
35
diff
changeset
|
245 |
1fef41162966
Fixed deserialization of whcar for D2. Fixed events for D2.
Jacob Carlborg <doob@me.com>
parents:
35
diff
changeset
|
246 if (codeLength!(wchar)(c) > 2) |
1fef41162966
Fixed deserialization of whcar for D2. Fixed events for D2.
Jacob Carlborg <doob@me.com>
parents:
35
diff
changeset
|
247 throw new ConversionException("Could not convert `" ~ |
1fef41162966
Fixed deserialization of whcar for D2. Fixed events for D2.
Jacob Carlborg <doob@me.com>
parents:
35
diff
changeset
|
248 to!(string)(value) ~ "` of type " ~ |
1fef41162966
Fixed deserialization of whcar for D2. Fixed events for D2.
Jacob Carlborg <doob@me.com>
parents:
35
diff
changeset
|
249 Data.stringof ~ " to type wchar."); |
1fef41162966
Fixed deserialization of whcar for D2. Fixed events for D2.
Jacob Carlborg <doob@me.com>
parents:
35
diff
changeset
|
250 |
1fef41162966
Fixed deserialization of whcar for D2. Fixed events for D2.
Jacob Carlborg <doob@me.com>
parents:
35
diff
changeset
|
251 return cast(wchar) c; |
1fef41162966
Fixed deserialization of whcar for D2. Fixed events for D2.
Jacob Carlborg <doob@me.com>
parents:
35
diff
changeset
|
252 } |
1fef41162966
Fixed deserialization of whcar for D2. Fixed events for D2.
Jacob Carlborg <doob@me.com>
parents:
35
diff
changeset
|
253 } |
0 | 254 } |