LibreOffice
LibreOffice 4.2 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 #if defined ( __MINGW32__ ) && !defined ( __USE_MINGW_ANSI_STDIO )
33 /* Define to use the C99 formating string for coherence reasons.
34  * In mingw-w64 some functions are ported to the ms formating string
35  * some are not yet. This is the only way to make the formatting
36  * strings work all the time
37  */
38 #define __USE_MINGW_ANSI_STDIO 1
39 #endif
40 
41 /********************************************************************************/
42 /* Data types
43 */
44 
45 /* Boolean */
46 typedef unsigned char sal_Bool;
47 # define sal_False ((sal_Bool)0)
48 # define sal_True ((sal_Bool)1)
49 
50 /* char is assumed to always be 1 byte long */
51 typedef signed char sal_Int8;
52 typedef unsigned char sal_uInt8;
53 
54 #if SAL_TYPES_SIZEOFSHORT == 2
55  typedef signed short sal_Int16;
56  typedef unsigned short sal_uInt16;
57 #else
58  #error "Could not find 16-bit type, add support for your architecture"
59 #endif
60 
61 #if SAL_TYPES_SIZEOFLONG == 4
62  typedef signed long sal_Int32;
63  typedef unsigned long sal_uInt32;
64  #define SAL_PRIdINT32 "ld"
65  #define SAL_PRIuUINT32 "lu"
66  #define SAL_PRIxUINT32 "lx"
67  #define SAL_PRIXUINT32 "lX"
68 #elif SAL_TYPES_SIZEOFINT == 4
69  typedef signed int sal_Int32;
70  typedef unsigned int sal_uInt32;
71  #define SAL_PRIdINT32 "d"
72  #define SAL_PRIuUINT32 "u"
73  #define SAL_PRIxUINT32 "x"
74  #define SAL_PRIXUINT32 "X"
75 #else
76  #error "Could not find 32-bit type, add support for your architecture"
77 #endif
78 
79 #ifdef _MSC_VER
80  typedef __int64 sal_Int64;
81  typedef unsigned __int64 sal_uInt64;
82 
83  /* The following are macros that will add the 64 bit constant suffix. */
84  #define SAL_CONST_INT64(x) x##i64
85  #define SAL_CONST_UINT64(x) x##ui64
86 
87  #define SAL_PRIdINT64 "I64d"
88  #define SAL_PRIuUINT64 "I64u"
89  #define SAL_PRIxUINT64 "I64x"
90  #define SAL_PRIXUINT64 "I64X"
91 #elif defined(__SUNPRO_CC) || defined(__SUNPRO_C) || defined (__GNUC__) || defined (sgi)
92  #if SAL_TYPES_SIZEOFLONG == 8
93  typedef signed long int sal_Int64;
94  typedef unsigned long int sal_uInt64;
95 
96 
97  /* The following are macros that will add the 64 bit constant suffix. */
98  #define SAL_CONST_INT64(x) x##l
99  #define SAL_CONST_UINT64(x) x##ul
100 
101  #define SAL_PRIdINT64 "ld"
102  #define SAL_PRIuUINT64 "lu"
103  #define SAL_PRIxUINT64 "lx"
104  #define SAL_PRIXUINT64 "lX"
105  #elif SAL_TYPES_SIZEOFLONGLONG == 8
106  typedef signed long long sal_Int64;
107  typedef unsigned long long sal_uInt64;
108 
109  /* The following are macros that will add the 64 bit constant suffix. */
110  #define SAL_CONST_INT64(x) x##ll
111  #define SAL_CONST_UINT64(x) x##ull
112 
113  #define SAL_PRIdINT64 "lld"
114  #define SAL_PRIuUINT64 "llu"
115  #define SAL_PRIxUINT64 "llx"
116  #define SAL_PRIXUINT64 "llX"
117  #else
118  #error "Could not find 64-bit type, add support for your architecture"
119  #endif
120 #else
121  #error "Please define the 64-bit types for your architecture/compiler in sal/inc/sal/types.h"
122 #endif
123 
124 typedef char sal_Char;
125 typedef signed char sal_sChar;
126 typedef unsigned char sal_uChar;
127 
128 #if ( defined(SAL_W32) && !defined(__MINGW32__) )
129  // http://msdn.microsoft.com/en-us/library/s3f49ktz%28v=vs.80%29.aspx
130  // "By default wchar_t is a typedef for unsigned short."
131  // But MinGW has a native wchar_t, and on many places, we cannot deal with
132  // that, so sal_Unicode has to be explicitly typedef'd as sal_uInt16 there.
133  typedef wchar_t sal_Unicode;
134 #else
135  #define SAL_UNICODE_NOTEQUAL_WCHAR_T
136  typedef sal_uInt16 sal_Unicode;
137 #endif
138 
139 typedef void * sal_Handle;
140 
141 /* sal_Size should currently be the native width of the platform */
142 #if SAL_TYPES_SIZEOFPOINTER == 4
143  typedef sal_uInt32 sal_Size;
144  typedef sal_Int32 sal_sSize;
145 #elif SAL_TYPES_SIZEOFPOINTER == 8
146  typedef sal_uInt64 sal_Size;
147  typedef sal_Int64 sal_sSize;
148 #else
149  #error "Please make sure SAL_TYPES_SIZEOFPOINTER is defined for your architecture/compiler"
150 #endif
151 
152 /* sal_PtrDiff holds the result of a pointer subtraction */
153 #if SAL_TYPES_SIZEOFPOINTER == 4
154  typedef sal_Int32 sal_PtrDiff;
155 #elif SAL_TYPES_SIZEOFPOINTER == 8
156  typedef sal_Int64 sal_PtrDiff;
157 #else
158  #error "Please make sure SAL_TYPES_SIZEOFPOINTER is defined for your architecture/compiler"
159 #endif
160 
161 /* printf-style conversion specification length modifiers for size_t and
162  ptrdiff_t (most platforms support C99, MSC has its own extension) */
163 #if defined(_MSC_VER)
164  #define SAL_PRI_SIZET "I"
165  #define SAL_PRI_PTRDIFFT "I"
166 #else
167  #define SAL_PRI_SIZET "z"
168  #define SAL_PRI_PTRDIFFT "t"
169 #endif
170 
171 /* sal_IntPtr, sal_uIntPtr are integer types designed to hold pointers so that any valid
172  * pointer to void can be converted to this type and back to a pointer to void and the
173  * result will compare to the original pointer */
174 #if SAL_TYPES_SIZEOFPOINTER == 4
175  typedef sal_Int32 sal_IntPtr;
176  typedef sal_uInt32 sal_uIntPtr;
177  #define SAL_PRIdINTPTR SAL_PRIdINT32
178  #define SAL_PRIuUINTPTR SAL_PRIuUINT32
179  #define SAL_PRIxUINTPTR SAL_PRIxUINT32
180  #define SAL_PRIXUINTPTR SAL_PRIXUINT32
181 #elif SAL_TYPES_SIZEOFPOINTER == 8
182  typedef sal_Int64 sal_IntPtr;
183  typedef sal_uInt64 sal_uIntPtr;
184  #define SAL_PRIdINTPTR SAL_PRIdINT64
185  #define SAL_PRIuUINTPTR SAL_PRIuUINT64
186  #define SAL_PRIxUINTPTR SAL_PRIxUINT64
187  #define SAL_PRIXUINTPTR SAL_PRIXUINT64
188 #else
189  #error "Please make sure SAL_TYPES_SIZEOFPOINTER is defined for your architecture/compiler"
190 #endif
191 
192 /********************************************************************************/
193 /* Useful defines
194  */
195 
196 /* The following SAL_MIN_INTn defines codify the assumption that the signed
197  * sal_Int types use two's complement representation. Defining them as
198  * "-0x7F... - 1" instead of as "-0x80..." prevents warnings about applying the
199  * unary minus operator to unsigned quantities.
200  */
201 #define SAL_MIN_INT8 ((sal_Int8) (-0x7F - 1))
202 #define SAL_MAX_INT8 ((sal_Int8) 0x7F)
203 #define SAL_MAX_UINT8 ((sal_uInt8) 0xFF)
204 #define SAL_MIN_INT16 ((sal_Int16) (-0x7FFF - 1))
205 #define SAL_MAX_INT16 ((sal_Int16) 0x7FFF)
206 #define SAL_MAX_UINT16 ((sal_uInt16) 0xFFFF)
207 #define SAL_MIN_INT32 ((sal_Int32) (-0x7FFFFFFF - 1))
208 #define SAL_MAX_INT32 ((sal_Int32) 0x7FFFFFFF)
209 #define SAL_MAX_UINT32 ((sal_uInt32) 0xFFFFFFFF)
210 #define SAL_MIN_INT64 ((sal_Int64) (SAL_CONST_INT64(-0x7FFFFFFFFFFFFFFF) - 1))
211 #define SAL_MAX_INT64 ((sal_Int64) SAL_CONST_INT64(0x7FFFFFFFFFFFFFFF))
212 #define SAL_MAX_UINT64 ((sal_uInt64) SAL_CONST_UINT64(0xFFFFFFFFFFFFFFFF))
213 
214 #if SAL_TYPES_SIZEOFLONG == 4
215 #define SAL_MAX_SSIZE SAL_MAX_INT32
216 #define SAL_MAX_SIZE SAL_MAX_UINT32
217 #elif SAL_TYPES_SIZEOFLONG == 8
218 #define SAL_MAX_SSIZE SAL_MAX_INT64
219 #define SAL_MAX_SIZE SAL_MAX_UINT64
220 #endif
221 
222 #if defined(SAL_W32) || defined(SAL_UNX)
223 # define SAL_MAX_ENUM 0x7fffffff
224 #endif
225 
226 #if defined(_MSC_VER) || defined(__MINGW32__)
227 # define SAL_DLLPUBLIC_EXPORT __declspec(dllexport)
228 # define SAL_JNI_EXPORT __declspec(dllexport)
229 #if defined(_MSC_VER)
230 # define SAL_DLLPUBLIC_IMPORT __declspec(dllimport)
231 #else
232 # define SAL_DLLPUBLIC_IMPORT
233 #endif // defined(_MSC_VER)
234 # define SAL_DLLPRIVATE
235 # define SAL_DLLPUBLIC_TEMPLATE
236 # define SAL_CALL __cdecl
237 # define SAL_CALL_ELLIPSE __cdecl
238 #elif defined SAL_UNX
239 # if defined(__SUNPRO_CC) && (__SUNPRO_CC >= 0x550)
240 # define SAL_DLLPUBLIC_EXPORT __global
241 # define SAL_JNI_EXPORT __global
242 # define SAL_DLLPUBLIC_IMPORT
243 # define SAL_DLLPRIVATE __hidden
244 # define SAL_DLLPUBLIC_TEMPLATE
245 # elif defined(__SUNPRO_C ) && (__SUNPRO_C >= 0x550)
246 # define SAL_DLLPUBLIC_EXPORT __global
247 # define SAL_JNI_EXPORT __global
248 # define SAL_DLLPUBLIC_IMPORT
249 # define SAL_DLLPRIVATE __hidden
250 # define SAL_DLLPUBLIC_TEMPLATE
251 # elif defined(__GNUC__) && defined(HAVE_GCC_VISIBILITY_FEATURE)
252 # if defined(DISABLE_DYNLOADING)
253 # define SAL_DLLPUBLIC_EXPORT __attribute__ ((visibility("hidden")))
254 # define SAL_JNI_EXPORT __attribute__ ((visibility("default")))
255 # define SAL_DLLPUBLIC_IMPORT __attribute__ ((visibility("hidden")))
256 # define SAL_DLLPRIVATE __attribute__ ((visibility("hidden")))
257 # define SAL_DLLPUBLIC_TEMPLATE __attribute__ ((visibility("hidden")))
258 # else
259 # define SAL_DLLPUBLIC_EXPORT __attribute__ ((visibility("default")))
260 # define SAL_JNI_EXPORT __attribute__ ((visibility("default")))
261 # define SAL_DLLPUBLIC_IMPORT __attribute__ ((visibility("default")))
262 # define SAL_DLLPRIVATE __attribute__ ((visibility("hidden")))
263 # define SAL_DLLPUBLIC_TEMPLATE __attribute__ ((visibility("default")))
264 # endif
265 # else
266 # define SAL_DLLPUBLIC_EXPORT
267 # define SAL_JNI_EXPORT
268 # define SAL_DLLPUBLIC_IMPORT
269 # define SAL_DLLPRIVATE
270 # define SAL_DLLPUBLIC_TEMPLATE
271 # endif
272 # define SAL_CALL
273 # define SAL_CALL_ELLIPSE
274 #else
275 # error("unknown platform")
276 #endif
277 
284 #if defined(__GNUC__) && ! defined(__MINGW32__)
285 # if defined(DISABLE_DYNLOADING)
286 # define SAL_EXCEPTION_DLLPUBLIC_EXPORT __attribute__((visibility("default")))
287 # else
288 # define SAL_EXCEPTION_DLLPUBLIC_EXPORT SAL_DLLPUBLIC_EXPORT
289 # endif
290 # define SAL_EXCEPTION_DLLPRIVATE SAL_DLLPRIVATE
291 #else
292 # define SAL_EXCEPTION_DLLPUBLIC_EXPORT
293 # define SAL_EXCEPTION_DLLPRIVATE
294 #endif
295 
302 #if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1))
303 # define SAL_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
304 #else
305 # define SAL_WARN_UNUSED_RESULT
306 #endif
307 
312 #ifdef _MSC_VER
313 # define SAL_NO_VTABLE __declspec(novtable)
314 #else
315 # define SAL_NO_VTABLE
316 #endif
317 
318 #ifdef SAL_W32
319 # pragma pack(push, 8)
320 #endif
321 
325 typedef struct _sal_Sequence
326 {
329  sal_Int32 nRefCount;
332  sal_Int32 nElements;
335  char elements[1];
336 } sal_Sequence;
337 
338 #define SAL_SEQUENCE_HEADER_SIZE ((sal_Size)&((sal_Sequence *)0)->elements)
339 
340 #if defined( SAL_W32)
341 #pragma pack(pop)
342 #endif
343 
354 #ifdef __cplusplus
355 #if defined(__GNUC__) || defined(__SUNPRO_CC) || defined(__sgi)
356 #define SAL_THROW( exc )
357 #else /* MSVC, all other */
358 #define SAL_THROW( exc ) throw exc
359 #endif /* __GNUC__, __SUNPRO_CC */
360 #define SAL_THROW_EXTERN_C() throw ()
361 #else /* ! __cplusplus */
362 /* SAL_THROW() must not be used in C headers, only SAL_THROW_EXTERN_C() is defined */
363 #define SAL_THROW_EXTERN_C()
364 #endif
365 
366 #ifdef __cplusplus
367 }
368 #endif /* __cplusplus */
369 
370 #ifdef __cplusplus
371 
373 {
377 };
378 
379 namespace com { namespace sun { namespace star { } } }
380 
385 namespace css = ::com::sun::star;
386 
395 #if HAVE_CXX11_DELETE
396 #define SAL_DELETED_FUNCTION = delete
397 #else
398 #define SAL_DELETED_FUNCTION
399 #endif
400 
408 #if HAVE_CXX11_OVERRIDE
409 #define SAL_OVERRIDE override
410 #else
411 #define SAL_OVERRIDE
412 #endif
413 
420 #if HAVE_CXX11_FINAL
421 #define SAL_FINAL final
422 #else
423 #define SAL_FINAL
424 #endif
425 
426 #endif /* __cplusplus */
427 
428 #ifdef __cplusplus
429 
430 namespace sal {
431 
443 template< typename T1, typename T2 > inline T1 static_int_cast(T2 n) {
444  return static_cast< T1 >(n);
445 }
446 
447 }
448 
449 #else /* __cplusplus */
450 
463 #define SAL_INT_CAST(type, expr) ((type) (expr))
464 
465 #endif /* __cplusplus */
466 
472 #if HAVE_GCC_DEPRECATED_MESSAGE
473 # define SAL_DEPRECATED(message) __attribute__((deprecated(message)))
474 #elif (__GNUC__)
475 # define SAL_DEPRECATED(message) __attribute__((deprecated))
476 #elif defined(_MSC_VER)
477 # define SAL_DEPRECATED(message) __declspec(deprecated(message))
478 #else
479 # define SAL_DEPRECATED(message)
480 #endif
481 
491 #ifdef LIBO_INTERNAL_ONLY
492 # define SAL_DEPRECATED_INTERNAL(message)
493 #else
494 # define SAL_DEPRECATED_INTERNAL(message) SAL_DEPRECATED(message)
495 #endif
496 
504 #if HAVE_GCC_PRAGMA_DIAGNOSTIC_MODIFY && HAVE_GCC_PRAGMA_DIAGNOSTIC_SCOPE && HAVE_GCC_PRAGMA_OPERATOR
505 #define SAL_WNODEPRECATED_DECLARATIONS_PUSH \
506  _Pragma(SAL_STRINGIFY_ARG(GCC diagnostic push)) \
507  _Pragma(SAL_STRINGIFY_ARG(GCC diagnostic ignored "-Wdeprecated-declarations"))
508 #define SAL_WNODEPRECATED_DECLARATIONS_POP \
509  _Pragma(SAL_STRINGIFY_ARG(GCC diagnostic pop))
510 #else
511 # define SAL_WNODEPRECATED_DECLARATIONS_PUSH
512 # define SAL_WNODEPRECATED_DECLARATIONS_POP
513 #endif
514 
531 #ifdef _MSC_VER
532 #define SAL_WNOUNREACHABLE_CODE_PUSH \
533  __pragma(warning(push)) \
534  __pragma(warning(disable:4702))
535 #define SAL_WNOUNREACHABLE_CODE_POP \
536  __pragma(warning(pop))
537 #else
538 /* Add definitions for GCC and Clang if needed */
539 #define SAL_WNOUNREACHABLE_CODE_PUSH
540 #define SAL_WNOUNREACHABLE_CODE_POP
541 #endif
542 
566 #if defined __cplusplus
567 #if defined __GNUC__
568 #define SAL_UNUSED_PARAMETER __attribute__ ((unused))
569 #else
570 #define SAL_UNUSED_PARAMETER
571 #endif
572 #endif
573 
586 #if HAVE_GCC_ATTRIBUTE_WARN_UNUSED
587 #define SAL_WARN_UNUSED __attribute__((warn_unused))
588 #elif defined __clang__
589 #define SAL_WARN_UNUSED __attribute__((annotate("lo_warn_unused")))
590 #else
591 #define SAL_WARN_UNUSED
592 #endif
593 
594 #endif /*_SAL_TYPES_H_ */
595 
596 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
unsigned char sal_uInt8
Definition: types.h:52
struct _sal_Sequence sal_Sequence
This is the binary specification of a SAL sequence.
sal_uInt16 sal_Unicode
Definition: types.h:136
T1 static_int_cast(T2 n)
A static_cast between integral types, to avoid C++ compiler warnings.
Definition: types.h:443
signed char sal_sChar
Definition: types.h:125
This is the binary specification of a SAL sequence.
Definition: types.h:325
char elements[1]
elements array
Definition: types.h:335
sal_Int32 nElements
element count
Definition: types.h:332
definition of a no acquire enum for ctors
Definition: types.h:376
unsigned char sal_Bool
Definition: types.h:46
__sal_NoAcquire
Definition: types.h:372
void * sal_Handle
Definition: types.h:139
char sal_Char
Definition: types.h:124
unsigned char sal_uChar
Definition: types.h:126
signed char sal_Int8
Definition: types.h:51
sal_Int32 nRefCount
reference count of sequence
Definition: types.h:329