• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdecore
 

tdecore

ksharedptr.h
00001 /* This file is part of the KDE libraries
00002    Copyright (c) 1999 Waldo Bastian <bastian@kde.org>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License version 2 as published by the Free Software Foundation.
00007 
00008    This library is distributed in the hope that it will be useful,
00009    but WITHOUT ANY WARRANTY; without even the implied warranty of
00010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011    Library General Public License for more details.
00012 
00013    You should have received a copy of the GNU Library General Public License
00014    along with this library; see the file COPYING.LIB.  If not, write to
00015    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00016    Boston, MA 02110-1301, USA.
00017 */
00018 #ifndef TDESharedPTR_H
00019 #define TDESharedPTR_H
00020 
00021 #include "tdelibs_export.h"
00022 
00040 class TDECORE_EXPORT TDEShared {
00041 public:
00046    TDEShared() : count(0) { }
00047 
00052    TDEShared( const TDEShared & ) : count(0) { }
00053 
00057    TDEShared &operator=(const TDEShared & ) { return *this; }
00058 
00062    void _TDEShared_ref() const { count++; }
00063 
00068    void _TDEShared_unref() const { if (!--count) delete this; }
00069 
00075    int _TDEShared_count() const { return count; }
00076 
00077 protected:
00078    virtual ~TDEShared() { }
00079 private:
00080    mutable int count;
00081 };
00082 
00099 template< class T >
00100 class TDESharedPtr
00101 {
00102 public:
00106   TDESharedPtr()
00107     : ptr(0) { }
00112   TDESharedPtr( T* t )
00113     : ptr(t) { if ( ptr ) ptr->_TDEShared_ref(); }
00114 
00119   TDESharedPtr( const TDESharedPtr& p )
00120     : ptr(p.ptr) { if ( ptr ) ptr->_TDEShared_ref(); }
00121 
00126   ~TDESharedPtr() { if ( ptr ) ptr->_TDEShared_unref(); }
00127 
00128   TDESharedPtr<T>& operator= ( const TDESharedPtr<T>& p ) {
00129     if ( ptr == p.ptr ) return *this;
00130     if ( ptr ) ptr->_TDEShared_unref();
00131     ptr = p.ptr;
00132     if ( ptr ) ptr->_TDEShared_ref();
00133     return *this;
00134   }
00135   TDESharedPtr<T>& operator= ( T* p ) {
00136     if ( ptr == p ) return *this;
00137     if ( ptr ) ptr->_TDEShared_unref();
00138     ptr = p;
00139     if ( ptr ) ptr->_TDEShared_ref();
00140     return *this;
00141   }
00142   bool operator== ( const TDESharedPtr<T>& p ) const { return ( ptr == p.ptr ); }
00143   bool operator!= ( const TDESharedPtr<T>& p ) const { return ( ptr != p.ptr ); }
00144   bool operator== ( const T* p ) const { return ( ptr == p ); }
00145   bool operator!= ( const T* p ) const { return ( ptr != p ); }
00146   bool operator!() const { return ( ptr == 0 ); }
00147   operator T*() const { return ptr; }
00148 
00153   T* data() { return ptr; }
00154 
00159   const T* data() const { return ptr; }
00160 
00161   const T& operator*() const { return *ptr; }
00162   T& operator*() { return *ptr; }
00163   const T* operator->() const { return ptr; }
00164   T* operator->() { return ptr; }
00165 
00170   int count() const { return ptr->_TDEShared_count(); } // for debugging purposes
00171 private:
00172   T* ptr;
00173 };
00174 
00175 #endif

tdecore

Skip menu "tdecore"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdecore

Skip menu "tdecore"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdecore by doxygen 1.7.6.1
This website is maintained by Timothy Pearson.