UDK 3.2.7 C/C++ API Reference
|
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 00002 /************************************************************************* 00003 * 00004 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 00005 * 00006 * Copyright 2000, 2010 Oracle and/or its affiliates. 00007 * 00008 * OpenOffice.org - a multi-platform office productivity suite 00009 * 00010 * This file is part of OpenOffice.org. 00011 * 00012 * OpenOffice.org is free software: you can redistribute it and/or modify 00013 * it under the terms of the GNU Lesser General Public License version 3 00014 * only, as published by the Free Software Foundation. 00015 * 00016 * OpenOffice.org is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU Lesser General Public License version 3 for more details 00020 * (a copy is included in the LICENSE file that accompanied this code). 00021 * 00022 * You should have received a copy of the GNU Lesser General Public License 00023 * version 3 along with OpenOffice.org. If not, see 00024 * <http://www.openoffice.org/license.html> 00025 * for a copy of the LGPLv3 License. 00026 * 00027 ************************************************************************/ 00028 00029 #ifndef _SAL_MACROS_H_ 00030 #define _SAL_MACROS_H_ 00031 00032 #include <stddef.h> 00033 00034 #ifndef SAL_MAX 00035 # define SAL_MAX(a,b) (((a) > (b)) ? (a) : (b)) 00036 #endif 00037 00038 #ifndef SAL_MIN 00039 # define SAL_MIN(a,b) (((a) < (b)) ? (a) : (b)) 00040 #endif 00041 00042 #ifndef SAL_FIELDOFFSET 00043 # define SAL_FIELDOFFSET(type, field) ((sal_Int32)(&((type *)16)->field) - 16) 00044 #endif 00045 00046 #ifndef SAL_N_ELEMENTS 00047 # if defined(__cplusplus) && ( defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L ) 00048 /* 00049 * Magic template to calculate at compile time the number of elements 00050 * in an array. Enforcing that the argument must be a array and not 00051 * a pointer, e.g. 00052 * char *pFoo="foo"; 00053 * SAL_N_ELEMENTS(pFoo); 00054 * fails while 00055 * SAL_N_ELEMENTS("foo"); 00056 * or 00057 * char aFoo[]="foo"; 00058 * SAL_N_ELEMENTS(aFoo); 00059 * pass 00060 * 00061 * Unfortunately if arr is an array of an anonymous class then we need 00062 * C++0x, i.e. see 00063 * http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#757 00064 */ 00065 template <typename T, size_t S> char (&sal_n_array_size( T(&)[S] ))[S]; 00066 # define SAL_N_ELEMENTS(arr) (sizeof(sal_n_array_size(arr))) 00067 # else 00068 # define SAL_N_ELEMENTS(arr) (sizeof (arr) / sizeof ((arr)[0])) 00069 # endif 00070 #endif 00071 00072 #ifndef SAL_BOUND 00073 # define SAL_BOUND(x,l,h) ((x) <= (l) ? (l) : ((x) >= (h) ? (h) : (x))) 00074 #endif 00075 00076 #ifndef SAL_ABS 00077 # define SAL_ABS(a) (((a) < 0) ? (-(a)) : (a)) 00078 #endif 00079 00080 #ifndef SAL_STRINGIFY 00081 # define SAL_STRINGIFY_ARG(x) #x 00082 # define SAL_STRINGIFY(x) SAL_STRINGIFY_ARG(x) 00083 #endif 00084 00085 #endif 00086 00087 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */