Advertisement
Guest User

Untitled

a guest
Nov 24th, 2013
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 1.45 KB | None | 0 0
  1. private void aggregateSerializeHelper (T) (ref T value)
  2. {
  3.     static assert(isStruct!(T) || isObject!(T), format!(`The given value of the type "`, T, `" is not a valid type, the only valid types for this method are objects and structs.`));
  4.  
  5.     foreach (i, dummy ; typeof(T.tupleof))
  6.     {
  7.         enum field = nameOfFieldAt!(T, i);
  8.  
  9.         mixin(`alias getAttributes!(value.` ~ field ~ `) attributes;`);
  10.  
  11.         static if (attributes.contains!(nonSerialized))
  12.             continue;
  13.  
  14.         else
  15.         {
  16.             alias typeof(T.tupleof[i]) Type;
  17.  
  18.             auto v = value.tupleof[i];
  19.             auto id = nextId();
  20.  
  21.             static if (isPointer!(Type))
  22.                 auto pointer = v;
  23.  
  24.             else
  25.                 auto pointer = &value.tupleof[i];
  26.  
  27.             auto reference = getSerializedReference(v);
  28.  
  29.             if (reference != Id.max)
  30.                 serializeReference(field, reference);
  31.  
  32.             else
  33.             {
  34.                 auto valueMeta = getSerializedValue(pointer);
  35.  
  36.                 if (valueMeta.isValid)
  37.                     serializePointer(pointer, toData(field), id);
  38.  
  39.                 else
  40.                 {
  41.                     serializeInternal(v, toData(field), id);
  42.                     addSerializedValue(pointer, id, toData(keyCounter));
  43.                 }
  44.             }
  45.         }
  46.     }
  47.  
  48.     static if (isObject!(T) && !is(Unqual!(T) == Object))
  49.         serializeBaseTypes(value);
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement