Mercurial > projects > orange
comparison orange/serialization/RegisterWrapper.d @ 26:78e5fef4bbf2 experimental
Third step in refactoring the API. Stating to add unit tests.
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Tue, 19 Oct 2010 10:22:10 +0200 |
parents | 9f6064f9505a |
children |
comparison
equal
deleted
inserted
replaced
25:b51e953f79eb | 26:78e5fef4bbf2 |
---|---|
4 * Version: Initial created: Feb 4, 2010 | 4 * Version: Initial created: Feb 4, 2010 |
5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0) | 5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0) |
6 */ | 6 */ |
7 module orange.serialization.RegisterWrapper; | 7 module orange.serialization.RegisterWrapper; |
8 | 8 |
9 import orange.serialization.archives.Archive; | 9 //import orange.serialization.archives.Archive; |
10 import orange.serialization.Serializer; | 10 //import orange.serialization.Serializer; |
11 import orange.core.string; | |
11 | 12 |
12 class RegisterBase | 13 class RegisterBase |
13 { | 14 { |
14 | 15 |
15 } | 16 } |
16 | 17 |
17 class SerializeRegisterWrapper (T, SerializerType) : RegisterBase | 18 class SerializeRegisterWrapper (T, SerializerType) : RegisterBase |
18 { | 19 { |
19 private alias SerializerType.DataType DataType; | 20 private void delegate (T, SerializerType, string) dg; |
20 private void delegate (T, SerializerType, DataType) dg; | |
21 private bool isDelegate; | 21 private bool isDelegate; |
22 | 22 |
23 this (void delegate (T, SerializerType, DataType) dg) | 23 this (void delegate (T, SerializerType, string) dg) |
24 { | 24 { |
25 isDelegate = true; | 25 isDelegate = true; |
26 this.dg = dg; | 26 this.dg = dg; |
27 } | 27 } |
28 | 28 |
29 this (void function (T, SerializerType, DataType) func) | 29 this (void function (T, SerializerType, string) func) |
30 { | 30 { |
31 dg.funcptr = func; | 31 dg.funcptr = func; |
32 } | 32 } |
33 | 33 |
34 void opCall (T value, SerializerType archive, DataType key) | 34 void opCall (T value, SerializerType archive, string key) |
35 { | 35 { |
36 if (dg && isDelegate) | 36 if (dg && isDelegate) |
37 dg(value, archive, key); | 37 dg(value, archive, key); |
38 | 38 |
39 else if (dg) | 39 else if (dg) |
41 } | 41 } |
42 } | 42 } |
43 | 43 |
44 class DeserializeRegisterWrapper (T, SerializerType) : RegisterBase | 44 class DeserializeRegisterWrapper (T, SerializerType) : RegisterBase |
45 { | 45 { |
46 private alias SerializerType.DataType DataType; | 46 private void delegate (ref T, SerializerType, string) dg; |
47 private void delegate (ref T, SerializerType, DataType) dg; | |
48 private bool isDelegate; | 47 private bool isDelegate; |
49 | 48 |
50 this (void delegate (ref T, SerializerType, DataType) dg) | 49 this (void delegate (ref T, SerializerType, string) dg) |
51 { | 50 { |
52 isDelegate = true; | 51 isDelegate = true; |
53 this.dg = dg; | 52 this.dg = dg; |
54 } | 53 } |
55 | 54 |
56 this (void function (ref T, SerializerType, DataType) func) | 55 this (void function (ref T, SerializerType, string) func) |
57 { | 56 { |
58 dg.funcptr = func; | 57 dg.funcptr = func; |
59 } | 58 } |
60 | 59 |
61 void opCall (ref T value, SerializerType archive, DataType key) | 60 void opCall (ref T value, SerializerType archive, string key) |
62 { | 61 { |
63 if (dg && isDelegate) | 62 if (dg && isDelegate) |
64 dg(value, archive, key); | 63 dg(value, archive, key); |
65 | 64 |
66 if (dg) | 65 if (dg) |