Mercurial > projects > orange
annotate 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 |
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 | |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
9 //import orange.serialization.archives.Archive; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
10 //import orange.serialization.Serializer; |
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
11 import orange.core.string; |
0 | 12 |
13 class RegisterBase | |
14 { | |
15 | |
16 } | |
17 | |
15
9f6064f9505a
Changed from archive to serializer in the register wrappers.
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
18 class SerializeRegisterWrapper (T, SerializerType) : RegisterBase |
0 | 19 { |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
20 private void delegate (T, SerializerType, string) 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
|
21 private bool isDelegate; |
0 | 22 |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
23 this (void delegate (T, SerializerType, string) dg) |
0 | 24 { |
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
|
25 isDelegate = true; |
0 | 26 this.dg = dg; |
27 } | |
28 | |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
29 this (void function (T, SerializerType, string) func) |
0 | 30 { |
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
|
31 dg.funcptr = func; |
0 | 32 } |
33 | |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
34 void opCall (T value, SerializerType archive, string key) |
0 | 35 { |
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
|
36 if (dg && isDelegate) |
0 | 37 dg(value, archive, key); |
38 | |
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
|
39 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
|
40 dg.funcptr(value, archive, key); |
0 | 41 } |
42 } | |
43 | |
15
9f6064f9505a
Changed from archive to serializer in the register wrappers.
Jacob Carlborg <doob@me.com>
parents:
4
diff
changeset
|
44 class DeserializeRegisterWrapper (T, SerializerType) : RegisterBase |
0 | 45 { |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
46 private void delegate (ref T, SerializerType, string) 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
|
47 private bool isDelegate; |
0 | 48 |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
49 this (void delegate (ref T, SerializerType, string) dg) |
0 | 50 { |
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
|
51 isDelegate = true; |
0 | 52 this.dg = dg; |
53 } | |
54 | |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
55 this (void function (ref T, SerializerType, string) func) |
0 | 56 { |
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
|
57 dg.funcptr = func; |
0 | 58 } |
59 | |
26
78e5fef4bbf2
Third step in refactoring the API. Stating to add unit tests.
Jacob Carlborg <doob@me.com>
parents:
15
diff
changeset
|
60 void opCall (ref T value, SerializerType archive, string key) |
0 | 61 { |
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
|
62 if (dg && isDelegate) |
0 | 63 dg(value, archive, 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) |
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
|
66 dg.funcptr(value, archive, key); |
0 | 67 } |
68 } |