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

KDECore

kglobal.h

Go to the documentation of this file.
00001 /* This file is part of the KDE libraries
00002    Copyright (C) 1999 Sirtaj Singh Kanq <taj@kde.org>
00003    Copyright (C) 2007 Matthias Kretz <kretz@kde.org>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License version 2 as published by the Free Software Foundation.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017    Boston, MA 02110-1301, USA.
00018 */
00019 #ifndef _KGLOBAL_H
00020 #define _KGLOBAL_H
00021 
00022 #include <kdecore_export.h>
00023 #include <QtCore/QAtomicPointer>
00024 #include <sys/types.h>
00025 
00026 
00027 //
00028 // WARNING!!
00029 // This code uses undocumented Qt API
00030 // Do not copy it to your application! Use only the functions that are here!
00031 // Otherwise, it could break when a new version of Qt ships.
00032 //
00033 
00034 class KComponentData;
00035 class KCharsets;
00036 class KConfig;
00037 class KLocale;
00038 class KStandardDirs;
00039 class KSharedConfig;
00040 template <typename T>
00041 class KSharedPtr;
00042 typedef KSharedPtr<KSharedConfig> KSharedConfigPtr;
00043 
00045 
00049 typedef void (*KdeCleanUpFunction)();
00050 
00057 class KCleanUpGlobalStatic
00058 {
00059     public:
00060         KdeCleanUpFunction func;
00061 
00062         inline ~KCleanUpGlobalStatic() { func(); }
00063 };
00064 
00065 #ifdef Q_CC_MSVC
00066 
00072 # define K_GLOBAL_STATIC_STRUCT_NAME(NAME) _k_##NAME##__LINE__
00073 #else
00074 
00079 # define K_GLOBAL_STATIC_STRUCT_NAME(NAME)
00080 #endif
00081 
00083 
00221 #define K_GLOBAL_STATIC(TYPE, NAME) K_GLOBAL_STATIC_WITH_ARGS(TYPE, NAME, ())
00222 
00255 #define K_GLOBAL_STATIC_WITH_ARGS(TYPE, NAME, ARGS)                            \
00256 static QBasicAtomicPointer<TYPE > _k_static_##NAME = Q_BASIC_ATOMIC_INITIALIZER(0); \
00257 static bool _k_static_##NAME##_destroyed;                                      \
00258 static struct K_GLOBAL_STATIC_STRUCT_NAME(NAME)                                \
00259 {                                                                              \
00260     inline bool isDestroyed() const                                            \
00261     {                                                                          \
00262         return _k_static_##NAME##_destroyed;                                   \
00263     }                                                                          \
00264     inline bool exists() const                                                 \
00265     {                                                                          \
00266         return _k_static_##NAME != 0;                                          \
00267     }                                                                          \
00268     inline operator TYPE*()                                                    \
00269     {                                                                          \
00270         return operator->();                                                   \
00271     }                                                                          \
00272     inline TYPE *operator->()                                                  \
00273     {                                                                          \
00274         if (!_k_static_##NAME) {                                               \
00275             if (isDestroyed()) {                                               \
00276                 qFatal("Fatal Error: Accessed global static '%s *%s()' after destruction. " \
00277                        "Defined at %s:%d", #TYPE, #NAME, __FILE__, __LINE__);  \
00278             }                                                                  \
00279             TYPE *x = new TYPE ARGS;                                           \
00280             if (!_k_static_##NAME.testAndSetOrdered(0, x)                      \
00281                 && _k_static_##NAME != x ) {                                   \
00282                 delete x;                                                      \
00283             } else {                                                           \
00284                 static KCleanUpGlobalStatic cleanUpObject = { destroy };       \
00285             }                                                                  \
00286         }                                                                      \
00287         return _k_static_##NAME;                                               \
00288     }                                                                          \
00289     inline TYPE &operator*()                                                   \
00290     {                                                                          \
00291         return *operator->();                                                  \
00292     }                                                                          \
00293     static void destroy()                                                      \
00294     {                                                                          \
00295         _k_static_##NAME##_destroyed = true;                                   \
00296         TYPE *x = _k_static_##NAME;                                            \
00297         _k_static_##NAME = 0;                                                  \
00298         delete x;                                                              \
00299     }                                                                          \
00300 } NAME;
00301 
00311 namespace KGlobal
00312 {
00313 
00320     KDECORE_EXPORT const KComponentData &mainComponent(); //krazy:exclude=constref (don't mess up ref-counting)
00321 
00326     KDECORE_EXPORT bool hasMainComponent();
00327 
00332     KDECORE_EXPORT KStandardDirs *dirs();
00333 
00338     KDECORE_EXPORT KSharedConfigPtr config();
00339 
00344     KDECORE_EXPORT KLocale *locale();
00349     KDECORE_EXPORT bool hasLocale();
00350 
00355     KDECORE_EXPORT KCharsets *charsets();
00356 
00361     KDECORE_EXPORT mode_t umask();
00362 
00380     KDECORE_EXPORT const QString& staticQString(const char *str); //krazy:exclude=constref (doesn't make sense otherwise)
00381 
00399     KDECORE_EXPORT const QString& staticQString(const QString &str); //krazy:exclude=constref (doesn't make sense otherwise)
00400 
00422     KDECORE_EXPORT void ref();
00423 
00428     KDECORE_EXPORT void deref();
00429 
00445     KDECORE_EXPORT void setAllowQuit(bool allowQuit);
00446 
00453     KDECORE_EXPORT KComponentData activeComponent();
00454 
00461     KDECORE_EXPORT void setActiveComponent(const KComponentData &d);
00462 
00471     KDECORE_EXPORT QString caption();
00472 
00476     enum CopyCatalogs { DoCopyCatalogs, DontCopyCatalogs};
00477 
00479     KDECORE_EXPORT void setLocale(KLocale *, CopyCatalogs copy = DoCopyCatalogs);
00480 }
00481 
00482 #ifdef KDE_SUPPORT
00483 
00488 #define KMIN(a,b)   qMin(a,b)
00489 
00494 #define KMAX(a,b)   qMax(a,b)
00495 
00500 #define KABS(a) qAbs(a)
00501 
00507 #define KCLAMP(x,low,high) qBound(low,x,high)
00508 
00509 #define kMin qMin
00510 #define kMax qMax
00511 #define kAbs qAbs
00512 
00520 template<class T>
00521 inline KDE_DEPRECATED T kClamp( const T& x, const T& low, const T& high )
00522 {
00523     if ( x < low )       return low;
00524     else if ( high < x ) return high;
00525                          return x;
00526 }
00527 
00528 #endif
00529 
00530 #endif // _KGLOBAL_H
00531 

KDECore

Skip menu "KDECore"
  • Main Page
  • Modules
  • 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
  • KPty
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.6.1
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