#ifndef SMARTPTR_H #define SMARTPTR_H #include #include #include /** * Simple shared pointer class with NO thread safety (not even the counter is thread-safe) */ template class SmartPtr { //Rule 1: tracker is always NULL when ptr == NULL //Rule 2: ID is only assigned in constructors typedef std::map*> IDMap; typedef std::pair*> IDPair; T* ptr; IDMap *tracker; //track pointers to same object unsigned long ID; static unsigned long __IDCounter; public: typedef T element_type; SmartPtr(const SmartPtr& other); SmartPtr& operator=(const SmartPtr& other); SmartPtr(T* new_ptr = NULL); T& operator*(); const T& operator*() const; ~SmartPtr(); unsigned long use_count() const; operator bool(); T* get(); const T* const get() const; T* release(); void reset(T* new_ptr = NULL); inline bool isNull(); template