• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

WTF

ListRefPtr.h

Go to the documentation of this file.
00001 // -*- mode: c++; c-basic-offset: 4 -*-
00002 /*
00003  *  This file is part of the KDE libraries
00004  *  Copyright (C) 2005 Apple Computer, Inc.
00005  *
00006  *  This library is free software; you can redistribute it and/or
00007  *  modify it under the terms of the GNU Library General Public
00008  *  License as published by the Free Software Foundation; either
00009  *  version 2 of the License, or (at your option) any later version.
00010  *
00011  *  This library is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  *  Library General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU Library General Public License
00017  *  along with this library; see the file COPYING.LIB.  If not, write to
00018  *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019  *  Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #ifndef WTF_ListRefPtr_h
00024 #define WTF_ListRefPtr_h
00025 
00026 #include "RefPtr.h"
00027 
00028 namespace WTF {
00029 
00030     // Specialized version of RefPtr desgined for use in singly-linked lists.
00031     // Derefs the list iteratively to avoid recursive derefing that can overflow the stack.
00032     template <typename T> class ListRefPtr : public RefPtr<T>
00033     {
00034     public:
00035         ListRefPtr() : RefPtr<T>() {}
00036         ListRefPtr(T *ptr) : RefPtr<T>(ptr) {}
00037         ListRefPtr(const RefPtr<T>& o) : RefPtr<T>(o) {}
00038         // see comment in PassRefPtr.h for why this takes const reference
00039         template <typename U> ListRefPtr(const PassRefPtr<U>& o) : RefPtr<T>(o) {}
00040 
00041         ~ListRefPtr() {
00042             RefPtr<T> reaper = this->release();
00043             while (reaper && reaper->refcount() == 1)
00044                 reaper = reaper->releaseNext(); // implicitly protects reaper->next, then derefs reaper
00045         }
00046 
00047         ListRefPtr& operator=(T *optr) { RefPtr<T>::operator=(optr); return *this; }
00048         ListRefPtr& operator=(const RefPtr<T>& o) { RefPtr<T>::operator=(o); return *this; }
00049         ListRefPtr& operator=(const PassRefPtr<T>& o) { RefPtr<T>::operator=(o); return *this; }
00050         template <typename U> ListRefPtr& operator=(const RefPtr<U>& o) { RefPtr<T>::operator=(o); return *this; }
00051         template <typename U> ListRefPtr& operator=(const PassRefPtr<U>& o) { RefPtr<T>::operator=(o); return *this; }
00052     };
00053 
00054 } // namespace WTF
00055 
00056 using WTF::ListRefPtr;
00057 
00058 #endif // WTF_ListRefPtr_h
00059 

WTF

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • KIO
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal