Answers for "weak"

C++
0

weak

class RefBase
{
public :
	 void             incStrong ( const  void * id)  const ;
	 void             decStrong ( const  void * id)  const ;

	void             forceIncStrong ( const  void * id)  const ;

	//! DEBUGGING ONLY: Get current strong ref count. 
	int32_t          getStrongCount ()  const ;

	class weakref_type
	{
	public :
		RefBase* refBase() const ;

		void                 incWeak ( const  void * id) ;
		 void                 decWeak ( const  void * id) ;

		bool                 attemptIncStrong ( const  void * id) ;

		//! This is only safe if you have set OBJECT_LIFETIME_FOREVER. 
		bool                 attemptIncWeak ( const  void * id) ;

		//! DEBUGGING ONLY: Get current weak ref count. 
		int32_t              getWeakCount ()  const ;

		//! DEBUGGING ONLY: Print references held on object. 
		void                 printRefs ()  const ;

		//! DEBUGGING ONLY: Enable tracking for this object. 
		// enable - enable/disable tracking 
		// retain - when tracking is enable, if true, then we save a stack trace 
		// for each reference and dereference; when retain == false, we 
		// match up references and dereferences and keep only the 
		// outstanding ones.

		void                 trackMe ( bool enable, bool retain) ;
	};

	weakref_type* createWeak( const  void * id) const ;

	weakref_type* getWeakRefs() const ;

	//! DEBUGGING ONLY: Print references held on object. 
	inline   void             printRefs ()  const  {getWeakRefs()->printRefs();}

	//! DEBUGGING ONLY: Enable tracking of object. 
	inline   void             trackMe ( bool enable, bool retain)
	 {
		getWeakRefs()->trackMe(enable, retain);
	}

protected :
	RefBase();
	virtual                  ~RefBase();

	//! Flags for extendObjectLifetime() 
	enum {
		OBJECT_LIFETIME_WEAK = 0x0001 ,
		OBJECT_LIFETIME_FOREVER = 0x0003
	};

	void             extendObjectLifetime ( int32_t mode) ;

	//! Flags for onIncStrongAttempted() 
	enum {
		FIRST_INC_STRONG = 0x0001
	};

	virtual  void             onFirstRef () ;
	 virtual  void             onLastStrongRef ( const  void * id) ;
	 virtual  bool             onIncStrongAttempted ( uint32_t flags, const  void * id) ;
	 virtual  void             onLastWeakRef ( const  void * id) ;

private :
	 friend  class weakref_type;
	 class weakref_impl;

	RefBase( const RefBase& o);
	RefBase&         operator =( const RefBase& o);

	weakref_impl* const mRefs;
};
Posted by: Guest on June-09-2021

Browse Popular Code Answers by Language