renamed member variables of some classes

This commit is contained in:
hyung-hwan 2015-03-12 11:32:18 +00:00
parent 756a93ff41
commit 36e75b3bb2
3 changed files with 50 additions and 47 deletions

View File

@ -36,39 +36,41 @@ QSE_BEGIN_NAMESPACE(QSE)
class QSE_EXPORT RefCounted: public Uncopyable class QSE_EXPORT RefCounted: public Uncopyable
{ {
protected: protected:
RefCounted () RefCounted (): _ref_count(0)
{ {
this->ref_count = 0;
} }
public: public:
virtual ~RefCounted () virtual ~RefCounted ()
{ {
QSE_ASSERT (this->ref_count == 0); QSE_ASSERT (this->_ref_count == 0);
} }
void ref () const void ref () const
{ {
this->ref_count++; this->_ref_count++;
} }
void deref (bool kill = true) const void deref (bool kill = true) const
{ {
if (--this->ref_count == 0 && kill) delete this; if (--this->_ref_count == 0 && kill)
{
delete this;
}
} }
qse_size_t getRefCount () const qse_size_t getRefCount () const
{ {
return this->ref_count; return this->_ref_count;
} }
bool isShared () const bool isShared () const
{ {
return this->ref_count > 1; return this->_ref_count > 1;
} }
protected: protected:
mutable qse_size_t ref_count; mutable qse_size_t _ref_count;
}; };
///////////////////////////////// /////////////////////////////////

View File

@ -112,7 +112,7 @@ public:
{ {
if (this->_ptr) if (this->_ptr)
{ {
this->deleter (this->_ptr, this->_darg); this->_deleter (this->_ptr, this->_darg);
} }
} }
@ -173,17 +173,17 @@ public:
{ {
if (this->_ptr) if (this->_ptr)
{ {
this->deleter (this->_ptr, this->_darg); this->_deleter (this->_ptr, this->_darg);
} }
this->_ptr = ptr; this->_ptr = ptr;
this->_darg = darg; this->_darg = darg;
} }
protected: private:
T* _ptr; T* _ptr;
void* _darg; void* _darg;
DELETER deleter; DELETER _deleter;
}; };
///////////////////////////////// /////////////////////////////////

View File

@ -28,6 +28,7 @@
#define _QSE_CMN_SHAREDPTR_HPP_ #define _QSE_CMN_SHAREDPTR_HPP_
#include <qse/cmn/Mmged.hpp> #include <qse/cmn/Mmged.hpp>
#include <qse/RefCounted.hpp>
///////////////////////////////// /////////////////////////////////
QSE_BEGIN_NAMESPACE(QSE) QSE_BEGIN_NAMESPACE(QSE)
@ -75,33 +76,33 @@ public:
SharedPtr (T* ptr = (T*)QSE_NULL, void* darg = (void*)QSE_NULL): Mmged(QSE_NULL) SharedPtr (T* ptr = (T*)QSE_NULL, void* darg = (void*)QSE_NULL): Mmged(QSE_NULL)
{ {
this->item = new (this->getMmgr()) item_t; this->_item = new (this->getMmgr()) item_t;
this->item->ref = 1; this->_item->ref = 1;
this->item->ptr = ptr; this->_item->ptr = ptr;
this->item->darg = darg; this->_item->darg = darg;
} }
SharedPtr (Mmgr* mmgr, T* ptr = (T*)QSE_NULL, void* darg = (void*)QSE_NULL): Mmged(mmgr) SharedPtr (Mmgr* mmgr, T* ptr = (T*)QSE_NULL, void* darg = (void*)QSE_NULL): Mmged(mmgr)
{ {
this->item = new (this->getMmgr()) item_t; this->_item = new (this->getMmgr()) item_t;
this->item->ref = 1; this->_item->ref = 1;
this->item->ptr = ptr; this->_item->ptr = ptr;
this->item->darg = darg; this->_item->darg = darg;
} }
SharedPtr (const SelfType& sp): Mmged(sp), item (sp.item) SharedPtr (const SelfType& sp): Mmged(sp), _item(sp._item)
{ {
this->item->ref++; this->_item->ref++;
} }
~SharedPtr () ~SharedPtr ()
{ {
this->item->ref--; this->_item->ref--;
if (this->item->ref <= 0) if (this->_item->ref <= 0)
{ {
if (this->item->ptr) this->item->deleter (this->item->ptr, this->item->darg); if (this->_item->ptr) this->_item->deleter (this->_item->ptr, this->_item->darg);
// no destructor as *this->_ref is a plain type. // no destructor as *this->_ref is a plain type.
::operator delete (this->item, this->getMmgr()); ::operator delete (this->_item, this->getMmgr());
} }
} }
@ -109,20 +110,20 @@ public:
{ {
if (this != &sp) if (this != &sp)
{ {
this->item->ref--; this->_item->ref--;
if (this->item->ref <= 0) if (this->_item->ref <= 0)
{ {
if (this->item->ptr) this->item->deleter (this->item->ptr, this->item->darg); if (this->_item->ptr) this->_item->deleter (this->_item->ptr, this->_item->darg);
// no destructor as *this->_ref is a plain type. // no destructor as *this->_ref is a plain type.
::operator delete (this->item, this->getMmgr()); ::operator delete (this->_item, this->getMmgr());
} }
// must copy the memory manager pointer as the item // must copy the memory manager pointer as the item
// to be copied is allocated using the memory manager of sp. // to be copied is allocated using the memory manager of sp.
this->setMmgr (sp.getMmgr()); this->setMmgr (sp.getMmgr());
this->item = sp.item; this->_item = sp._item;
this->item->ref++; this->_item->ref++;
} }
return *this; return *this;
@ -130,50 +131,50 @@ public:
T& operator* () T& operator* ()
{ {
QSE_ASSERT (this->item->ptr != (T*)QSE_NULL); QSE_ASSERT (this->_item->ptr != (T*)QSE_NULL);
return *this->item->ptr; return *this->_item->ptr;
} }
const T& operator* () const const T& operator* () const
{ {
QSE_ASSERT (this->item->ptr != (T*)QSE_NULL); QSE_ASSERT (this->_item->ptr != (T*)QSE_NULL);
return *this->item->ptr; return *this->_item->ptr;
} }
T* operator-> () T* operator-> ()
{ {
QSE_ASSERT (this->item->ptr != (T*)QSE_NULL); QSE_ASSERT (this->_item->ptr != (T*)QSE_NULL);
return this->item->ptr; return this->_item->ptr;
} }
const T* operator-> () const const T* operator-> () const
{ {
QSE_ASSERT (this->item->ptr != (T*)QSE_NULL); QSE_ASSERT (this->_item->ptr != (T*)QSE_NULL);
return this->item->ptr; return this->_item->ptr;
} }
bool operator! () const bool operator! () const
{ {
return this->item->ptr == (T*)QSE_NULL; return this->_item->ptr == (T*)QSE_NULL;
} }
T& operator[] (qse_size_t idx) T& operator[] (qse_size_t idx)
{ {
QSE_ASSERT (this->item->ptr != (T*)QSE_NULL); QSE_ASSERT (this->_item->ptr != (T*)QSE_NULL);
return this->item->ptr[idx]; return this->_item->ptr[idx];
} }
T* getPtr () T* getPtr ()
{ {
return this->item->ptr; return this->_item->ptr;
} }
const T* getPtr () const const T* getPtr () const
{ {
return this->item->ptr; return this->_item->ptr;
} }
protected: private:
struct item_t struct item_t
{ {
qse_size_t ref; qse_size_t ref;
@ -182,7 +183,7 @@ protected:
DELETER deleter; DELETER deleter;
}; };
item_t* item; item_t* _item;
}; };
///////////////////////////////// /////////////////////////////////