Page MenuHomePhabricator (Chris)

No OneTemporary

Authored By
Unknown
Size
2 KB
Referenced Files
None
Subscribers
None
diff --git a/util/pointer.h b/util/pointer.h
index 33e8ae4c..bfa3d944 100644
--- a/util/pointer.h
+++ b/util/pointer.h
@@ -1,127 +1,135 @@
#ifndef _paintown_util_pointer_h
#define _paintown_util_pointer_h
namespace Util{
/* Some helpful pointer classes, probably equivalent to stuff in boost
*/
template <class Data>
class ReferenceCount{
public:
ReferenceCount(Data * what = NULL):
count(NULL),
data(what){
count = new int;
*count = 1;
}
ReferenceCount(const ReferenceCount<Data> & him){
data = him.data;
count = him.count;
*count += 1;
}
ReferenceCount & operator=(const ReferenceCount<Data> & him){
release();
data = him.data;
count = him.count;
*count += 1;
return *this;
}
+ ReferenceCount & operator=(Data * what){
+ release();
+ count = new int;
+ *count = 1;
+ data = what;
+ return *this;
+ }
+
Data * operator->() const {
return data;
}
Data & operator*() const {
return *data;
}
bool operator==(const ReferenceCount<Data> & him) const {
return data == him.data;
}
bool operator!=(const ReferenceCount<Data> & him) const {
return !(*this == him);
}
bool operator==(const void * what) const {
return data == what;
}
bool operator!=(const void * what) const {
return !(*this == what);
}
virtual ~ReferenceCount(){
release();
}
protected:
void release(){
*count -= 1;
if (*count == 0){
delete data;
delete count;
data = NULL;
count = NULL;
}
}
int * count;
Data * data;
};
/* Initializes its pointer to NULL and deletes the data in the destructor.
* how is this different from the ReferenceCount class above? its basically
* the same thing but only allows one owner at a time.
*/
template <class Data>
class ClassPointer{
public:
ClassPointer():
data(NULL){
}
ClassPointer(Data * him):
data(him){
}
ClassPointer & operator=(Data * him){
if (data != NULL){
delete data;
}
data = him;
return *this;
}
Data & operator*() const {
return *data;
}
bool operator==(const void * what) const {
return data == what;
}
bool operator!=(const void * what) const {
return !(*this == what);
}
Data* operator->() const {
return data;
}
virtual ~ClassPointer(){
delete data;
}
private:
Data* data;
};
}
#endif

File Metadata

Mime Type
text/x-diff
Expires
Thu, Jun 11, 11:15 AM (3 w, 5 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
68686
Default Alt Text
(2 KB)

Event Timeline