My Project
UDK 3.2.7 C/C++ API Reference
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
macros.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * Copyright 2000, 2010 Oracle and/or its affiliates.
7  *
8  * OpenOffice.org - a multi-platform office productivity suite
9  *
10  * This file is part of OpenOffice.org.
11  *
12  * OpenOffice.org is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU Lesser General Public License version 3
14  * only, as published by the Free Software Foundation.
15  *
16  * OpenOffice.org is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Lesser General Public License version 3 for more details
20  * (a copy is included in the LICENSE file that accompanied this code).
21  *
22  * You should have received a copy of the GNU Lesser General Public License
23  * version 3 along with OpenOffice.org. If not, see
24  * <http://www.openoffice.org/license.html>
25  * for a copy of the LGPLv3 License.
26  *
27  ************************************************************************/
28 
29 #ifndef _SAL_MACROS_H_
30 #define _SAL_MACROS_H_
31 
32 #include <stddef.h>
33 
34 #ifndef SAL_MAX
35 # define SAL_MAX(a,b) (((a) > (b)) ? (a) : (b))
36 #endif
37 
38 #ifndef SAL_MIN
39 # define SAL_MIN(a,b) (((a) < (b)) ? (a) : (b))
40 #endif
41 
42 #ifndef SAL_FIELDOFFSET
43 # define SAL_FIELDOFFSET(type, field) ((sal_Int32)(&((type *)16)->field) - 16)
44 #endif
45 
46 #ifndef SAL_N_ELEMENTS
47 # if defined(__cplusplus) && ( defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L )
48  /*
49  * Magic template to calculate at compile time the number of elements
50  * in an array. Enforcing that the argument must be a array and not
51  * a pointer, e.g.
52  * char *pFoo="foo";
53  * SAL_N_ELEMENTS(pFoo);
54  * fails while
55  * SAL_N_ELEMENTS("foo");
56  * or
57  * char aFoo[]="foo";
58  * SAL_N_ELEMENTS(aFoo);
59  * pass
60  *
61  * Unfortunately if arr is an array of an anonymous class then we need
62  * C++0x, i.e. see
63  * http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#757
64  */
65  template <typename T, size_t S> char (&sal_n_array_size( T(&)[S] ))[S];
66 # define SAL_N_ELEMENTS(arr) (sizeof(sal_n_array_size(arr)))
67 # else
68 # define SAL_N_ELEMENTS(arr) (sizeof (arr) / sizeof ((arr)[0]))
69 # endif
70 #endif
71 
72 #ifndef SAL_BOUND
73 # define SAL_BOUND(x,l,h) ((x) <= (l) ? (l) : ((x) >= (h) ? (h) : (x)))
74 #endif
75 
76 #ifndef SAL_ABS
77 # define SAL_ABS(a) (((a) < 0) ? (-(a)) : (a))
78 #endif
79 
80 #ifndef SAL_STRINGIFY
81 # define SAL_STRINGIFY_ARG(x) #x
82 # define SAL_STRINGIFY(x) SAL_STRINGIFY_ARG(x)
83 #endif
84 
85 #endif
86 
87 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */