00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 00002 /* 00003 * This file is part of the LibreOffice project. 00004 * 00005 * This Source Code Form is subject to the terms of the Mozilla Public 00006 * License, v. 2.0. If a copy of the MPL was not distributed with this 00007 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 00008 * 00009 * This file incorporates work covered by the following license notice: 00010 * 00011 * Licensed to the Apache Software Foundation (ASF) under one or more 00012 * contributor license agreements. See the NOTICE file distributed 00013 * with this work for additional information regarding copyright 00014 * ownership. The ASF licenses this file to you under the Apache 00015 * License, Version 2.0 (the "License"); you may not use this file 00016 * except in compliance with the License. You may obtain a copy of 00017 * the License at http://www.apache.org/licenses/LICENSE-2.0 . 00018 */ 00019 00020 #ifndef _SAL_MACROS_H_ 00021 #define _SAL_MACROS_H_ 00022 00023 #include <stddef.h> 00024 00025 #ifndef SAL_N_ELEMENTS 00026 # if defined(__cplusplus) && ( defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L ) 00027 /* 00028 * Magic template to calculate at compile time the number of elements 00029 * in an array. Enforcing that the argument must be a array and not 00030 * a pointer, e.g. 00031 * char *pFoo="foo"; 00032 * SAL_N_ELEMENTS(pFoo); 00033 * fails while 00034 * SAL_N_ELEMENTS("foo"); 00035 * or 00036 * char aFoo[]="foo"; 00037 * SAL_N_ELEMENTS(aFoo); 00038 * pass 00039 * 00040 * Unfortunately if arr is an array of an anonymous class then we need 00041 * C++0x, i.e. see 00042 * http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#757 00043 */ 00044 template <typename T, size_t S> char (&sal_n_array_size( T(&)[S] ))[S]; 00045 # define SAL_N_ELEMENTS(arr) (sizeof(sal_n_array_size(arr))) 00046 # else 00047 # define SAL_N_ELEMENTS(arr) (sizeof (arr) / sizeof ((arr)[0])) 00048 # endif 00049 #endif 00050 00051 #ifndef SAL_BOUND 00052 # define SAL_BOUND(x,l,h) ((x) <= (l) ? (l) : ((x) >= (h) ? (h) : (x))) 00053 #endif 00054 00055 #ifndef SAL_ABS 00056 # define SAL_ABS(a) (((a) < 0) ? (-(a)) : (a)) 00057 #endif 00058 00059 #ifndef SAL_STRINGIFY 00060 # define SAL_STRINGIFY_ARG(x) #x 00061 # define SAL_STRINGIFY(x) SAL_STRINGIFY_ARG(x) 00062 #endif 00063 00064 #endif 00065 00066 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */