Warning, /frameworks/kdelibs4support/src/kdemacros.h.cmake is written in an unsupported language. File is not indexed.

0001 /* This file is part of the KDE libraries
0002     Copyright (c) 2002-2003 KDE Team
0003 
0004     This library is free software; you can redistribute it and/or
0005     modify it under the terms of the GNU Library General Public
0006     License as published by the Free Software Foundation; either
0007     version 2 of the License, or (at your option) any later version.
0008 
0009     This library is distributed in the hope that it will be useful,
0010     but WITHOUT ANY WARRANTY; without even the implied warranty of
0011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012     Library General Public License for more details.
0013 
0014     You should have received a copy of the GNU Library General Public License
0015     along with this library; see the file COPYING.LIB.  If not, write to
0016     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017     Boston, MA 02110-1301, USA.
0018 */
0019 
0020 /**
0021  * @file kdemacros.h
0022  *
0023  * This header defines several compiler-independent macros which are used
0024  * throughout KDE. Most of these macros make use of GCC extensions; on other
0025  * compilers, they don't have any effect.
0026  */
0027 
0028 #ifndef _KDE_MACROS_H_
0029 #define _KDE_MACROS_H_
0030 
0031 #cmakedefine __KDE_HAVE_GCC_VISIBILITY
0032 
0033 /**
0034  * @def KDE_NO_EXPORT
0035  * @ingroup KDEMacros
0036  *
0037  * The KDE_NO_EXPORT macro marks the symbol of the given variable
0038  * to be hidden. A hidden symbol is stripped during the linking step,
0039  * so it can't be used from outside the resulting library, which is similar
0040  * to static. However, static limits the visibility to the current
0041  * compilation unit. Hidden symbols can still be used in multiple compilation
0042  * units.
0043  *
0044  * \code
0045  * int KDE_NO_EXPORT foo;
0046  * int KDE_EXPORT bar;
0047  * \endcode
0048  *
0049  * @sa KDE_EXPORT
0050  */
0051 
0052 /**
0053  * @def KDE_EXPORT
0054  * @ingroup KDEMacros
0055  *
0056  * The KDE_EXPORT macro marks the symbol of the given variable
0057  * to be visible, so it can be used from outside the resulting library.
0058  *
0059  * \code
0060  * int KDE_NO_EXPORT foo;
0061  * int KDE_EXPORT bar;
0062  * \endcode
0063  *
0064  * @sa KDE_NO_EXPORT
0065  */
0066 
0067 /**
0068  * @def KDE_IMPORT
0069  * @ingroup KDEMacros
0070  */
0071 
0072 #ifdef __KDE_HAVE_GCC_VISIBILITY
0073 #define KDE_NO_EXPORT __attribute__ ((visibility("hidden")))
0074 #define KDE_EXPORT __attribute__ ((visibility("default")))
0075 #define KDE_IMPORT __attribute__ ((visibility("default")))
0076 #elif defined(_WIN32) || defined(_WIN64)
0077 #define KDE_NO_EXPORT
0078 #define KDE_EXPORT __declspec(dllexport)
0079 #define KDE_IMPORT __declspec(dllimport)
0080 #else
0081 #define KDE_NO_EXPORT
0082 #define KDE_EXPORT
0083 #define KDE_IMPORT
0084 #endif
0085 
0086 /**
0087  * @def KDE_PACKED
0088  * @ingroup KDEMacros
0089  *
0090  * The KDE_PACKED macro can be used to hint the compiler that a particular
0091  * structure or class should not contain unnecessary paddings.
0092  */
0093 
0094 #ifdef __GNUC__
0095 #define KDE_PACKED __attribute__((__packed__))
0096 #else
0097 #define KDE_PACKED
0098 #endif
0099 
0100 /**
0101  * @def KDE_DEPRECATED
0102  * @ingroup KDEMacros
0103  *
0104  * The KDE_DEPRECATED macro can be used to trigger compile-time warnings
0105  * with newer compilers when deprecated functions are used.
0106  *
0107  * For non-inline functions, the macro gets inserted at front of the
0108  * function declaration, right before the return type:
0109  *
0110  * \code
0111  * KDE_DEPRECATED void deprecatedFunctionA();
0112  * KDE_DEPRECATED int deprecatedFunctionB() const;
0113  * \endcode
0114  *
0115  * For functions which are implemented inline,
0116  * the KDE_DEPRECATED macro is inserted at the front, right before the return
0117  * type, but after "static", "inline" or "virtual":
0118  *
0119  * \code
0120  * KDE_DEPRECATED void deprecatedInlineFunctionA() { .. }
0121  * virtual KDE_DEPRECATED int deprecatedInlineFunctionB() { .. }
0122  * static KDE_DEPRECATED bool deprecatedInlineFunctionC() { .. }
0123  * inline KDE_DEPRECATED bool deprecatedInlineFunctionD() { .. }
0124  * \endcode
0125  *
0126  * You can also mark whole structs or classes as deprecated, by inserting the
0127  * KDE_DEPRECATED macro after the struct/class keyword, but before the
0128  * name of the struct/class:
0129  *
0130  * \code
0131  * class KDE_DEPRECATED DeprecatedClass { };
0132  * struct KDE_DEPRECATED DeprecatedStruct { };
0133  * \endcode
0134  *
0135  * \note
0136  * It does not make much sense to use the KDE_DEPRECATED keyword for a Qt signal;
0137  * this is because usually get called by the class which they belong to,
0138  * and one would assume that a class author does not use deprecated methods of
0139  * his own class. The only exception to this are signals which are connected to
0140  * other signals; they get invoked from moc-generated code. In any case,
0141  * printing a warning message in either case is not useful.
0142  * For slots, it can make sense (since slots can be invoked directly) but be
0143  * aware that if the slots get triggered by a signal, the will get called from
0144  * moc code as well and thus the warnings are useless.
0145  *
0146  * \par
0147  * Also note that it is not possible to use KDE_DEPRECATED for classes which
0148  * use the k_dcop keyword (to indicate a DCOP interface declaration); this is
0149  * because the dcopidl program would choke on the unexpected declaration
0150  * syntax.
0151  *
0152  * \note
0153  * KDE_DEPRECATED cannot be used at the end of the declaration anymore,
0154  * unlike what is done for KDE3.
0155  *
0156  * \note
0157  * KDE_DEPRECATED cannot be used for constructors, 
0158  * use KDE_CONSTRUCTOR_DEPRECATED instead.
0159  */
0160 
0161 #ifdef __cplusplus
0162 # include <QtCore/qglobal.h>
0163 # ifndef KDE_DEPRECATED
0164 #  ifdef KDE_DEPRECATED_WARNINGS
0165 #   define KDE_DEPRECATED Q_DECL_DEPRECATED
0166 #  else
0167 #   define KDE_DEPRECATED
0168 #  endif
0169 # endif
0170 #endif
0171 
0172 /**
0173  * @def KDE_CONSTRUCTOR_DEPRECATED
0174  * @ingroup KDEMacros
0175  *
0176  * The KDE_CONSTRUCTOR_DEPRECATED macro can be used to trigger compile-time
0177  * warnings with newer compilers when deprecated constructors are used.
0178  *
0179  * For non-inline constructors, the macro gets inserted at front of the
0180  * constructor declaration, right before the return type:
0181  *
0182  * \code
0183  * KDE_CONSTRUCTOR_DEPRECATED classA();
0184  * \endcode
0185  *
0186  * For constructors which are implemented inline,
0187  * the KDE_CONSTRUCTOR_DEPRECATED macro is inserted at the front,
0188  * but after the "inline" keyword:
0189  *
0190  * \code
0191  * KDE_CONSTRUCTOR_DEPRECATED classA() { .. }
0192  * \endcode
0193  *
0194  * \note Do not forget that inlined constructors are not allowed in public
0195  * headers for KDE.
0196  */
0197 
0198 // QT5 KF5 TODO: Mark this macro deprecated or remove it entirely.
0199 #ifndef KDE_CONSTRUCTOR_DEPRECATED
0200 # ifdef __GNUC__
0201 #  if __GNUC__ == 3 && __GNUC_MINOR__ <= 3 
0202     /* GCC 3.3.x cannot handle Qt 4.1.2's definition of Q_DECL_CONSTRUCTOR_DEPRECATED */
0203 #   define KDE_CONSTRUCTOR_DEPRECATED
0204 #  else
0205 #   define KDE_CONSTRUCTOR_DEPRECATED Q_DECL_DEPRECATED
0206 #  endif
0207 # else
0208 #  define KDE_CONSTRUCTOR_DEPRECATED Q_DECL_DEPRECATED
0209 # endif
0210 #endif
0211 
0212 /**
0213  * @def KDELIBS4SUPPORT_NO_DEPRECATED
0214  * @ingroup KDEMacros
0215  *
0216  * The KDELIBS4SUPPORT_NO_DEPRECATED indicates if the deprecated symbols of the platform
0217  * have been compiled out.
0218  */
0219 #cmakedefine KDELIBS4SUPPORT_NO_DEPRECATED
0220 
0221 /**
0222  * @def KDE_ISLIKELY
0223  * @ingroup KDEMacros
0224  *
0225  * The KDE_ISLIKELY macro tags a boolean expression as likely to evaluate to
0226  * @c true. When used in an <tt>if ( )</tt> statement, it gives a hint to the compiler
0227  * that the following codeblock is likely to get executed. Providing this
0228  * information helps the compiler to optimize the code for better performance.
0229  * Using the macro has an insignificant code size or runtime memory footprint impact.
0230  * The code semantics is not affected.
0231  *
0232  * Example:
0233  *
0234  * \code
0235  * if ( KDE_ISLIKELY( testsomething() ) )
0236  *     abort();     // assume its likely that the application aborts
0237  * \endcode
0238  *
0239  * \note
0240  * Providing wrong information ( like marking a condition that almost never
0241  * passes as 'likely' ) will cause a significant runtime slowdown. Therefore only
0242  * use it for cases where you can be sure about the odds of the expression to pass
0243  * in all cases ( independent from e.g. user configuration ).
0244  *
0245  * \note
0246  * Do NOT use ( !KDE_ISLIKELY(foo) ) as an replacement for KDE_ISUNLIKELY() !
0247  *
0248  * @sa KDE_ISUNLIKELY
0249  */
0250 
0251 /**
0252  * @def KDE_ISUNLIKELY
0253  * @ingroup KDEMacros
0254  *
0255  * The KDE_ISUNLIKELY macro tags a boolean expression as likely to evaluate to
0256  * @c false. When used in an <tt>if ( )</tt> statement, it gives a hint to the compiler
0257  * that the following codeblock is unlikely to get executed. Providing this
0258  * information helps the compiler to optimize the code for better performance.
0259  * Using the macro has an insignificant code size or runtime memory footprint impact.
0260  * The code semantics is not affected.
0261  *
0262  * Example:
0263  *
0264  * \code
0265  * if ( KDE_ISUNLIKELY( testsomething() ) )
0266  *     abort();     // assume its unlikely that the application aborts
0267  * \endcode
0268  *
0269  * \note
0270  * Providing wrong information ( like marking a condition that almost never
0271  * passes as 'unlikely' ) will cause a significant runtime slowdown. Therefore only
0272  * use it for cases where you can be sure about the odds of the expression to pass
0273  * in all cases ( independent from e.g. user configuration ).
0274  *
0275  * \note
0276  * Do NOT use ( !KDE_ISUNLIKELY(foo) ) as an replacement for KDE_ISLIKELY() !
0277  *
0278  * @sa KDE_ISLIKELY
0279  */
0280 
0281 #if defined(__GNUC__) && __GNUC__ - 0 >= 3
0282 # define KDE_ISLIKELY( x )    __builtin_expect(!!(x),1)
0283 # define KDE_ISUNLIKELY( x )  __builtin_expect(!!(x),0)
0284 #else
0285 # define KDE_ISLIKELY( x )   ( x )
0286 # define KDE_ISUNLIKELY( x )  ( x )
0287 #endif
0288 
0289 
0290 /**
0291  * @ingroup KDEMacros
0292  * This macro, and it's friends going up to 10 reserve a fixed number of virtual
0293  * functions in a class.  Because adding virtual functions to a class changes the
0294  * size of the vtable, adding virtual functions to a class breaks binary
0295  * compatibility.  However, by using this macro, and decrementing it as new
0296  * virtual methods are added, binary compatibility can still be preserved.
0297  *
0298  * \note The added functions must be added to the header at the same location
0299  * as the macro; changing the order of virtual functions in a header is also
0300  * binary incompatible as it breaks the layout of the vtable.
0301  */
0302 #define RESERVE_VIRTUAL_1 \
0303     virtual void reservedVirtual1() {}
0304 /**
0305  * @ingroup KDEMacros
0306  */
0307 #define RESERVE_VIRTUAL_2 \
0308     virtual void reservedVirtual2() {} \
0309     RESERVE_VIRTUAL_1
0310 /**
0311  * @ingroup KDEMacros
0312  */
0313 #define RESERVE_VIRTUAL_3 \
0314     virtual void reservedVirtual3() {} \
0315     RESERVE_VIRTUAL_2
0316 /**
0317  * @ingroup KDEMacros
0318  */
0319 #define RESERVE_VIRTUAL_4 \
0320     virtual void reservedVirtual4() {} \
0321     RESERVE_VIRTUAL_3
0322 /**
0323  * @ingroup KDEMacros
0324  */
0325 #define RESERVE_VIRTUAL_5 \
0326     virtual void reservedVirtual5() {} \
0327     RESERVE_VIRTUAL_4
0328 /**
0329  * @ingroup KDEMacros
0330  */
0331 #define RESERVE_VIRTUAL_6 \
0332     virtual void reservedVirtual6() {} \
0333     RESERVE_VIRTUAL_5
0334 /**
0335  * @ingroup KDEMacros
0336  */
0337 #define RESERVE_VIRTUAL_7 \
0338     virtual void reservedVirtual7() {} \
0339     RESERVE_VIRTUAL_6
0340 /**
0341  * @ingroup KDEMacros
0342  */
0343 #define RESERVE_VIRTUAL_8 \
0344     virtual void reservedVirtual8() {} \
0345     RESERVE_VIRTUAL_7
0346 /**
0347  * @ingroup KDEMacros
0348  */
0349 #define RESERVE_VIRTUAL_9 \
0350     virtual void reservedVirtual9() {} \
0351     RESERVE_VIRTUAL_8
0352 #define RESERVE_VIRTUAL_10 \
0353     virtual void reservedVirtual10() {} \
0354     RESERVE_VIRTUAL_9
0355 
0356 /**
0357  * @def KDE_FULL_TEMPLATE_EXPORT_INSTANTIATION
0358  * @ingroup KDEMacros
0359  *
0360  * From Qt's global.h:
0361  * Compilers which follow outdated template instantiation rules
0362  * require a class to have a comparison operator to exist when
0363  * a QList of this type is instantiated. It's not actually
0364  * used in the list, though. Hence the dummy implementation.
0365  * Just in case other code relies on it we better trigger a warning
0366  * mandating a real implementation.
0367  *
0368  * In KDE we need this for classes which are exported in a shared
0369  * lib because some compilers need a full instantiated class then.
0370  *
0371  * @sa KDE_DUMMY_COMPARISON_OPERATOR
0372  * @sa KDE_DUMMY_QHASH_FUNCTION
0373  */
0374 
0375 /**
0376  * @def KDE_DUMMY_COMPARISON_OPERATOR
0377  * @ingroup KDEMacros
0378  *
0379  * The KDE_DUMMY_COMPARISON_OPERATOR defines a simple
0380  * compare operator for classes.
0381  *
0382  * @sa KDE_FULL_TEMPLATE_EXPORT_INSTANTIATION
0383  * @sa KDE_DUMMY_QHASH_FUNCTION
0384  */
0385 
0386 /**
0387  * @def KDE_DUMMY_QHASH_FUNCTION
0388  * @ingroup KDEMacros
0389  *
0390  * The KDE_DUMMY_QHASH_FUNCTION defines a simple
0391  * hash-function for classes. 
0392  *
0393  * @sa KDE_FULL_TEMPLATE_EXPORT_INSTANTIATION
0394  * @sa KDE_DUMMY_COMPARISON_OPERATOR
0395  */
0396 
0397 #ifdef _MSC_VER
0398 # ifndef KDE_FULL_TEMPLATE_EXPORT_INSTANTIATION
0399 #  define KDE_FULL_TEMPLATE_EXPORT_INSTANTIATION
0400 # endif
0401 #endif
0402 
0403 #ifdef KDE_FULL_TEMPLATE_EXPORT_INSTANTIATION
0404 # define KDE_DUMMY_COMPARISON_OPERATOR(C) \
0405     bool operator==(const C&) const { \
0406         qWarning(#C"::operator==(const "#C"&) was called"); \
0407         return false; \
0408     }
0409 # define KDE_DUMMY_QHASH_FUNCTION(C) \
0410     inline uint qHash(const C) { \
0411         qWarning("inline uint qHash(const "#C") was called"); \
0412         return 0; \
0413     }
0414 #else
0415 # define KDE_DUMMY_COMPARISON_OPERATOR(C)
0416 # define KDE_DUMMY_QHASH_FUNCTION(C)
0417 #endif
0418 
0419 /**
0420  * @def KDE_BF_ENUM
0421  * @ingroup KDEMacros
0422  *
0423  * The KDE_BF_ENUM is used when storing an enum
0424  * in a bitfield, to ensure correct conversion
0425  * by all compilers.
0426  *
0427  * @sa KDE_CAST_BF_ENUM
0428  */
0429 
0430 /**
0431  * @def KDE_CAST_BF_ENUM
0432  * @ingroup KDEMacros
0433  *
0434  * The KDE_CAST_BF_ENUM is used when retrieving an
0435  * enum from a bitfield, to ensure correct conversion
0436  * by all compilers.
0437  *
0438  * @sa KDE_BF_ENUM
0439  */
0440 
0441 #ifdef Q_CC_MSVC
0442 # define KDE_BF_ENUM(a) unsigned int
0443 # define KDE_CAST_BF_ENUM(a,b) static_cast<a>(b)
0444 #else
0445 # define KDE_BF_ENUM(a) a
0446 # define KDE_CAST_BF_ENUM(a,b) b
0447 #endif
0448 
0449 /**
0450  * @def KDE_WEAK_SYMBOL
0451  * @ingroup KDEMacros
0452  *
0453  * The KDE_WEAK_SYMBOL macro can be used to tell the compiler that
0454  * a particular function should be a weak symbol (that e.g. may be overridden
0455  * in another library, -Bdirect will not bind this symbol directly)
0456  */
0457 
0458 #ifdef __GNUC__
0459 #define KDE_WEAK_SYMBOL __attribute__((__weak__))
0460 #else
0461 #define KDE_WEAK_SYMBOL
0462 #endif
0463 
0464 
0465 /**
0466  * @def KDE_MUST_USE_RESULT
0467  * @ingroup KDEMacros
0468  *
0469  * The KDE_MUST_USE_RESULT macro can be used to tell the compiler that
0470  * a particular functions return value must be checked.
0471  */
0472 
0473 #ifdef __GNUC__
0474 #define KDE_MUST_USE_RESULT __attribute__((__warn_unused_result__))
0475 #else
0476 #define KDE_MUST_USE_RESULT
0477 #endif
0478 
0479 
0480 
0481 #endif /* _KDE_MACROS_H_ */