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:
Patrick Ohly 2008-01-14 21:23:37 +00:00
parent 64756c9860
commit d68488c0be
1 changed files with 12 additions and 6 deletions

View File

@ -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; }