LibreOffice
LibreOffice 4.1 SDK C/C++ API Reference
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
types.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #ifndef _SAL_TYPES_H_
21 #define _SAL_TYPES_H_
22 
23 #include <sal/config.h>
24 #include <sal/macros.h>
25 
26 #include <sal/typesizes.h>
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 /********************************************************************************/
33 /* Data types
34 */
35 
36 /* Boolean */
37 typedef unsigned char sal_Bool;
38 # define sal_False ((sal_Bool)0)
39 # define sal_True ((sal_Bool)1)
40 
41 /* char is assumed to always be 1 byte long */
42 typedef signed char sal_Int8;
43 typedef unsigned char sal_uInt8;
44 
45 #if SAL_TYPES_SIZEOFSHORT == 2
46  typedef signed short sal_Int16;
47  typedef unsigned short sal_uInt16;
48 #else
49  #error "Could not find 16-bit type, add support for your architecture"
50 #endif
51 
52 #if SAL_TYPES_SIZEOFLONG == 4
53  typedef signed long sal_Int32;
54  typedef unsigned long sal_uInt32;
55  #define SAL_PRIdINT32 "ld"
56  #define SAL_PRIuUINT32 "lu"
57  #define SAL_PRIxUINT32 "lx"
58  #define SAL_PRIXUINT32 "lX"
59 #elif SAL_TYPES_SIZEOFINT == 4
60  typedef signed int sal_Int32;
61  typedef unsigned int sal_uInt32;
62  #define SAL_PRIdINT32 "d"
63  #define SAL_PRIuUINT32 "u"
64  #define SAL_PRIxUINT32 "x"
65  #define SAL_PRIXUINT32 "X"
66 #else
67  #error "Could not find 32-bit type, add support for your architecture"
68 #endif
69 
70 #ifdef _MSC_VER
71  typedef __int64 sal_Int64;
72  typedef unsigned __int64 sal_uInt64;
73 
74  /* The following are macros that will add the 64 bit constant suffix. */
75  #define SAL_CONST_INT64(x) x##i64
76  #define SAL_CONST_UINT64(x) x##ui64
77 
78  #define SAL_PRIdINT64 "I64d"
79  #define SAL_PRIuUINT64 "I64u"
80  #define SAL_PRIxUINT64 "I64x"
81  #define SAL_PRIXUINT64 "I64X"
82 #elif defined(__SUNPRO_CC) || defined(__SUNPRO_C) || defined (__GNUC__) || defined (sgi)
83  #if SAL_TYPES_SIZEOFLONG == 8
84  typedef signed long int sal_Int64;
85  typedef unsigned long int sal_uInt64;
86 
87 
88  /* The following are macros that will add the 64 bit constant suffix. */
89  #define SAL_CONST_INT64(x) x##l
90  #define SAL_CONST_UINT64(x) x##ul
91 
92  #define SAL_PRIdINT64 "ld"
93  #define SAL_PRIuUINT64 "lu"
94  #define SAL_PRIxUINT64 "lx"
95  #define SAL_PRIXUINT64 "lX"
96  #elif SAL_TYPES_SIZEOFLONGLONG == 8
97  typedef signed long long sal_Int64;
98  typedef unsigned long long sal_uInt64;
99 
100  /* The following are macros that will add the 64 bit constant suffix. */
101  #define SAL_CONST_INT64(x) x##ll
102  #define SAL_CONST_UINT64(x) x##ull
103 
104  #ifdef __MINGW32__
105  #define SAL_PRIdINT64 "I64d"
106  #define SAL_PRIuUINT64 "I64u"
107  #define SAL_PRIxUINT64 "I64x"
108  #define SAL_PRIXUINT64 "I64X"
109  #else
110  #define SAL_PRIdINT64 "lld"
111  #define SAL_PRIuUINT64 "llu"
112  #define SAL_PRIxUINT64 "llx"
113  #define SAL_PRIXUINT64 "llX"
114  #endif
115  #else
116  #error "Could not find 64-bit type, add support for your architecture"
117  #endif
118 #else
119  #error "Please define the 64-bit types for your architecture/compiler in sal/inc/sal/types.h"
120 #endif
121 
122 typedef char sal_Char;
123 typedef signed char sal_sChar;
124 typedef unsigned char sal_uChar;
125 
126 #if ( defined(SAL_W32) && !defined(__MINGW32__) )
127  // http://msdn.microsoft.com/en-us/library/s3f49ktz%28v=vs.80%29.aspx
128  // "By default wchar_t is a typedef for unsigned short."
129  // But MinGW has a native wchar_t, and on many places, we cannot deal with
130  // that, so sal_Unicode has to be explicitly typedef'd as sal_uInt16 there.
131  typedef wchar_t sal_Unicode;
132 #else
133  #define SAL_UNICODE_NOTEQUAL_WCHAR_T
134  typedef sal_uInt16 sal_Unicode;
135 #endif
136 
137 typedef void * sal_Handle;
138 
139 /* sal_Size should currently be the native width of the platform */
140 #if SAL_TYPES_SIZEOFPOINTER == 4
141  typedef sal_uInt32 sal_Size;
142  typedef sal_Int32 sal_sSize;
143 #elif SAL_TYPES_SIZEOFPOINTER == 8
144  typedef sal_uInt64 sal_Size;
145  typedef sal_Int64 sal_sSize;
146 #else
147  #error "Please make sure SAL_TYPES_SIZEOFPOINTER is defined for your architecture/compiler"
148 #endif
149 
150 /* sal_PtrDiff holds the result of a pointer subtraction */
151 #if SAL_TYPES_SIZEOFPOINTER == 4
152  typedef sal_Int32 sal_PtrDiff;
153 #elif SAL_TYPES_SIZEOFPOINTER == 8
154  typedef sal_Int64 sal_PtrDiff;
155 #else
156  #error "Please make sure SAL_TYPES_SIZEOFPOINTER is defined for your architecture/compiler"
157 #endif
158 
159 /* printf-style conversion specification length modifiers for size_t and
160  ptrdiff_t (most platforms support C99, MSC has its own extension) */
161 #if defined(_MSC_VER) || defined(__MINGW32__)
162  #define SAL_PRI_SIZET "I"
163  #define SAL_PRI_PTRDIFFT "I"
164 #else
165  #define SAL_PRI_SIZET "z"
166  #define SAL_PRI_PTRDIFFT "t"
167 #endif
168 
169 /* sal_IntPtr, sal_uIntPtr are integer types designed to hold pointers so that any valid
170  * pointer to void can be converted to this type and back to a pointer to void and the
171  * result will compare to the original pointer */
172 #if SAL_TYPES_SIZEOFPOINTER == 4
173  typedef sal_Int32 sal_IntPtr;
174  typedef sal_uInt32 sal_uIntPtr;
175  #define SAL_PRIdINTPTR SAL_PRIdINT32
176  #define SAL_PRIuUINTPTR SAL_PRIuUINT32
177  #define SAL_PRIxUINTPTR SAL_PRIxUINT32
178  #define SAL_PRIXUINTPTR SAL_PRIXUINT32
179 #elif SAL_TYPES_SIZEOFPOINTER == 8
180  typedef sal_Int64 sal_IntPtr;
181  typedef sal_uInt64 sal_uIntPtr;
182  #define SAL_PRIdINTPTR SAL_PRIdINT64
183  #define SAL_PRIuUINTPTR SAL_PRIuUINT64
184  #define SAL_PRIxUINTPTR SAL_PRIxUINT64
185  #define SAL_PRIXUINTPTR SAL_PRIXUINT64
186 #else
187  #error "Please make sure SAL_TYPES_SIZEOFPOINTER is defined for your architecture/compiler"
188 #endif
189 
190 /********************************************************************************/
191 /* Useful defines
192  */
193 
194 /* The following SAL_MIN_INTn defines codify the assumption that the signed
195  * sal_Int types use two's complement representation. Defining them as
196  * "-0x7F... - 1" instead of as "-0x80..." prevents warnings about applying the
197  * unary minus operator to unsigned quantities.
198  */
199 #define SAL_MIN_INT8 ((sal_Int8) (-0x7F - 1))
200 #define SAL_MAX_INT8 ((sal_Int8) 0x7F)
201 #define SAL_MAX_UINT8 ((sal_uInt8) 0xFF)
202 #define SAL_MIN_INT16 ((sal_Int16) (-0x7FFF - 1))
203 #define SAL_MAX_INT16 ((sal_Int16) 0x7FFF)
204 #define SAL_MAX_UINT16 ((sal_uInt16) 0xFFFF)
205 #define SAL_MIN_INT32 ((sal_Int32) (-0x7FFFFFFF - 1))
206 #define SAL_MAX_INT32 ((sal_Int32) 0x7FFFFFFF)
207 #define SAL_MAX_UINT32 ((sal_uInt32) 0xFFFFFFFF)
208 #define SAL_MIN_INT64 ((sal_Int64) (SAL_CONST_INT64(-0x7FFFFFFFFFFFFFFF) - 1))
209 #define SAL_MAX_INT64 ((sal_Int64) SAL_CONST_INT64(0x7FFFFFFFFFFFFFFF))
210 #define SAL_MAX_UINT64 ((sal_uInt64) SAL_CONST_UINT64(0xFFFFFFFFFFFFFFFF))
211 
212 #if SAL_TYPES_SIZEOFLONG == 4
213 #define SAL_MAX_SSIZE SAL_MAX_INT32
214 #define SAL_MAX_SIZE SAL_MAX_UINT32
215 #elif SAL_TYPES_SIZEOFLONG == 8
216 #define SAL_MAX_SSIZE SAL_MAX_INT64
217 #define SAL_MAX_SIZE SAL_MAX_UINT64
218 #endif
219 
220 #if defined(SAL_W32) || defined(SAL_UNX)
221 # define SAL_MAX_ENUM 0x7fffffff
222 #endif
223 
224 #if defined(_MSC_VER) || defined(__MINGW32__)
225 # define SAL_DLLPUBLIC_EXPORT __declspec(dllexport)
226 # define SAL_JNI_EXPORT __declspec(dllexport)
227 #if defined(_MSC_VER)
228 # define SAL_DLLPUBLIC_IMPORT __declspec(dllimport)
229 #else
230 # define SAL_DLLPUBLIC_IMPORT
231 #endif // defined(_MSC_VER)
232 # define SAL_DLLPRIVATE
233 # define SAL_DLLPUBLIC_TEMPLATE
234 # define SAL_CALL __cdecl
235 # define SAL_CALL_ELLIPSE __cdecl
236 #elif defined SAL_UNX
237 # if defined(__SUNPRO_CC) && (__SUNPRO_CC >= 0x550)
238 # define SAL_DLLPUBLIC_EXPORT __global
239 # define SAL_JNI_EXPORT __global
240 # define SAL_DLLPUBLIC_IMPORT
241 # define SAL_DLLPRIVATE __hidden
242 # define SAL_DLLPUBLIC_TEMPLATE
243 # elif defined(__SUNPRO_C ) && (__SUNPRO_C >= 0x550)
244 # define SAL_DLLPUBLIC_EXPORT __global
245 # define SAL_JNI_EXPORT __global
246 # define SAL_DLLPUBLIC_IMPORT
247 # define SAL_DLLPRIVATE __hidden
248 # define SAL_DLLPUBLIC_TEMPLATE
249 # elif defined(__GNUC__) && defined(HAVE_GCC_VISIBILITY_FEATURE)
250 # if defined(DISABLE_DYNLOADING)
251 # define SAL_DLLPUBLIC_EXPORT __attribute__ ((visibility("hidden")))
252 # define SAL_JNI_EXPORT __attribute__ ((visibility("default")))
253 # define SAL_DLLPUBLIC_IMPORT __attribute__ ((visibility("hidden")))
254 # define SAL_DLLPRIVATE __attribute__ ((visibility("hidden")))
255 # define SAL_DLLPUBLIC_TEMPLATE __attribute__ ((visibility("hidden")))
256 # else
257 # define SAL_DLLPUBLIC_EXPORT __attribute__ ((visibility("default")))
258 # define SAL_JNI_EXPORT __attribute__ ((visibility("default")))
259 # define SAL_DLLPUBLIC_IMPORT __attribute__ ((visibility("default")))
260 # define SAL_DLLPRIVATE __attribute__ ((visibility("hidden")))
261 # define SAL_DLLPUBLIC_TEMPLATE __attribute__ ((visibility("default")))
262 # endif
263 # else
264 # define SAL_DLLPUBLIC_EXPORT
265 # define SAL_JNI_EXPORT
266 # define SAL_DLLPUBLIC_IMPORT
267 # define SAL_DLLPRIVATE
268 # define SAL_DLLPUBLIC_TEMPLATE
269 # endif
270 # define SAL_CALL
271 # define SAL_CALL_ELLIPSE
272 #else
273 # error("unknown platform")
274 #endif
275 
282 #if defined(__GNUC__) && ! defined(__MINGW32__)
283 # if defined(DISABLE_DYNLOADING)
284 # define SAL_EXCEPTION_DLLPUBLIC_EXPORT __attribute__((visibility("default")))
285 # else
286 # define SAL_EXCEPTION_DLLPUBLIC_EXPORT SAL_DLLPUBLIC_EXPORT
287 # endif
288 # define SAL_EXCEPTION_DLLPRIVATE SAL_DLLPRIVATE
289 #else
290 # define SAL_EXCEPTION_DLLPUBLIC_EXPORT
291 # define SAL_EXCEPTION_DLLPRIVATE
292 #endif
293 
300 #if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1))
301 # define SAL_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
302 #else
303 # define SAL_WARN_UNUSED_RESULT
304 #endif
305 
310 #ifdef _MSC_VER
311 # define SAL_NO_VTABLE __declspec(novtable)
312 #else
313 # define SAL_NO_VTABLE
314 #endif
315 
316 #ifdef SAL_W32
317 # pragma pack(push, 8)
318 #endif
319 
323 typedef struct _sal_Sequence
324 {
327  sal_Int32 nRefCount;
330  sal_Int32 nElements;
333  char elements[1];
334 } sal_Sequence;
335 
336 #define SAL_SEQUENCE_HEADER_SIZE ((sal_Size)&((sal_Sequence *)0)->elements)
337 
338 #if defined( SAL_W32)
339 #pragma pack(pop)
340 #endif
341 
352 #ifdef __cplusplus
353 #if defined(__GNUC__) || defined(__SUNPRO_CC) || defined(__sgi)
354 #define SAL_THROW( exc )
355 #else /* MSVC, all other */
356 #define SAL_THROW( exc ) throw exc
357 #endif /* __GNUC__, __SUNPRO_CC */
358 #define SAL_THROW_EXTERN_C() throw ()
359 #else /* ! __cplusplus */
360 /* SAL_THROW() must not be used in C headers, only SAL_THROW_EXTERN_C() is defined */
361 #define SAL_THROW_EXTERN_C()
362 #endif
363 
364 #ifdef __cplusplus
365 }
366 #endif /* __cplusplus */
367 
368 #ifdef __cplusplus
369 
371 {
375 };
376 
377 namespace com { namespace sun { namespace star { } } }
378 
383 namespace css = ::com::sun::star;
384 
393 #if HAVE_CXX11_DELETE
394 #define SAL_DELETED_FUNCTION = delete
395 #else
396 #define SAL_DELETED_FUNCTION
397 #endif
398 
406 #if HAVE_CXX11_OVERRIDE
407 #define SAL_OVERRIDE override
408 #else
409 #define SAL_OVERRIDE
410 #endif
411 
418 #if HAVE_CXX11_FINAL
419 #define SAL_FINAL final
420 #else
421 #define SAL_FINAL
422 #endif
423 
424 #endif /* __cplusplus */
425 
426 #ifdef __cplusplus
427 
428 namespace sal {
429 
441 template< typename T1, typename T2 > inline T1 static_int_cast(T2 n) {
442  return static_cast< T1 >(n);
443 }
444 
445 }
446 
447 #else /* __cplusplus */
448 
461 #define SAL_INT_CAST(type, expr) ((type) (expr))
462 
463 #endif /* __cplusplus */
464 
470 #if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5))
471 # define SAL_DEPRECATED(message) __attribute__((deprecated(message)))
472 #elif (__GNUC__)
473 # define SAL_DEPRECATED(message) __attribute__((deprecated))
474 #elif defined(_MSC_VER)
475 # define SAL_DEPRECATED(message) __declspec(deprecated(message))
476 #else
477 # define SAL_DEPRECATED(message)
478 #endif
479 
489 #ifdef LIBO_INTERNAL_ONLY
490 # define SAL_DEPRECATED_INTERNAL(message)
491 #else
492 # define SAL_DEPRECATED_INTERNAL(message) SAL_DEPRECATED(message)
493 #endif
494 
502 #if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) || defined(__clang__)
503 #define SAL_WNODEPRECATED_DECLARATIONS_PUSH \
504  _Pragma(SAL_STRINGIFY_ARG(GCC diagnostic push)) \
505  _Pragma(SAL_STRINGIFY_ARG(GCC diagnostic ignored "-Wdeprecated-declarations"))
506 #define SAL_WNODEPRECATED_DECLARATIONS_POP \
507  _Pragma(SAL_STRINGIFY_ARG(GCC diagnostic pop))
508 #else
509 # define SAL_WNODEPRECATED_DECLARATIONS_PUSH
510 # define SAL_WNODEPRECATED_DECLARATIONS_POP
511 #endif
512 
536 #if defined __cplusplus
537 #if defined __GNUC__
538 #define SAL_UNUSED_PARAMETER __attribute__ ((unused))
539 #else
540 #define SAL_UNUSED_PARAMETER
541 #endif
542 #endif
543 
558 #if defined __clang__
559 #define SAL_WARN_UNUSED __attribute__((annotate("lo_warn_unused")))
560 #else
561 #define SAL_WARN_UNUSED
562 #endif
563 
564 #endif /*_SAL_TYPES_H_ */
565 
566 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */