Mercurial > projects > orange
view 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 |
line wrap: on
line source
/** * 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 bool isDelegate; this (void delegate (T, SerializerType, DataType) dg) { isDelegate = true; this.dg = dg; } this (void function (T, SerializerType, DataType) func) { dg.funcptr = func; } void opCall (T value, SerializerType archive, DataType key) { if (dg && isDelegate) dg(value, archive, key); else if (dg) dg.funcptr(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 bool isDelegate; this (void delegate (ref T, SerializerType, DataType) dg) { isDelegate = true; this.dg = dg; } this (void function (ref T, SerializerType, DataType) func) { dg.funcptr = func; } void opCall (ref T value, SerializerType archive, DataType key) { if (dg && isDelegate) dg(value, archive, key); if (dg) dg.funcptr(value, archive, key); } }