mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
added missign file from previous merge
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7494 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
f6db432c74
commit
9781982811
30
libretroshare/src/util/rsinitedptr.h
Normal file
30
libretroshare/src/util/rsinitedptr.h
Normal file
@ -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<type> ptr;
|
||||
|
||||
this class can
|
||||
- get assigned a pointer
|
||||
- be dereferenced
|
||||
- be converted back to a pointer
|
||||
*/
|
||||
namespace RsUtil{
|
||||
template<class T> class inited_ptr{
|
||||
public:
|
||||
inited_ptr(): _ptr(NULL){}
|
||||
inited_ptr(const inited_ptr<T>& other): _ptr(other._ptr){}
|
||||
inited_ptr<T>& operator= (const inited_ptr<T>& other){ _ptr = other._ptr; return *this;}
|
||||
inited_ptr<T>& 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
|
Loading…
Reference in New Issue
Block a user