root/trunk/Serial/Common.d

Revision 591, 1.1 kB (checked in by BCS, 3 years ago)

Added support for 3rd party types and arrays

Line 
1 module Common;
2
3 public import Interface;
4 public import Demarshal;
5 import State;
6
7 alias Object function(Source!(char) source, ref OutMap) Factory;
8 Factory[char[]] Factories;
9
10 template NativeBaseType(T)
11 {
12     const bool NativeBaseType = is(T == int) || is(T == uint) || is(T == long)
13     || is(T == ulong) || is(T == short) ||is(T == ushort)
14     || is(T == byte) || is(T == ubyte) || is(T == float)
15     || is(T == double) || is(T == real);
16 }
17
18
19 template CommonMixin()
20 {
21     static if(is(typeof(this) == class))
22     {
23         static const char[] StaticTypeTag = typeof(this).mangleof;
24        
25         bool TypeTag(Sink!(char) sink, ref InMap map)
26         {
27             static if(CyclicType)
28             {
29                 uint id;
30                 if(map.Hold(cast(void*)this,id))
31                 {
32                     sink.Dump(std.string.format(` ID="%s"/>`, id));
33                     return true;
34                 }
35                 else
36                 {
37                     sink.Dump(std.string.format(` ID="%s"`, id));
38                 }
39             }
40             sink.Dump(` type="`);
41             XML.WriteContentXML(sink,StaticTypeTag);
42             return false;
43         }
44        
45         static this()
46         {
47             Factories[StaticTypeTag] = function Object(Source!(char) source, ref OutMap map)
48             {
49                 return DemarshalMe(source,map);
50             };
51         }
52     }
53
54 }
Note: See TracBrowser for help on using the browser.