comparison qt/QGlobal.d.inc @ 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 df7dd6ef9e23
children d5af7c48b733
comparison
equal deleted inserted replaced
183:d3f4f14d43a5 184:7d9db724ee1d
578 const ushort QT_EDITION_ACADEMIC = QT_EDITION_DESKTOP; 578 const ushort QT_EDITION_ACADEMIC = QT_EDITION_DESKTOP;
579 const ushort QT_EDITION_EDUCATIONAL = QT_EDITION_DESKTOP; 579 const ushort QT_EDITION_EDUCATIONAL = QT_EDITION_DESKTOP;
580 const ushort QT_EDITION_EVALUATION = QT_EDITION_DESKTOP; 580 const ushort QT_EDITION_EVALUATION = QT_EDITION_DESKTOP;
581 581
582 mixin QT_END_NAMESPACE; 582 mixin QT_END_NAMESPACE;
583
584 package import tango.stdc.stdlib,
585 tango.core.Memory;
586
587 private
588 struct Align
589 {
590 ubyte a;
591 void* b;
592 }
593
594 private
595 const PTR_ALIGN = Align.tupleof[1].alignof;
596
597 version( X86 )
598 const MEM_ALIGN = 8u;
599 else
600 static assert(false, "Unknown memory alignment for this platform.");
601
602 private
603 template AlignPad(size_t base, size_t aligned)
604 {
605 static if( aligned == 0 )
606 const AlignPad = base;
607 else
608 const AlignPad = ((base+PTR_ALIGN-1)/PTR_ALIGN)*PTR_ALIGN
609 + aligned;
610 }
611
612 template InstanceSize(T)
613 {
614 static if( is( T == Object ) )
615 const InstanceSize = 2*(void*).sizeof;
616 else
617 const InstanceSize = Max!(
618 AlignPad!(
619 InstanceSize!(Super!(T)),
620 InterfaceCount!(T)*(void*).sizeof),
621
622 AlignPad!(
623 InstanceSizeImpl!(T, 0),
624 + InterfaceCount!(T)*(void*).sizeof));
625 }
626
627 private
628 template Super(T)
629 {
630 static if( is( T S == super ) )
631 alias First!(S) Super;
632 else
633 static assert(false, "Can't get super of "~T.mangleof);
634 }
635
636 private
637 template First(T)
638 {
639 alias T First;
640 }
641
642 private
643 template First(T, Ts...)
644 {
645 alias T First;
646 }
647
648 private
649 template InstanceSizeImpl(T, size_t i)
650 {
651 static if( i < T.tupleof.length )
652 const InstanceSizeImpl = Max!(
653 T.tupleof[i].offsetof + T.tupleof[i].sizeof,
654 InstanceSizeImpl!(T, i+1));
655 else
656 // This is necessary to account for classes without member
657 // variables.
658 const InstanceSizeImpl = 2*(void*).sizeof;
659 }
660
661 private
662 template Max(size_t a, size_t b)
663 {
664 static if( a > b )
665 const Max = a;
666 else
667 const Max = b;
668 }
669
670 template InstanceSizeAligned(T, size_t alignment=MEM_ALIGN)
671 {
672 static if( alignment == 0 )
673 const InstanceSizeAligned = InstanceSize!(T);
674 else
675 const uint InstanceSizeAligned
676 = InstanceSizeAlignImpl!(T, alignment).result;
677 }
678
679 private
680 template InstanceSizeAlignedImpl(T, size_t alignment)
681 {
682 private const base_size = InstanceSize!(T);
683 const result = ((base_size+alignment-1)/alignment)*alignment;
684 }
685
686 private
687 template InterfaceCount(T)
688 {
689 static if( is( T == Object ) )
690 const InterfaceCount = 0u;
691 else static if( is( T S == super ) )
692 const InterfaceCount = InterfaceCountImpl!(S);
693 }
694
695 private
696 template InterfaceCountImpl(TBase, TInterfaces...)
697 {
698 const InterfaceCountImpl = TInterfaces.length;
699 }
700
701 scope class StackObject(C)
702 {
703 byte[InstanceSize!(C)] data;
704 bool constructed;
705
706 C opCall(A...)(A args)
707 {
708 assert(!constructed);
709
710 auto r = new(&data)C(args);
711 r.__stackAllocated = true;
712 constructed = true;
713
714 return r;
715 }
716
717 ~this()
718 {
719 if (constructed)
720 {
721 auto obj = cast(C)&data;
722 delete obj;
723 }
724 }
725 }
726
583 mixin QT_END_HEADER; 727 mixin QT_END_HEADER;