added transferring pointer and its ownership from one smart pointer to another
git-svn-id: https://zeitsenke.de/svn/SyncEvolution/trunk@485 15ad00c4-1369-45f4-8270-35d70d36bdcd
This commit is contained in:
parent
64756c9860
commit
d68488c0be
|
@ -58,12 +58,6 @@ template <class T> void unref(T *pointer) { delete pointer; }
|
|||
* unreferencing valid objects is done automatically
|
||||
*/
|
||||
template<class T, class base = T> class eptr {
|
||||
/** do not allow copy construction */
|
||||
eptr( const eptr &other) {};
|
||||
|
||||
/** do not allow copying */
|
||||
void operator = ( const eptr &other ) {}
|
||||
|
||||
protected:
|
||||
T *m_pointer;
|
||||
|
||||
|
@ -84,6 +78,17 @@ template<class T, class base = T> class eptr {
|
|||
set( NULL );
|
||||
}
|
||||
|
||||
/** assignment and copy construction transfer ownership to the copy */
|
||||
eptr(eptr &other) {
|
||||
m_pointer = other.m_pointer;
|
||||
other.m_pointer = NULL;
|
||||
}
|
||||
eptr & operator = (eptr &other) {
|
||||
m_pointer = other.m_pointer;
|
||||
other.m_pointer = NULL;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* store another object in this pointer, replacing any which was
|
||||
* referenced there before;
|
||||
|
@ -108,6 +113,7 @@ template<class T, class base = T> class eptr {
|
|||
T *release() { T *res = m_pointer; m_pointer = NULL; return res; }
|
||||
|
||||
eptr<T, base> &operator = ( T *pointer ) { set( pointer ); return *this; }
|
||||
T *get() { return m_pointer; }
|
||||
T *operator-> () { return m_pointer; }
|
||||
T &operator* () { return *m_pointer; }
|
||||
operator T * () { return m_pointer; }
|
||||
|
|
Loading…
Reference in New Issue