Mercurial > projects > orange
diff orange/serialization/Serializer.d @ 18:3d42ea434d46
Added an error callback. Fixes #3 and #4.
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Thu, 12 Aug 2010 23:24:51 +0200 |
parents | c4e7e64ffb67 |
children | 9a575087b961 |
line wrap: on
line diff
--- a/orange/serialization/Serializer.d Sun Aug 08 21:59:59 2010 +0200 +++ b/orange/serialization/Serializer.d Thu Aug 12 23:24:51 2010 +0200 @@ -37,10 +37,12 @@ { static assert(isArchive!(ArchiveType), format!(`The type "`, ArchiveType, `" does not implement the necessary methods to be an archive.`)); + alias ArchiveType.ErrorCallback ErrorCallback; + alias ArchiveType.DataType DataType; + private { ArchiveType archive; - alias ArchiveType.DataType DataType; RegisterBase[string] serializers; RegisterBase[string] deserializers; @@ -49,11 +51,19 @@ bool hasBegunSerializing; bool hasBegunDeserializing; + + void delegate (ArchiveException exception, DataType[] data) throwOnErrorCallback; + void delegate (ArchiveException exception, DataType[] data) doNothingOnErrorCallback; } this () { archive = new ArchiveType; + + throwOnErrorCallback = (ArchiveException exception, DataType[] data) { throw exception; }; + doNothingOnErrorCallback = (ArchiveException exception, DataType[] data) { /* do nothing */ }; + + setThrowOnErrorCallback(); } void registerSerializer (T) (string type, void delegate (T, Serializer, DataType) dg) @@ -85,6 +95,26 @@ archive.reset; } + ErrorCallback errorCallback () + { + return archive.errorCallback; + } + + ErrorCallback errorCallback (ErrorCallback errorCallback) + { + return archive.errorCallback = errorCallback; + } + + void setThrowOnErrorCallback () + { + errorCallback = throwOnErrorCallback; + } + + void setDoNothingOnErrorCallback () + { + errorCallback = doNothingOnErrorCallback; + } + DataType serialize (T) (T value, DataType key = null) { if (!hasBegunSerializing)