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