| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 
 |  
#ifndef FRAMEWORK_POINTER_____
#define FRAMEWORK_POINTER_____
 
#include "Object.h"
 
namespace foundation
{
	template <class T>
	class MyPointer
	{
	private:
		MyObject* ObjectPointe;
 
	public:
		//Constructeur
		inline MyPointer() : ObjectPointe(NULL)
		{ }
		inline MyPointer(const MyObject* inPtr) : ObjectPointe( (inPtr != NULL) ? (const_cast<MyObject*>(inPtr)->refer()) : NULL )
		{ }
		inline MyPointer( const MyPointer& inPtr ) : ObjectPointe( (inPtr.getPointer() != NULL) ? (const_cast<foundation::MyObject*>(inPtr.getPointer())->refer()) : NULL )
		{ }
		inline ~MyPointer()
		{
			if ( this->ObjectPointe != NULL ) this->ObjectPointe->unrefer();
			this->ObjectPointe = NULL;
		}
 
		inline T* getPointer()
		{
			return static_cast<T*>( this->ObjectPointe);
		}
		inline const T* getPointer() const
		{
			return static_cast<T*> (this->ObjectPointe);
		}
 
		inline MyPointer& operator=(const MyObject* inPtr)
		{
			if (this->ObjectPointe == inPtr) return *this; // si le pointeur pointe deja sur l'object
			if ( this->ObjectPointe != NULL ) this->ObjectPointe->unrefer(); // liberation de l'object deja pointe
			if ( inPtr )
				this->ObjectPointe = const_cast<T*>(inPtr)->refer();
			else this->ObjectPointe = NULL;
			return *this;
		}
		inline MyPointer& operator=(const MyPointer& inPtr)
		{
			if ( this==&inPtr ) return *this;
			if ( this->ObjectPointe == inPtr.getPointer() ) return *this;
			if ( this->ObjectPointe )
				this->ObjectPointe->unrefer();
			if ( inPtr.getPointer() != NULL )
				this->ObjectPointe = const_cast<T*>(inPtr.getPointer())->refer();
			else this->ObjectPointe = NULL;
			return *this;
		}
 
		inline T& operator*()
		{
			return *(static_cast<T*> (this->ObjectPointe));
		}
		inline const T& operator*() const
		{
			return *(static_cast<T*> (this->ObjectPointe));
		}
		inline T* operator->()
		{
			return static_cast<T*> (this->ObjectPointe);
		}
		inline const T* operator->() const
		{
			return static_cast<T*> (this->ObjectPointe);
		}
 
		inline bool operator!() const
		{
			return (!this->ObjectPointe);
		}
		inline bool operator==(const MyObject* inPtr) const
		{
			return ( this->ObjectPointe == inPtr);
		}
		inline bool operator==(const MyPointer& inPtr) const
		{
			return ( this->ObjectPointe == inPtr.getPointer());
		}
		inline bool operator!=(const MyObject* inPtr) const
		{
			return (this->ObjectPointe != inPtr);
		}
		inline bool operator!=(const MyPointer& inPtr) const
		{
			return ( this->ObjectPointe != inPtr.getPointer());
		}
	};
}
 
#endif | 
Partager