Mercurial > projects > qtd
comparison qt/QGlobal.d @ 184:7d9db724ee1d
QObject is now non GC'ed, to better integrate to Qt memory management
author | eldar |
---|---|
date | Sat, 04 Jul 2009 13:04:46 +0000 |
parents | d3f4f14d43a5 |
children | 7dd099050621 |
comparison
equal
deleted
inserted
replaced
183:d3f4f14d43a5 | 184:7d9db724ee1d |
---|---|
584 const ushort QT_EDITION_EDUCATIONAL = QT_EDITION_DESKTOP; | 584 const ushort QT_EDITION_EDUCATIONAL = QT_EDITION_DESKTOP; |
585 const ushort QT_EDITION_EVALUATION = QT_EDITION_DESKTOP; | 585 const ushort QT_EDITION_EVALUATION = QT_EDITION_DESKTOP; |
586 | 586 |
587 mixin QT_END_NAMESPACE; | 587 mixin QT_END_NAMESPACE; |
588 | 588 |
589 package import tango.stdc.stdlib; | 589 package import tango.stdc.stdlib, |
590 | 590 tango.core.Memory; |
591 template sizeOf(C : Object) | 591 |
592 { | 592 private |
593 const sizeOf = sizeOfImpl!(C); | 593 struct Align |
594 } | 594 { |
595 | 595 ubyte a; |
596 size_t sizeOfImpl(C)() | 596 void* b; |
597 { | 597 } |
598 size_t size; | 598 |
599 | 599 private |
600 foreach (i, _; typeof(C.tupleof)) | 600 const PTR_ALIGN = Align.tupleof[1].alignof; |
601 { | 601 |
602 auto newSize = C.tupleof[i].offsetof + C.tupleof[i].sizeof; | 602 version( X86 ) |
603 if (newSize > size) | 603 const MEM_ALIGN = 8u; |
604 size = newSize; | 604 else |
605 } | 605 static assert(false, "Unknown memory alignment for this platform."); |
606 | 606 |
607 return size; | 607 private |
608 template AlignPad(size_t base, size_t aligned) | |
609 { | |
610 static if( aligned == 0 ) | |
611 const AlignPad = base; | |
612 else | |
613 const AlignPad = ((base+PTR_ALIGN-1)/PTR_ALIGN)*PTR_ALIGN | |
614 + aligned; | |
615 } | |
616 | |
617 template InstanceSize(T) | |
618 { | |
619 static if( is( T == Object ) ) | |
620 const InstanceSize = 2*(void*).sizeof; | |
621 else | |
622 const InstanceSize = Max!( | |
623 AlignPad!( | |
624 InstanceSize!(Super!(T)), | |
625 InterfaceCount!(T)*(void*).sizeof), | |
626 | |
627 AlignPad!( | |
628 InstanceSizeImpl!(T, 0), | |
629 + InterfaceCount!(T)*(void*).sizeof)); | |
630 } | |
631 | |
632 private | |
633 template Super(T) | |
634 { | |
635 static if( is( T S == super ) ) | |
636 alias First!(S) Super; | |
637 else | |
638 static assert(false, "Can't get super of "~T.mangleof); | |
639 } | |
640 | |
641 private | |
642 template First(T) | |
643 { | |
644 alias T First; | |
645 } | |
646 | |
647 private | |
648 template First(T, Ts...) | |
649 { | |
650 alias T First; | |
651 } | |
652 | |
653 private | |
654 template InstanceSizeImpl(T, size_t i) | |
655 { | |
656 static if( i < T.tupleof.length ) | |
657 const InstanceSizeImpl = Max!( | |
658 T.tupleof[i].offsetof + T.tupleof[i].sizeof, | |
659 InstanceSizeImpl!(T, i+1)); | |
660 else | |
661 // This is necessary to account for classes without member | |
662 // variables. | |
663 const InstanceSizeImpl = 2*(void*).sizeof; | |
664 } | |
665 | |
666 private | |
667 template Max(size_t a, size_t b) | |
668 { | |
669 static if( a > b ) | |
670 const Max = a; | |
671 else | |
672 const Max = b; | |
673 } | |
674 | |
675 template InstanceSizeAligned(T, size_t alignment=MEM_ALIGN) | |
676 { | |
677 static if( alignment == 0 ) | |
678 const InstanceSizeAligned = InstanceSize!(T); | |
679 else | |
680 const uint InstanceSizeAligned | |
681 = InstanceSizeAlignImpl!(T, alignment).result; | |
682 } | |
683 | |
684 private | |
685 template InstanceSizeAlignedImpl(T, size_t alignment) | |
686 { | |
687 private const base_size = InstanceSize!(T); | |
688 const result = ((base_size+alignment-1)/alignment)*alignment; | |
689 } | |
690 | |
691 private | |
692 template InterfaceCount(T) | |
693 { | |
694 static if( is( T == Object ) ) | |
695 const InterfaceCount = 0u; | |
696 else static if( is( T S == super ) ) | |
697 const InterfaceCount = InterfaceCountImpl!(S); | |
698 } | |
699 | |
700 private | |
701 template InterfaceCountImpl(TBase, TInterfaces...) | |
702 { | |
703 const InterfaceCountImpl = TInterfaces.length; | |
608 } | 704 } |
609 | 705 |
610 scope class StackObject(C) | 706 scope class StackObject(C) |
611 { | 707 { |
612 byte[sizeOf!(C)] data; | 708 byte[InstanceSize!(C)] data; |
613 bool constructed; | 709 bool constructed; |
614 | 710 |
615 C opCall(A...)(A args) | 711 C opCall(A...)(A args) |
616 { | 712 { |
617 assert(!constructed); | 713 assert(!constructed); |