• Skip to content
  • Skip to link menu
KDE 4.4 API Reference
  • KDE API Reference
  • KDevelop Platform Libraries
  • Sitemap
  • Contact Us
 

util

ksharedobject.h

00001 /*
00002    Copyright 2009 David Nolden <david.nolden.kdevelop@art-master.de>
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 
00019 #ifndef KSHAREDOBJECT_H
00020 #define KSHAREDOBJECT_H
00021 
00022 #include <KDE/KSharedPtr>
00023 #include <QtCore/QObject>
00024 
00034 namespace KDevelop {
00035 
00036 struct FakeAtomic {
00037     inline FakeAtomic(QObject& object, QSharedData& real) : m_object(object), m_real(real) {
00038     }
00039     inline operator int() const {
00040       if(!m_real.ref)
00041           return 1; //Always return true, because we handle the deleting by ourself using deleteLater
00042       return m_real.ref;
00043     }
00044     
00045     inline bool ref() {
00046       return m_real.ref.ref();
00047     }
00048     
00049     inline bool deref() {
00050       bool ret = m_real.ref.deref();
00051       if(!ret)
00052         m_object.deleteLater();
00053 
00054       return true; //Always return true, because we handle the deleting by ourself
00055     }
00056     
00057     QObject& m_object;
00058     QSharedData& m_real;
00059 };
00060 
00061 struct KSharedObject : public KShared {
00062   inline KSharedObject(QObject& object) : ref(object, *this) {
00063   }
00064   
00065   mutable FakeAtomic ref;
00066 };
00067 
00068 }
00069 
00070 #endif

util

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

KDevelop Platform Libraries

Skip menu "KDevelop Platform Libraries"
  • interfaces
  • language
  •   codegen
  •   duchain
  •   editor
  • outputview
  • project
  • shell
  • sublime
  • util
  • vcs
Generated for KDevelop Platform Libraries by doxygen 1.5.9-20090814
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