Mercurial > projects > orange
comparison orange/serialization/archives/XMLArchive.d @ 21:51f05fd6a626
Merged changes from dsource repository.
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Mon, 04 Oct 2010 20:18:02 +0200 |
parents | 9a575087b961 |
children | 963b756ed579 |
comparison
equal
deleted
inserted
replaced
20:9a575087b961 | 21:51f05fd6a626 |
---|---|
414 } | 414 } |
415 | 415 |
416 lastElement = tmp; | 416 lastElement = tmp; |
417 | 417 |
418 auto runtimeType = getValueOfAttribute(Attributes.runtimeTypeAttribute); | 418 auto runtimeType = getValueOfAttribute(Attributes.runtimeTypeAttribute); |
419 | |
420 if (!runtimeType) | |
421 return T.init; | |
422 | |
419 auto name = fromDataType!(string)(runtimeType); | 423 auto name = fromDataType!(string)(runtimeType); |
420 id = getValueOfAttribute(Attributes.idAttribute); | 424 id = getValueOfAttribute(Attributes.idAttribute); |
425 | |
426 if (!id) | |
427 return T.init; | |
428 | |
421 T result = cast(T) newInstance(name); | 429 T result = cast(T) newInstance(name); |
422 | 430 |
423 addUnarchivedReference(result, id); | 431 addUnarchivedReference(result, id); |
424 | 432 |
425 return result; | 433 return result; |
471 | 479 |
472 if (!element.isValid) | 480 if (!element.isValid) |
473 return T.init; | 481 return T.init; |
474 | 482 |
475 lastElement = element; | 483 lastElement = element; |
476 auto length = getValueOfAttribute(Attributes.lengthAttribute); | 484 auto length = getValueOfAttribute(Attributes.lengthAttribute); |
485 | |
486 if (!length) | |
487 return T.init; | |
488 | |
477 value.length = fromDataType!(size_t)(length); | 489 value.length = fromDataType!(size_t)(length); |
478 slice.id = getValueOfAttribute(Attributes.idAttribute); | 490 slice.id = getValueOfAttribute(Attributes.idAttribute); |
491 | |
492 if (!slice.id) | |
493 return T.init; | |
479 | 494 |
480 addUnarchivedSlice(value, slice.id); | 495 addUnarchivedSlice(value, slice.id); |
481 | 496 |
482 return value; | 497 return value; |
483 } | 498 } |
507 if (!element.isValid) | 522 if (!element.isValid) |
508 return T.init; | 523 return T.init; |
509 | 524 |
510 lastElement = element; | 525 lastElement = element; |
511 id = getValueOfAttribute(Attributes.idAttribute); | 526 id = getValueOfAttribute(Attributes.idAttribute); |
527 | |
528 if (!id) | |
529 return T.init; | |
512 | 530 |
513 T result = new BaseTypeOfPointer!(T); | 531 T result = new BaseTypeOfPointer!(T); |
514 | 532 |
515 addUnarchivedReference(result, id); | 533 addUnarchivedReference(result, id); |
516 | 534 |
615 else | 633 else |
616 errorCallback(new ArchiveException(`Could not unarchive the value with the key "` ~ to!(string)(key) ~ `" due to malformed data.`, __FILE__, __LINE__), [tag, Attributes.keyAttribute, key]); | 634 errorCallback(new ArchiveException(`Could not unarchive the value with the key "` ~ to!(string)(key) ~ `" due to malformed data.`, __FILE__, __LINE__), [tag, Attributes.keyAttribute, key]); |
617 } | 635 } |
618 | 636 |
619 return doc.Node.invalid; | 637 return doc.Node.invalid; |
620 } | 638 } |
621 } | 639 } |
622 | 640 |
623 private DataType getValueOfAttribute (DataType attribute, doc.Node element = doc.Node.invalid) | 641 private DataType getValueOfAttribute (DataType attribute, doc.Node element = doc.Node.invalid) |
624 { | 642 { |
625 if (!element.isValid) element = lastElement; | 643 if (!element.isValid) element = lastElement; |
637 errorCallback(new ArchiveException(`Could not find the attribute "` ~ to!(string)(attribute) ~ `".`, __FILE__, __LINE__), [attribute]); | 655 errorCallback(new ArchiveException(`Could not find the attribute "` ~ to!(string)(attribute) ~ `".`, __FILE__, __LINE__), [attribute]); |
638 | 656 |
639 else | 657 else |
640 errorCallback(new ArchiveException(`Could not unarchive the value of the attribute "` ~ to!(string)(attribute) ~ `" due to malformed data.`, __FILE__, __LINE__), [attribute]); | 658 errorCallback(new ArchiveException(`Could not unarchive the value of the attribute "` ~ to!(string)(attribute) ~ `" due to malformed data.`, __FILE__, __LINE__), [attribute]); |
641 } | 659 } |
642 } | 660 } |
661 | |
662 return null; | |
643 } | 663 } |
644 | 664 |
645 private void addArchivedReference (T) (T value, DataType id) | 665 private void addArchivedReference (T) (T value, DataType id) |
646 { | 666 { |
647 static assert(isReference!(T), format!(`The given type "`, T, `" is not a reference type, i.e. object or pointer.`)); | 667 static assert(isReference!(T), format!(`The given type "`, T, `" is not a reference type, i.e. object or pointer.`)); |