Mercurial > projects > orange
diff orange/serialization/RegisterWrapper.d @ 0:f7b078e85f7f
First commit
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Wed, 26 May 2010 17:19:13 +0200 |
parents | |
children | 470ab5270d0c |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/orange/serialization/RegisterWrapper.d Wed May 26 17:19:13 2010 +0200 @@ -0,0 +1,69 @@ +/** + * Copyright: Copyright (c) 2010 Jacob Carlborg. + * Authors: Jacob Carlborg + * Version: Initial created: Feb 4, 2010 + * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0) + */ +module orange.serialization.RegisterWrapper; + +import orange.serialization.archives.Archive; +import orange.serialization.Serializer; + +class RegisterBase +{ + +} + +class SerializeRegisterWrapper (T, ArchiveType : IArchive) : RegisterBase +{ + private alias Serializer!(ArchiveType) SerializerType; + private alias SerializerType.DataType DataType; + private void delegate (T, SerializerType, DataType) dg; + private void function (T, SerializerType, DataType) func; + + this (void delegate (T, SerializerType, DataType) dg) + { + this.dg = dg; + } + + this (void function (T, SerializerType, DataType) func) + { + this.func = func; + } + + void opCall (T value, SerializerType archive, DataType key) + { + if (dg) + dg(value, archive, key); + + else if (func) + func(value, archive, key); + } +} + +class DeserializeRegisterWrapper (T, ArchiveType : IArchive) : RegisterBase +{ + private alias Serializer!(ArchiveType) SerializerType; + private alias SerializerType.DataType DataType; + private void delegate (ref T, SerializerType, DataType) dg; + private void function (ref T, SerializerType, DataType) func; + + this (void delegate (ref T, SerializerType, DataType) dg) + { + this.dg = dg; + } + + this (void function (ref T, SerializerType, DataType) func) + { + this.func = func; + } + + void opCall (ref T value, SerializerType archive, DataType key) + { + if (dg) + dg(value, archive, key); + + if (func) + func(value, archive, key); + } +} \ No newline at end of file