1 /** 2 * Copyright: Copyright (c) 2010-2011 Jacob Carlborg. 3 * Authors: Jacob Carlborg 4 * Version: Initial created: Jan 26, 2010 5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0) 6 */ 7 module orange.serialization.Events; 8 9 import orange.core.Attribute; 10 import orange.util._; 11 12 /** 13 * This event is triggered after the struct/class, this template has been mixed into, 14 * has been completely deserialized, including all the fields. 15 * 16 * Params: 17 * method = the method to be invoked when the event is triggered 18 */ 19 template OnDeserialized (alias method) 20 { 21 static orange.serialization.Events.Event!(method) __onDeserialized; 22 } 23 24 /** 25 * Methods with this attribute attached will be called after the struct/class has been 26 * deserialized. 27 */ 28 @attribute struct onDeserialized { } 29 30 /** 31 * This event is triggered after the struct/class, this template has been mixed into, 32 * has been deserialized, but before any fields have been deserialized. 33 * 34 * Params: 35 * method = the method to be invoked when the event is triggered 36 */ 37 template OnDeserializing (alias method) 38 { 39 static orange.serialization.Events.Event!(method) __onDeserializing; 40 } 41 42 /** 43 * Methods with this attribute attached will be called before the struct/class has been 44 * deserialized. 45 */ 46 @attribute struct onDeserializing { } 47 48 /** 49 * This event is triggered after the struct/class, this template has been mixed into, 50 * has been completely serialized, including all the fields. 51 * 52 * Params: 53 * method = the method to be invoked when the event is triggered 54 */ 55 template OnSerialized (alias method) 56 { 57 static orange.serialization.Events.Event!(method) __onSerialized; 58 } 59 60 /** 61 * Methods with this attribute attached will be called after the struct/class has been 62 * serialized. 63 */ 64 @attribute struct onSerialized { } 65 66 /** 67 * This event is triggered after the struct/class, this template has been mixed into, 68 * has been serialized, but before any fields have been serialized. 69 * 70 * Params: 71 * method = the method to be invoked when the event is triggered 72 */ 73 template OnSerializing (alias method) 74 { 75 static orange.serialization.Events.Event!(method) __onSerializing; 76 } 77 78 /** 79 * Methods with this attribute attached will be called before the struct/class has been 80 * serialized. 81 */ 82 @attribute struct onSerializing { } 83 84 /** 85 * This struct represents an event. 86 * 87 * Params: 88 * m = the method to be invoked when the event is triggered 89 */ 90 struct Event (alias m) 91 { 92 private enum method = &m; 93 94 /** 95 * Triggers the event on the given value. 96 * 97 * Params: 98 * value = the object to trigger the event on 99 */ 100 void opCall (T) (T value) 101 { 102 void delegate () dg; 103 dg.ptr = cast(void*) value; 104 dg.funcptr = method; 105 dg(); 106 } 107 } 108 109 package: 110 111 enum onDeserializedField = "__onDeserialized"; 112 enum onDeserializingField = "__onDeserializing"; 113 enum onSerializedField = "__onSerialized"; 114 enum onSerializingField = "__onSerializing";