Mercurial > projects > orange
comparison orange/serialization/Serializer.d @ 8:613a0bb20207
Now works with dmd 1.062
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Wed, 21 Jul 2010 13:44:08 +0200 |
parents | 470ab5270d0c |
children | 99c52d46822a |
comparison
equal
deleted
inserted
replaced
7:32152d5fad4b | 8:613a0bb20207 |
---|---|
424 } | 424 } |
425 | 425 |
426 private void objectStructSerializeHelper (T) (ref T value) | 426 private void objectStructSerializeHelper (T) (ref T value) |
427 { | 427 { |
428 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.`)); | 428 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.`)); |
429 const nonSerializedFields = collectAnnotations!(nonSerializedField)(value); | 429 const nonSerializedFields = collectAnnotations!(nonSerializedField, T); |
430 | 430 |
431 foreach (i, dummy ; typeof(T.tupleof)) | 431 foreach (i, dummy ; typeof(T.tupleof)) |
432 { | 432 { |
433 const field = nameOfFieldAt!(T, i); | 433 const field = nameOfFieldAt!(T, i); |
434 | 434 |
445 } | 445 } |
446 | 446 |
447 private void objectStructDeserializeHelper (T) (ref T value) | 447 private void objectStructDeserializeHelper (T) (ref T value) |
448 { | 448 { |
449 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.`)); | 449 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.`)); |
450 const nonSerializedFields = collectAnnotations!(nonSerializedField)(value); | 450 const nonSerializedFields = collectAnnotations!(nonSerializedField, T); |
451 | 451 |
452 foreach (i, dummy ; typeof(T.tupleof)) | 452 foreach (i, dummy ; typeof(T.tupleof)) |
453 { | 453 { |
454 const field = nameOfFieldAt!(T, i); | 454 const field = nameOfFieldAt!(T, i); |
455 | 455 |
588 | 588 |
589 else | 589 else |
590 triggerEvent!(onDeserializedField)(value); | 590 triggerEvent!(onDeserializedField)(value); |
591 } | 591 } |
592 | 592 |
593 private static string[] collectAnnotations (string name, T) (T value) | 593 private static string[] collectAnnotations (string name, T) () |
594 { | 594 { |
595 static assert (isObject!(T) || isStruct!(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.`)); | 595 static assert (isObject!(T) || isStruct!(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.`)); |
596 | 596 |
597 string[] annotations; | 597 string[] annotations; |
598 | 598 |
599 foreach (i, dummy ; typeof(T.tupleof)) | 599 foreach (i, type ; typeof(T.tupleof)) |
600 { | 600 { |
601 const field = nameOfFieldAt!(T, i); | 601 const field = nameOfFieldAt!(T, i); |
602 | 602 |
603 static if (field == name) | 603 static if (field == name) |
604 { | 604 annotations ~= type.field; |
605 typeof(value.tupleof[i]) f; | |
606 annotations ~= f.field; | |
607 } | |
608 } | 605 } |
609 | 606 |
610 return annotations; | 607 return annotations; |
611 } | 608 } |
612 } | 609 } |