comparison orange/serialization/archives/Archive.d @ 20:9a575087b961

Added support for slices. Strings and arrays are now treated as references.
author Jacob Carlborg <doob@me.com>
date Mon, 04 Oct 2010 18:27:21 +0200
parents 3d42ea434d46
children 55f0a9d5df8d
comparison
equal deleted inserted replaced
18:3d42ea434d46 20:9a575087b961
14 import std.conv; 14 import std.conv;
15 alias ConvError ConversionException; 15 alias ConvError ConversionException;
16 } 16 }
17 17
18 import orange.serialization.archives.ArchiveException; 18 import orange.serialization.archives.ArchiveException;
19
20 struct Slice
21 {
22 size_t length;
23 void* ptr;
24
25 static Slice opCall (T) (T[] value)
26 {
27 Slice slice;
28 slice.length = value.length;
29 slice.ptr = value.ptr;
30
31 return slice;
32 }
33 }
19 34
20 interface IArchive 35 interface IArchive
21 { 36 {
22 void beginArchiving (); 37 void beginArchiving ();
23 void reset (); 38 void reset ();
51 try 66 try
52 return to!(T)(value); 67 return to!(T)(value);
53 68
54 catch (ConversionException e) 69 catch (ConversionException e)
55 throw new ArchiveException(e); 70 throw new ArchiveException(e);
56 } 71 }
72
73 protected bool isSliceOf (T, U = T) (T[] a, U[] b)
74 {
75 void* aPtr = a.ptr;
76 void* bPtr = b.ptr;
77
78 return aPtr >= bPtr && aPtr + a.length * T.sizeof <= bPtr + b.length * U.sizeof;
79 }
57 } 80 }