0
|
1 /**
|
|
2 * Copyright: Copyright (c) 2010 Jacob Carlborg.
|
|
3 * Authors: Jacob Carlborg
|
|
4 * Version: Initial created: Feb 4, 2010
|
|
5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0)
|
|
6 */
|
|
7 module orange.serialization.RegisterWrapper;
|
|
8
|
|
9 import orange.serialization.archives.Archive;
|
|
10 import orange.serialization.Serializer;
|
|
11
|
|
12 class RegisterBase
|
|
13 {
|
|
14
|
|
15 }
|
|
16
|
|
17 class SerializeRegisterWrapper (T, ArchiveType : IArchive) : RegisterBase
|
|
18 {
|
|
19 private alias Serializer!(ArchiveType) SerializerType;
|
|
20 private alias SerializerType.DataType DataType;
|
|
21 private void delegate (T, SerializerType, DataType) dg;
|
|
22 private void function (T, SerializerType, DataType) func;
|
|
23
|
|
24 this (void delegate (T, SerializerType, DataType) dg)
|
|
25 {
|
|
26 this.dg = dg;
|
|
27 }
|
|
28
|
|
29 this (void function (T, SerializerType, DataType) func)
|
|
30 {
|
|
31 this.func = func;
|
|
32 }
|
|
33
|
|
34 void opCall (T value, SerializerType archive, DataType key)
|
|
35 {
|
|
36 if (dg)
|
|
37 dg(value, archive, key);
|
|
38
|
|
39 else if (func)
|
|
40 func(value, archive, key);
|
|
41 }
|
|
42 }
|
|
43
|
|
44 class DeserializeRegisterWrapper (T, ArchiveType : IArchive) : RegisterBase
|
|
45 {
|
|
46 private alias Serializer!(ArchiveType) SerializerType;
|
|
47 private alias SerializerType.DataType DataType;
|
|
48 private void delegate (ref T, SerializerType, DataType) dg;
|
|
49 private void function (ref T, SerializerType, DataType) func;
|
|
50
|
|
51 this (void delegate (ref T, SerializerType, DataType) dg)
|
|
52 {
|
|
53 this.dg = dg;
|
|
54 }
|
|
55
|
|
56 this (void function (ref T, SerializerType, DataType) func)
|
|
57 {
|
|
58 this.func = func;
|
|
59 }
|
|
60
|
|
61 void opCall (ref T value, SerializerType archive, DataType key)
|
|
62 {
|
|
63 if (dg)
|
|
64 dg(value, archive, key);
|
|
65
|
|
66 if (func)
|
|
67 func(value, archive, key);
|
|
68 }
|
|
69 } |