Mercurial > projects > orange
annotate orange/serialization/archives/Archive.d @ 28:bffcbc8c392b experimental
Associative arrays are now treated as references.
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Fri, 19 Nov 2010 11:55:04 +0100 |
parents | 78e5fef4bbf2 |
children | c422ff6477dd |
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); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
82 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
|
83 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
|
84 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
|
85 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
|
86 |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
87 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
|
88 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
|
89 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
|
90 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
|
91 void archive (byte 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 (cdouble value, string key, Id id); // currently not suppported by to!() |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
93 //void archive (cent 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 (cfloat value, string key, Id id); // currently not suppported by to!() |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
95 void archive (char 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
|
96 //void archive (creal value, string key, Id id); // currently not suppported by to!() |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
97 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
|
98 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
|
99 void archive (float 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 (idouble value, string key, Id id); // currently not suppported by to!() |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
101 //void archive (ifloat value, string key, Id id); // currently not suppported by to!() |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
102 void archive (int 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 (ireal value, string key, Id id); // currently not suppported by to!() |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
104 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
|
105 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
|
106 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
|
107 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
|
108 //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
|
109 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
|
110 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
|
111 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
|
112 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
|
113 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
114 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
|
115 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
|
116 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
|
117 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
|
118 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
|
119 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
120 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
|
121 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
|
122 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
|
123 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
|
124 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
|
125 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
|
126 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
|
127 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
|
128 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
|
129 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
|
130 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
|
131 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
|
132 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
133 // 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
|
134 // 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
|
135 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
|
136 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
|
137 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
|
138 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
|
139 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
|
140 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
|
141 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
142 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
|
143 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
|
144 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
|
145 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
146 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
|
147 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
|
148 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
|
149 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
|
150 byte unarchiveByte (string key); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
151 //cdouble unarchiveCdouble (string key); // currently not suppported by to!() |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
152 //cent unarchiveCent (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
|
153 //cfloat unarchiveCfloat (string key); // currently not suppported by to!() |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
154 char unarchiveChar (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
|
155 //creal unarchiveCreal (string key); // currently not suppported by to!() |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
156 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
|
157 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
|
158 float unarchiveFloat (string key); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
159 //idouble unarchiveIdouble (string key); // currently not suppported by to!() |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
160 //ifloat unarchiveIfloat (string key); // currently not suppported by to!()*/ |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
161 int unarchiveInt (string key); |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
162 //ireal unarchiveIreal (string key); // currently not suppported by to!() |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
163 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
|
164 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
|
165 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
|
166 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
|
167 //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
|
168 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
|
169 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
|
170 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
|
171 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
|
172 |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
173 void postProcessArray (Id id); |
0 | 174 } |
175 | |
28
bffcbc8c392b
Associative arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
26
diff
changeset
|
176 abstract class Base (U) : Archive |
0 | 177 { |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
178 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
|
179 else mixin ("alias immutable(U)[] Data;"); |
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 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
|
182 |
25
b51e953f79eb
Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
24
diff
changeset
|
183 protected ErrorCallback errorCallback; |
b51e953f79eb
Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
24
diff
changeset
|
184 |
b51e953f79eb
Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
24
diff
changeset
|
185 protected this (ErrorCallback errorCallback) |
b51e953f79eb
Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
24
diff
changeset
|
186 { |
b51e953f79eb
Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
24
diff
changeset
|
187 this.errorCallback = errorCallback; |
b51e953f79eb
Second step in refactoring the API.
Jacob Carlborg <doob@me.com>
parents:
24
diff
changeset
|
188 } |
18
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
9
diff
changeset
|
189 |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
190 protected Data toData (T) (T value) |
0 | 191 { |
192 try | |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
193 return to!(Data)(value); |
0 | 194 |
195 catch (ConversionException e) | |
196 throw new ArchiveException(e); | |
197 } | |
198 | |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
199 protected T fromData (T) (Data value) |
0 | 200 { |
201 try | |
202 return to!(T)(value); | |
203 | |
204 catch (ConversionException e) | |
205 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
|
206 } |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
207 |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
208 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
|
209 { |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
210 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
|
211 } |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
25
diff
changeset
|
212 |
20
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
213 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
|
214 { |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
215 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
|
216 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
|
217 |
9a575087b961
Added support for slices. Strings and arrays are now treated as references.
Jacob Carlborg <doob@me.com>
parents:
18
diff
changeset
|
218 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
|
219 } |
0 | 220 } |