diff --git a/libretroshare/src/util/rsinitedptr.h b/libretroshare/src/util/rsinitedptr.h new file mode 100644 index 000000000..a1d346ba0 --- /dev/null +++ b/libretroshare/src/util/rsinitedptr.h @@ -0,0 +1,30 @@ +#pragma once +/** +helper class to store a pointer +it is usefull because it initialises itself to NULL + +usage: +replace + type* ptr; +with + inited_ptr ptr; + +this class can +- get assigned a pointer +- be dereferenced +- be converted back to a pointer +*/ +namespace RsUtil{ +template class inited_ptr{ +public: + inited_ptr(): _ptr(NULL){} + inited_ptr(const inited_ptr& other): _ptr(other._ptr){} + inited_ptr& operator= (const inited_ptr& other){ _ptr = other._ptr; return *this;} + inited_ptr& operator= (T* ptr){ _ptr = ptr; return *this;} + operator T* () const { return _ptr;} + T* operator ->() const { return _ptr;} + T& operator *() const { return *_ptr;} +private: + T* _ptr; +}; +}//namespace RsUtil