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
|
|
12 import orange.serialization.archives.ArchiveException;
|
|
13
|
|
14 interface IArchive
|
|
15 {
|
|
16 void beginArchiving ();
|
|
17 void reset ();
|
|
18 }
|
|
19
|
|
20 abstract class Archive (U) : IArchive
|
|
21 {
|
|
22 alias U[] DataType;
|
|
23
|
|
24 abstract void beginArchiving ();
|
|
25 abstract void beginUnarchiving (DataType data);
|
|
26 abstract DataType data ();
|
|
27 abstract void reset ();
|
|
28
|
|
29 protected DataType toDataType (T) (T value)
|
|
30 {
|
|
31 try
|
|
32 return to!(DataType)(value);
|
|
33
|
|
34 catch (ConversionException e)
|
|
35 throw new ArchiveException(e);
|
|
36 }
|
|
37
|
|
38 protected T fromDataType (T) (DataType value)
|
|
39 {
|
|
40 try
|
|
41 return to!(T)(value);
|
|
42
|
|
43 catch (ConversionException e)
|
|
44 throw new ArchiveException(e);
|
|
45 }
|
|
46 } |