Mercurial > projects > orange
annotate orange/serialization/RegisterWrapper.d @ 4:470ab5270d0c
Simplified the implementation of RegisterWrapper. Fixed: the base class of an object was not serialized
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Mon, 31 May 2010 19:20:14 +0200 |
parents | f7b078e85f7f |
children | 9f6064f9505a |
rev | line source |
---|---|
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; | |
4
470ab5270d0c
Simplified the implementation of RegisterWrapper. Fixed: the base class of an object was not serialized
Jacob Carlborg <doob@me.com>
parents:
0
diff
changeset
|
22 private bool isDelegate; |
0 | 23 |
24 this (void delegate (T, SerializerType, DataType) dg) | |
25 { | |
4
470ab5270d0c
Simplified the implementation of RegisterWrapper. Fixed: the base class of an object was not serialized
Jacob Carlborg <doob@me.com>
parents:
0
diff
changeset
|
26 isDelegate = true; |
0 | 27 this.dg = dg; |
28 } | |
29 | |
30 this (void function (T, SerializerType, DataType) func) | |
31 { | |
4
470ab5270d0c
Simplified the implementation of RegisterWrapper. Fixed: the base class of an object was not serialized
Jacob Carlborg <doob@me.com>
parents:
0
diff
changeset
|
32 dg.funcptr = func; |
0 | 33 } |
34 | |
35 void opCall (T value, SerializerType archive, DataType key) | |
36 { | |
4
470ab5270d0c
Simplified the implementation of RegisterWrapper. Fixed: the base class of an object was not serialized
Jacob Carlborg <doob@me.com>
parents:
0
diff
changeset
|
37 if (dg && isDelegate) |
0 | 38 dg(value, archive, key); |
39 | |
4
470ab5270d0c
Simplified the implementation of RegisterWrapper. Fixed: the base class of an object was not serialized
Jacob Carlborg <doob@me.com>
parents:
0
diff
changeset
|
40 else if (dg) |
470ab5270d0c
Simplified the implementation of RegisterWrapper. Fixed: the base class of an object was not serialized
Jacob Carlborg <doob@me.com>
parents:
0
diff
changeset
|
41 dg.funcptr(value, archive, key); |
0 | 42 } |
43 } | |
44 | |
45 class DeserializeRegisterWrapper (T, ArchiveType : IArchive) : RegisterBase | |
46 { | |
47 private alias Serializer!(ArchiveType) SerializerType; | |
48 private alias SerializerType.DataType DataType; | |
49 private void delegate (ref T, SerializerType, DataType) dg; | |
4
470ab5270d0c
Simplified the implementation of RegisterWrapper. Fixed: the base class of an object was not serialized
Jacob Carlborg <doob@me.com>
parents:
0
diff
changeset
|
50 private bool isDelegate; |
0 | 51 |
52 this (void delegate (ref T, SerializerType, DataType) dg) | |
53 { | |
4
470ab5270d0c
Simplified the implementation of RegisterWrapper. Fixed: the base class of an object was not serialized
Jacob Carlborg <doob@me.com>
parents:
0
diff
changeset
|
54 isDelegate = true; |
0 | 55 this.dg = dg; |
56 } | |
57 | |
58 this (void function (ref T, SerializerType, DataType) func) | |
59 { | |
4
470ab5270d0c
Simplified the implementation of RegisterWrapper. Fixed: the base class of an object was not serialized
Jacob Carlborg <doob@me.com>
parents:
0
diff
changeset
|
60 dg.funcptr = func; |
0 | 61 } |
62 | |
63 void opCall (ref T value, SerializerType archive, DataType key) | |
64 { | |
4
470ab5270d0c
Simplified the implementation of RegisterWrapper. Fixed: the base class of an object was not serialized
Jacob Carlborg <doob@me.com>
parents:
0
diff
changeset
|
65 if (dg && isDelegate) |
0 | 66 dg(value, archive, key); |
67 | |
4
470ab5270d0c
Simplified the implementation of RegisterWrapper. Fixed: the base class of an object was not serialized
Jacob Carlborg <doob@me.com>
parents:
0
diff
changeset
|
68 if (dg) |
470ab5270d0c
Simplified the implementation of RegisterWrapper. Fixed: the base class of an object was not serialized
Jacob Carlborg <doob@me.com>
parents:
0
diff
changeset
|
69 dg.funcptr(value, archive, key); |
0 | 70 } |
71 } |