• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdepim
  • Sitemap
  • Contact Us
 

kleopatra

checker.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 ** Copyright (C) 2001-2007 Klarälvdalens Datakonsult AB.  All rights reserved.
00003 **
00004 ** This file is part of the KD Tools library.
00005 **
00006 ** This file may be distributed and/or modified under the terms of the
00007 ** GNU General Public License version 2 as published by the Free Software
00008 ** Foundation and appearing in the file LICENSE.GPL included in the
00009 ** packaging of this file.
00010 **
00011 ** Licensees holding valid commercial KD Tools licenses may use this file in
00012 ** accordance with the KD Tools Commercial License Agreement provided with
00013 ** the Software.
00014 **
00015 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00016 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00017 **
00018 ** Contact info@klaralvdalens-datakonsult.se if any conditions of this
00019 ** licensing are not clear to you.
00020 **
00021 **********************************************************************/
00022 
00023 #ifndef __KDABTOOLS__CPP__CHECKER_H__
00024 #define __KDABTOOLS__CPP__CHECKER_H__
00025 
00026 #include "kdtoolsglobal.h"
00027 
00028 #include <cstdlib>
00029 
00068 class __KDAB__CheckerImplBase {
00069 public:
00070     virtual ~__KDAB__CheckerImplBase() {}
00071     virtual void checkInvariants() const = 0;
00072 };
00073 
00074 template <typename T_Class>
00075 class __KDAB__CheckerImpl : public __KDAB__CheckerImplBase {
00076     KDAB_DISABLE_COPY( __KDAB__CheckerImpl );
00077     const T_Class * const p;
00078 public:
00079     __KDAB__CheckerImpl( const T_Class * t )
00080         : __KDAB__CheckerImplBase(), p( t ) {}
00081     void checkInvariants() const {
00082         try {
00083             p->__KDAB_Checker__checkInvariants__();
00084         } catch( ... ) {
00085             std::abort();
00086         }
00087     }
00088 };
00089 
00090 template <bool check_in_ctor, bool check_in_dtor>
00091 class __KDAB__Checker {
00092     KDAB_DISABLE_COPY( __KDAB__Checker );
00093     const __KDAB__CheckerImplBase * const checker;
00094 public:
00095     template <typename T_Class>
00096     __KDAB__Checker( const T_Class * t )
00097         : checker( new __KDAB__CheckerImpl<T_Class>( t ) )
00098     {
00099         if ( check_in_ctor )
00100             checker->checkInvariants();
00101     }
00102     ~__KDAB__Checker() {
00103         if ( check_in_dtor )
00104             checker->checkInvariants();
00105         delete checker;
00106     }
00107 };
00108 
00109 #define KDAB_MAKE_CHECKABLE( Class ) \
00110     private:                         \
00111     void __KDAB_Checker__checkInvariants__() const;    \
00112     friend class __KDAB__CheckerImpl<Class>;
00113 
00114 #define KDAB_DEFINE_CHECKS( Class )                             \
00115     void Class::__KDAB_Checker__checkInvariants__() const
00116 
00117 #ifndef NDEBUG
00118 # define __KDAB_CHECK_HELPER__( ctor, dtor ) \
00119     const __KDAB__Checker<ctor,dtor> __checker_uglified__( this )
00120 #else
00121 # define __KDAB_CHECK_HELPER__( ctor, dtor ) \
00122     do {} while (0)
00123 #endif
00124 
00125 #define KDAB_CHECK_THIS __KDAB_CHECK_HELPER__( true, true )
00126 #define KDAB_CHECK_CTOR __KDAB_CHECK_HELPER__( false, true )
00127 #define KDAB_CHECK_DTOR __KDAB_CHECK_HELPER__( true, false )
00128 
00129 #endif /* __KDABTOOLS__CPP__CHECKER_H__ */
00130 

kleopatra

Skip menu "kleopatra"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

kdepim

Skip menu "kdepim"
  • akonadi
  •   clients
  •   kabc
  •   kcal
  •   kcm
  • akregator
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt
  • kdgantt1
  • kjots
  • kleopatra
  • kmail
  • kmobiletools
  • knode
  • knotes
  • kontact
  • kontactinterfaces
  • korganizer
  •   korgac
  • kpilot
  • ktimetracker
  • libkdepim
  • libkholidays
  • libkleo
  • libkpgp
  • maildir
Generated for kdepim 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