Mercurial > projects > orange
annotate orange/serialization/archives/Archive.d @ 9:99c52d46822a
Serialization works now with D2, deserialization still doesn't work
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Sat, 24 Jul 2010 18:58:18 +0200 |
parents | f7b078e85f7f |
children | 3d42ea434d46 |
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; |
19 | |
20 interface IArchive | |
21 { | |
22 void beginArchiving (); | |
23 void reset (); | |
24 } | |
25 | |
26 abstract class Archive (U) : IArchive | |
27 { | |
9
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
0
diff
changeset
|
28 version (Tango) alias U[] DataType; |
99c52d46822a
Serialization works now with D2, deserialization still doesn't work
Jacob Carlborg <doob@me.com>
parents:
0
diff
changeset
|
29 else mixin ("alias immutable(U)[] DataType;"); |
0 | 30 |
31 abstract void beginArchiving (); | |
32 abstract void beginUnarchiving (DataType data); | |
33 abstract DataType data (); | |
34 abstract void reset (); | |
35 | |
36 protected DataType toDataType (T) (T value) | |
37 { | |
38 try | |
39 return to!(DataType)(value); | |
40 | |
41 catch (ConversionException e) | |
42 throw new ArchiveException(e); | |
43 } | |
44 | |
45 protected T fromDataType (T) (DataType value) | |
46 { | |
47 try | |
48 return to!(T)(value); | |
49 | |
50 catch (ConversionException e) | |
51 throw new ArchiveException(e); | |
52 } | |
53 } |