Mercurial > projects > orange
annotate orange/serialization/archives/Archive.d @ 35:511d1ef4e299 experimental
Now all unit tests pass on latest DMD2 compiler.
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Wed, 03 Aug 2011 21:44:11 +0200 |
parents | 068e853b9c07 |
children | 1fef41162966 |
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 { |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
0
diff
changeset
|
14 import std.conv; |
34
068e853b9c07
Cleaned up. Updated to latest D2 compiler.
Jacob Carlborg <doob@me.com>
parents:
33
diff
changeset
|
15 alias ConvException ConversionException; |
9
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
0
diff
changeset
|
16 } |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
0
diff
changeset
|
17 |
0 | 18 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
|
19 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
|
20 |
25
b51e953f79eb
Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
24
diff
changeset
|
21 private enum ArchiveMode |
b51e953f79eb
Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
24
diff
changeset
|
22 { |
b51e953f79eb
Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
24
diff
changeset
|
23 archiving, |
b51e953f79eb
Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
24
diff
changeset
|
24 unarchiving |
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 |
24
55f0a9d5df8d
First step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
27 struct Array |
55f0a9d5df8d
First step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
28 { |
35
511d1ef4e299
Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents:
34
diff
changeset
|
29 version (Tango) |
511d1ef4e299
Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents:
34
diff
changeset
|
30 void* ptr; |
511d1ef4e299
Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents:
34
diff
changeset
|
31 |
511d1ef4e299
Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents:
34
diff
changeset
|
32 else |
511d1ef4e299
Now all unit tests pass on latest DMD2 compiler.
Jacob Carlborg <doob@me.com>
parents:
34
diff
changeset
|
33 mixin(`const(void)* ptr;`); |
34
068e853b9c07
Cleaned up. Updated to latest D2 compiler.
Jacob Carlborg <doob@me.com>
parents:
33
diff
changeset
|
34 |
24
55f0a9d5df8d
First step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
35 size_t length; |
55f0a9d5df8d
First step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
36 size_t elementSize; |
55f0a9d5df8d
First step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
37 |
55f0a9d5df8d
First step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
38 bool isSliceOf (Array b) |
55f0a9d5df8d
First step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
39 { |
55f0a9d5df8d
First step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
40 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
|
41 } |
55f0a9d5df8d
First step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
42 } |
0 | 43 |
20
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
44 struct Slice |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
45 { |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
46 size_t length; |
24
55f0a9d5df8d
First step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
47 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
|
48 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
|
49 } |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
50 |
28
bffcbc8c392b
Associative arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
26
diff
changeset
|
51 interface Archive |
0 | 52 { |
34
068e853b9c07
Cleaned up. Updated to latest D2 compiler.
Jacob Carlborg <doob@me.com>
parents:
33
diff
changeset
|
53 alias size_t Id; |
068e853b9c07
Cleaned up. Updated to latest D2 compiler.
Jacob Carlborg <doob@me.com>
parents:
33
diff
changeset
|
54 |
068e853b9c07
Cleaned up. Updated to latest D2 compiler.
Jacob Carlborg <doob@me.com>
parents:
33
diff
changeset
|
55 version (Tango) alias void[] UntypedData; |
068e853b9c07
Cleaned up. Updated to latest D2 compiler.
Jacob Carlborg <doob@me.com>
parents:
33
diff
changeset
|
56 else mixin ("alias immutable(void)[] UntypedData;"); |
24
55f0a9d5df8d
First step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
57 |
0 | 58 void beginArchiving (); |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
59 void beginUnarchiving (UntypedData data); |
24
55f0a9d5df8d
First step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
60 |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
61 UntypedData untypedData (); |
0 | 62 void reset (); |
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 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
|
65 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
|
66 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
|
67 void archiveAssociativeArrayValue (string key, void delegate () dg); |
24
55f0a9d5df8d
First step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
20
diff
changeset
|
68 |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
69 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
|
70 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
|
71 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
|
72 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
|
73 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
|
74 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
|
75 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
|
76 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
|
77 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
|
78 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
|
79 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
|
80 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
|
81 |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
82 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
|
83 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
|
84 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
|
85 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
|
86 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
|
87 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
|
88 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
|
89 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
|
90 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
|
91 |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
92 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
|
93 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
|
94 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
|
95 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
|
96 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
|
97 //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
|
98 //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
|
99 //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
|
100 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
|
101 //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
|
102 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
|
103 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
|
104 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
|
105 //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
|
106 //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
|
107 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
|
108 //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
|
109 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
|
110 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
|
111 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
|
112 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
|
113 //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
|
114 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
|
115 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
|
116 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
|
117 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
|
118 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
119 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
|
120 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
|
121 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
|
122 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
|
123 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
|
124 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
125 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
|
126 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
|
127 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
|
128 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
|
129 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
|
130 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
|
131 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
|
132 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
|
133 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
|
134 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
|
135 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
|
136 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
|
137 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
138 // Object unarchiveBaseClass (string key); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
139 // 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
|
140 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
|
141 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
|
142 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
|
143 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
|
144 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
|
145 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
|
146 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
147 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
|
148 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
|
149 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
|
150 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
151 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
|
152 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
|
153 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
|
154 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
|
155 byte unarchiveByte (string key); |
33
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
29
diff
changeset
|
156 //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
|
157 //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
|
158 //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
|
159 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
|
160 //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
|
161 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
|
162 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
|
163 float unarchiveFloat (string key); |
33
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
29
diff
changeset
|
164 //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
|
165 //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
|
166 int unarchiveInt (string key); |
34
068e853b9c07
Cleaned up. Updated to latest D2 compiler.
Jacob Carlborg <doob@me.com>
parents:
33
diff
changeset
|
167 //int unarchiveInt (Id id); |
33
4fea56a5849f
Now both internal and external pointers work.
Jacob Carlborg <doob@me.com>
parents:
29
diff
changeset
|
168 //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
|
169 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
|
170 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
|
171 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
|
172 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
|
173 //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
|
174 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
|
175 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
|
176 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
|
177 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
|
178 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
179 void postProcessArray (Id id); |
29
c422ff6477dd
Better handling of serializing pointers.
Jacob Carlborg <doob@me.com>
parents:
28
diff
changeset
|
180 void postProcessPointer (Id id); |
0 | 181 } |
182 | |
28
bffcbc8c392b
Associative arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
26
diff
changeset
|
183 abstract class Base (U) : Archive |
0 | 184 { |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
185 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
|
186 else mixin ("alias immutable(U)[] Data;"); |
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 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
|
189 |
25
b51e953f79eb
Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
24
diff
changeset
|
190 protected ErrorCallback errorCallback; |
b51e953f79eb
Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
24
diff
changeset
|
191 |
b51e953f79eb
Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
24
diff
changeset
|
192 protected this (ErrorCallback errorCallback) |
b51e953f79eb
Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
24
diff
changeset
|
193 { |
b51e953f79eb
Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
24
diff
changeset
|
194 this.errorCallback = errorCallback; |
b51e953f79eb
Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
24
diff
changeset
|
195 } |
18
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
9
diff
changeset
|
196 |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
197 protected Data toData (T) (T value) |
0 | 198 { |
199 try | |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
200 return to!(Data)(value); |
0 | 201 |
202 catch (ConversionException e) | |
203 throw new ArchiveException(e); | |
204 } | |
205 | |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
206 protected T fromData (T) (Data value) |
0 | 207 { |
208 try | |
209 return to!(T)(value); | |
210 | |
211 catch (ConversionException e) | |
212 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
|
213 } |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
214 |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
215 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
|
216 { |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
217 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
|
218 } |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
219 |
20
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
220 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
|
221 { |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
222 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
|
223 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
|
224 |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
225 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
|
226 } |
0 | 227 } |