added util/refptr module
git-svn-id: svn://anubis/fart/trunk@90 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
1 parent
fc8a46853b
commit
d34242252a
3 files changed
+69
-3
No files matched your search
@@ -0,0 +1,27 @@
|
||||
|
||||
#include "refptr.h"
|
||||
|
||||
template <typename T> refptr<T>::refptr(const T * ptr)
|
||||
{
|
||||
m_ptr = ptr;
|
||||
refCount = new int;
|
||||
*refCount = 1;
|
||||
}
|
||||
|
||||
template <typename T> refptr<T>::refptr(const refptr<T> & orig)
|
||||
{
|
||||
cloneFrom(orig);
|
||||
}
|
||||
|
||||
template <typename T> refptr<T> & refptr<T>::operator=(const refptr<T> & orig)
|
||||
{
|
||||
cloneFrom(orig);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T> void refptr<T>::cloneFrom(const refptr<T> & orig)
|
||||
{
|
||||
this->ptr = orig.ptr;
|
||||
this->refCount = orig.refCount;
|
||||
(*refCount)++;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
|
||||
#ifndef REFPTR_H
|
||||
#define REFPTR_H REFPTR_H
|
||||
|
||||
template <typename T>
|
||||
class refptr
|
||||
{
|
||||
public:
|
||||
refptr<T>(const T * ptr);
|
||||
refptr<T>(const refptr<T> & orig);
|
||||
refptr<T> & operator=(const refptr<T> & orig);
|
||||
|
||||
private:
|
||||
void cloneFrom(const refptr<T> & orig);
|
||||
|
||||
T * m_ptr;
|
||||
int * refCount;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in new issue
Block a user