bbweakref.cpp 781 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include "bbweakref.h"
  2. bbGCWeakRef *bbGC::weakRefs;
  3. bbGCWeakRef::bbGCWeakRef( bbObject *target ):target( target ){
  4. if( !target) return;
  5. succ=bbGC::weakRefs;
  6. bbGC::weakRefs=this;
  7. target->flags|=2;
  8. }
  9. bbGCWeakRef::~bbGCWeakRef(){
  10. if( !target ) return;
  11. bbAssert( target->flags & 2,"internal bbGCWeakRef error 1" );
  12. bbGCWeakRef **pred=&bbGC::weakRefs,*curr;
  13. target->flags&=~2;
  14. while( curr=*pred ){
  15. if( curr==this ){
  16. *pred=succ;
  17. if( target->flags & 2 ) return;
  18. while( curr=*pred ){
  19. if( curr->target==target ){
  20. target->flags|=2;
  21. return;
  22. }
  23. pred=&curr->succ;
  24. }
  25. return;
  26. }
  27. if( curr->target==target ) target->flags|=2;
  28. pred=&curr->succ;
  29. }
  30. }
  31. bbObject *bbGCWeakRef::getTarget(){
  32. return target;
  33. }