shared.h
00001 #ifndef SHARED_H
00002 #define SHARED_H
00003
00004 namespace khtml {
00005
00006 template<class type> class Shared
00007 {
00008 public:
00009 Shared() { _ref=0; }
00010 ~Shared() { }
00011
00012 void ref() { _ref++; }
00013 void deref() {
00014 if(_ref) _ref--;
00015 if(!_ref)
00016 delete static_cast<type *>(this);
00017 }
00018 bool hasOneRef() {
00019 return _ref==1; }
00020
00021 int refCount() const { return _ref; }
00022
00023 protected:
00024 unsigned int _ref;
00025 };
00026
00027 template<class type> class TreeShared
00028 {
00029 public:
00030 TreeShared() { _ref = 0; m_parent = 0; }
00031 TreeShared( type *parent ) { _ref=0; m_parent = parent; }
00032 ~TreeShared() { }
00033
00034 void ref() { _ref++; }
00035 void deref() {
00036 if(_ref) _ref--;
00037 if(!_ref && !m_parent) {
00038 delete static_cast<type *>(this);
00039 }
00040 }
00041 bool hasOneRef() {
00042 return _ref==1; }
00043
00044 int refCount() const { return _ref; }
00045
00046
00047 void setParent(type *parent) { m_parent = parent; }
00048 type *parent() const { return m_parent; }
00049 private:
00050 unsigned int _ref;
00051 protected:
00052 type *m_parent;
00053 };
00054
00055 }
00056
00057 #endif
This file is part of the documentation for kdelibs Version 3.1.4.