00001 #ifndef _HANDLE_HPP 00002 #define _HANDLE_HPP 00003 00004 template <typename T> 00005 class PointerHandle { 00006 private: 00007 T* ptr; 00008 public: 00009 const T& operator*() const { return *ptr; } 00010 T& operator*() { return *ptr; } 00011 const T* operator->() const { return ptr; } 00012 T* operator->() { return ptr; } 00013 bool valid() const { return (ptr != NULL); } 00014 00015 PointerHandle() { ptr = NULL; } 00016 PointerHandle(const PointerHandle<T> &vh) { this->ptr = vh.ptr; } 00017 PointerHandle(T* ptr) { this->ptr = ptr; } 00018 PointerHandle(T& item) { this->ptr = &item; } 00019 00020 bool operator==(const PointerHandle<T>& other) const 00021 { return (ptr == other.ptr); } 00022 bool operator!=(const PointerHandle<T>& other) const 00023 { return (ptr != other.ptr); } 00024 bool operator<(const PointerHandle<T>& other) const 00025 { return (ptr < other.ptr); } 00026 00027 const PointerHandle<T>& operator=(const PointerHandle<T>& other) 00028 { this->ptr = other.ptr; return *this; } 00029 }; 00030 00031 #endif