shared.h Source File (khtml Library)

| # khtml Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# 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; /*counter++;*/ }
    00010     ~Shared() { /*counter--;*/ }
    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() { //kdDebug(300) << "ref=" << _ref << endl;
    00019         return _ref==1; }
    00020
    00021     int refCount() const { return _ref; }
    00022 //    static int counter;
    00023 protected:
    00024     unsigned int _ref;
    00025 };
    00026
    00027 template<class type> class TreeShared
    00028 {
    00029 public:
    00030     TreeShared() { _ref = 0; m_parent = 0; /*counter++;*/ }
    00031     TreeShared( type *parent ) { _ref=0; m_parent = parent; /*counter++;*/ }
    00032     ~TreeShared() { /*counter--;*/ }
    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() { //kdDebug(300) << "ref=" << _ref << endl;
    00042         return _ref==1; }
    00043
    00044     int refCount() const { return _ref; }
    00045 //    static int counter;
    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.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 13:34:44 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001