Mercurial > projects > orange
annotate orange/serialization/archives/Archive.d @ 18:3d42ea434d46
Added an error callback. Fixes #3 and #4.
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Thu, 12 Aug 2010 23:24:51 +0200 |
parents | 99c52d46822a |
children | 9a575087b961 |
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 |
18
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
9
diff
changeset
|
31 alias void delegate (ArchiveException exception, DataType[] data) ErrorCallback; |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
9
diff
changeset
|
32 |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
9
diff
changeset
|
33 ErrorCallback errorCallback; |
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
9
diff
changeset
|
34 |
0 | 35 abstract void beginArchiving (); |
36 abstract void beginUnarchiving (DataType data); | |
37 abstract DataType data (); | |
38 abstract void reset (); | |
39 | |
40 protected DataType toDataType (T) (T value) | |
41 { | |
42 try | |
43 return to!(DataType)(value); | |
44 | |
45 catch (ConversionException e) | |
46 throw new ArchiveException(e); | |
47 } | |
48 | |
49 protected T fromDataType (T) (DataType value) | |
50 { | |
51 try | |
52 return to!(T)(value); | |
53 | |
54 catch (ConversionException e) | |
55 throw new ArchiveException(e); | |
18
3d42ea434d46
Added an error callback. Fixes #3 and #4.
Jacob Carlborg <doob@me.com>
parents:
9
diff
changeset
|
56 } |
0 | 57 } |