AlterOffice
AlterOffice 3.4 SDK C/C++ API Reference
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 
4 #ifndef INCLUDED_SAL_TYPES_H
5 #define INCLUDED_SAL_TYPES_H
6 
7 #include "sal/config.h"
8 
9 #include <stddef.h>
10 
11 #include "sal/macros.h"
12 #include "sal/typesizes.h"
13 
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17 
18 typedef unsigned char sal_Bool;
19 # define sal_False ((sal_Bool)0)
20 # define sal_True ((sal_Bool)1)
21 
22 /* char is assumed to always be 1 byte long */
23 typedef signed char sal_Int8;
24 typedef unsigned char sal_uInt8;
25 
26 #if SAL_TYPES_SIZEOFSHORT == 2
27  typedef signed short sal_Int16;
28  typedef unsigned short sal_uInt16;
29 #else
30  #error "Could not find 16-bit type, add support for your architecture"
31 #endif
32 
33 #if SAL_TYPES_SIZEOFLONG == 4
34  typedef signed long sal_Int32;
35  typedef unsigned long sal_uInt32;
36  #define SAL_PRIdINT32 "ld"
37  #define SAL_PRIuUINT32 "lu"
38  #define SAL_PRIxUINT32 "lx"
39  #define SAL_PRIXUINT32 "lX"
40 #elif SAL_TYPES_SIZEOFINT == 4
41  typedef signed int sal_Int32;
42  typedef unsigned int sal_uInt32;
43  #define SAL_PRIdINT32 "d"
44  #define SAL_PRIuUINT32 "u"
45  #define SAL_PRIxUINT32 "x"
46  #define SAL_PRIXUINT32 "X"
47 #else
48  #error "Could not find 32-bit type, add support for your architecture"
49 #endif
50 
51 #ifdef _MSC_VER
52  typedef __int64 sal_Int64;
53  typedef unsigned __int64 sal_uInt64;
54 
55  /* The following are macros that will add the 64 bit constant suffix. */
56  #define SAL_CONST_INT64(x) x##i64
57  #define SAL_CONST_UINT64(x) x##ui64
58 
59  #define SAL_PRIdINT64 "I64d"
60  #define SAL_PRIuUINT64 "I64u"
61  #define SAL_PRIxUINT64 "I64x"
62  #define SAL_PRIXUINT64 "I64X"
63 #elif defined (__GNUC__)
64  #if SAL_TYPES_SIZEOFLONG == 8
65  typedef signed long int sal_Int64;
66  typedef unsigned long int sal_uInt64;
67 
68 
69  /* The following are macros that will add the 64 bit constant suffix. */
70  #define SAL_CONST_INT64(x) x##l
71  #define SAL_CONST_UINT64(x) x##ul
72 
73  #define SAL_PRIdINT64 "ld"
74  #define SAL_PRIuUINT64 "lu"
75  #define SAL_PRIxUINT64 "lx"
76  #define SAL_PRIXUINT64 "lX"
77  #elif SAL_TYPES_SIZEOFLONGLONG == 8
78  typedef signed long long sal_Int64;
79  typedef unsigned long long sal_uInt64;
80 
81  /* The following are macros that will add the 64 bit constant suffix. */
82  #define SAL_CONST_INT64(x) x##ll
83  #define SAL_CONST_UINT64(x) x##ull
84 
85  #define SAL_PRIdINT64 "lld"
86  #define SAL_PRIuUINT64 "llu"
87  #define SAL_PRIxUINT64 "llx"
88  #define SAL_PRIXUINT64 "llX"
89  #else
90  #error "Could not find 64-bit type, add support for your architecture"
91  #endif
92 #else
93  #error "Please define the 64-bit types for your architecture/compiler in include/sal/types.h"
94 #endif
95 
96 #if defined LIBO_INTERNAL_ONLY && defined __cplusplus
97  #define SAL_UNICODE_NOTEQUAL_WCHAR_T
98  typedef char16_t sal_Unicode;
99 #elif defined(_WIN32)
100  typedef wchar_t sal_Unicode;
101 #else
102  #define SAL_UNICODE_NOTEQUAL_WCHAR_T
103  typedef sal_uInt16 sal_Unicode;
104 #endif
105 
106 typedef void * sal_Handle;
107 
108 /* sal_Size should currently be the native width of the platform */
109 #if SAL_TYPES_SIZEOFPOINTER == 4
110  typedef sal_uInt32 sal_Size;
111  typedef sal_Int32 sal_sSize;
112 #elif SAL_TYPES_SIZEOFPOINTER == 8
113  typedef sal_uInt64 sal_Size;
114  typedef sal_Int64 sal_sSize;
115 #else
116  #error "Please make sure SAL_TYPES_SIZEOFPOINTER is defined for your architecture/compiler"
117 #endif
118 
119 /* sal_PtrDiff holds the result of a pointer subtraction */
120 #if SAL_TYPES_SIZEOFPOINTER == 4
121  typedef sal_Int32 sal_PtrDiff;
122 #elif SAL_TYPES_SIZEOFPOINTER == 8
123  typedef sal_Int64 sal_PtrDiff;
124 #else
125  #error "Please make sure SAL_TYPES_SIZEOFPOINTER is defined for your architecture/compiler"
126 #endif
127 
128 /* printf-style conversion specification length modifiers for size_t and
129  ptrdiff_t (most platforms support C99, MSC has its own extension) */
130 #if defined(_MSC_VER)
131  #define SAL_PRI_SIZET "I"
132  #define SAL_PRI_PTRDIFFT "I"
133 #else
134  #define SAL_PRI_SIZET "z"
135  #define SAL_PRI_PTRDIFFT "t"
136 #endif
137 
138 /* sal_IntPtr, sal_uIntPtr are integer types designed to hold pointers so that any valid
139  * pointer to void can be converted to this type and back to a pointer to void and the
140  * result will compare to the original pointer */
141 #if SAL_TYPES_SIZEOFPOINTER == 4
142  typedef sal_Int32 sal_IntPtr;
143  typedef sal_uInt32 sal_uIntPtr;
144  #define SAL_PRIdINTPTR SAL_PRIdINT32
145  #define SAL_PRIuUINTPTR SAL_PRIuUINT32
146  #define SAL_PRIxUINTPTR SAL_PRIxUINT32
147  #define SAL_PRIXUINTPTR SAL_PRIXUINT32
148 #elif SAL_TYPES_SIZEOFPOINTER == 8
149  typedef sal_Int64 sal_IntPtr;
150  typedef sal_uInt64 sal_uIntPtr;
151  #define SAL_PRIdINTPTR SAL_PRIdINT64
152  #define SAL_PRIuUINTPTR SAL_PRIuUINT64
153  #define SAL_PRIxUINTPTR SAL_PRIxUINT64
154  #define SAL_PRIXUINTPTR SAL_PRIXUINT64
155 #else
156  #error "Please make sure SAL_TYPES_SIZEOFPOINTER is defined for your architecture/compiler"
157 #endif
158 
159 /* The following SAL_MIN_INTn defines codify the assumption that the signed
160  * sal_Int types use two's complement representation. Defining them as
161  * "-0x7F... - 1" instead of as "-0x80..." prevents warnings about applying the
162  * unary minus operator to unsigned quantities.
163  */
164 #define SAL_MIN_INT8 ((sal_Int8) (-0x7F - 1))
165 #define SAL_MAX_INT8 ((sal_Int8) 0x7F)
166 #define SAL_MAX_UINT8 ((sal_uInt8) 0xFF)
167 #define SAL_MIN_INT16 ((sal_Int16) (-0x7FFF - 1))
168 #define SAL_MAX_INT16 ((sal_Int16) 0x7FFF)
169 #define SAL_MAX_UINT16 ((sal_uInt16) 0xFFFF)
170 #define SAL_MIN_INT32 ((sal_Int32) (-0x7FFFFFFF - 1))
171 #define SAL_MAX_INT32 ((sal_Int32) 0x7FFFFFFF)
172 #define SAL_MAX_UINT32 ((sal_uInt32) 0xFFFFFFFF)
173 #define SAL_MIN_INT64 ((sal_Int64) (SAL_CONST_INT64(-0x7FFFFFFFFFFFFFFF) - 1))
174 #define SAL_MAX_INT64 ((sal_Int64) SAL_CONST_INT64(0x7FFFFFFFFFFFFFFF))
175 #define SAL_MAX_UINT64 ((sal_uInt64) SAL_CONST_UINT64(0xFFFFFFFFFFFFFFFF))
176 
177 #if SAL_TYPES_SIZEOFPOINTER == 4
178 #define SAL_MAX_SSIZE SAL_MAX_INT32
179 #define SAL_MAX_SIZE SAL_MAX_UINT32
180 #elif SAL_TYPES_SIZEOFPOINTER == 8
181 #define SAL_MAX_SSIZE SAL_MAX_INT64
182 #define SAL_MAX_SIZE SAL_MAX_UINT64
183 #endif
184 
185 #define SAL_MAX_ENUM 0x7fffffff
186 
187 #if defined(_MSC_VER)
188 # define SAL_DLLPUBLIC_EXPORT __declspec(dllexport)
189 # define SAL_JNI_EXPORT __declspec(dllexport)
190 # define SAL_DLLPUBLIC_IMPORT __declspec(dllimport)
191 # define SAL_DLLPRIVATE
192 # define SAL_DLLPUBLIC_TEMPLATE
193 # define SAL_DLLPUBLIC_RTTI
194 # define SAL_CALL __cdecl
195 #elif defined SAL_UNX
196 # if defined(__GNUC__)
197 # if defined(DISABLE_DYNLOADING)
198 # define SAL_DLLPUBLIC_EXPORT __attribute__ ((visibility("hidden")))
199 # define SAL_JNI_EXPORT __attribute__ ((visibility("default")))
200 # define SAL_DLLPUBLIC_IMPORT __attribute__ ((visibility("hidden")))
201 # define SAL_DLLPRIVATE __attribute__ ((visibility("hidden")))
202 # define SAL_DLLPUBLIC_TEMPLATE __attribute__ ((visibility("hidden")))
203 # define SAL_DLLPUBLIC_RTTI
204 # else
205 # define SAL_DLLPUBLIC_EXPORT __attribute__ ((visibility("default")))
206 # define SAL_JNI_EXPORT __attribute__ ((visibility("default")))
207 # define SAL_DLLPUBLIC_IMPORT __attribute__ ((visibility("default")))
208 # define SAL_DLLPRIVATE __attribute__ ((visibility("hidden")))
209 # define SAL_DLLPUBLIC_TEMPLATE __attribute__ ((visibility("default")))
210 # if defined __clang__
211 # if __has_attribute(type_visibility)
212 # define SAL_DLLPUBLIC_RTTI __attribute__ ((type_visibility("default")))
213 # else
214 # define SAL_DLLPUBLIC_RTTI __attribute__ ((visibility("default")))
215 # endif
216 # else
217 # define SAL_DLLPUBLIC_RTTI
218 # endif
219 # endif
220 # else
221 # define SAL_DLLPUBLIC_EXPORT
222 # define SAL_JNI_EXPORT
223 # define SAL_DLLPUBLIC_IMPORT
224 # define SAL_DLLPRIVATE
225 # define SAL_DLLPUBLIC_TEMPLATE
226 # define SAL_DLLPUBLIC_RTTI
227 # endif
228 # define SAL_CALL
229 #else
230 # error("unknown platform")
231 #endif
232 
239 #if defined(__GNUC__)
240 # if defined(DISABLE_DYNLOADING)
241 # define SAL_EXCEPTION_DLLPUBLIC_EXPORT __attribute__((visibility("default")))
242 # else
243 # define SAL_EXCEPTION_DLLPUBLIC_EXPORT SAL_DLLPUBLIC_EXPORT
244 # endif
245 # define SAL_EXCEPTION_DLLPRIVATE SAL_DLLPRIVATE
246 #else
247 # define SAL_EXCEPTION_DLLPUBLIC_EXPORT
248 # define SAL_EXCEPTION_DLLPRIVATE
249 #endif
250 
257 #if defined LIBO_INTERNAL_ONLY && defined __cplusplus
258 #define SAL_WARN_UNUSED_RESULT [[nodiscard]]
259 #elif (defined __GNUC__ \
260  && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1))) \
261  || defined __clang__
262 # define SAL_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
263 #else
264 # define SAL_WARN_UNUSED_RESULT
265 #endif
266 
271 #ifdef _MSC_VER
272 # define SAL_NO_VTABLE __declspec(novtable)
273 #else
274 # define SAL_NO_VTABLE
275 #endif
276 
277 #ifdef _WIN32
278 # pragma pack(push, 8)
279 #endif
280 
283 typedef struct _sal_Sequence
284 {
287  sal_Int32 nRefCount;
290  sal_Int32 nElements;
293  char elements[1];
294 } sal_Sequence;
295 
296 #define SAL_SEQUENCE_HEADER_SIZE ((sal_Size) offsetof(sal_Sequence,elements))
297 
298 #if defined( _WIN32)
299 #pragma pack(pop)
300 #endif
301 
302 #ifdef __cplusplus
303 }
304 #endif /* __cplusplus */
305 
310 #if defined __cplusplus
311 #if __cplusplus >= 201103L
312 #define SAL_THROW_EXTERN_C() noexcept
313 #else
314 #define SAL_THROW_EXTERN_C() throw ()
315 #endif
316 #else
317 #define SAL_THROW_EXTERN_C()
318 #endif
319 
320 #ifdef __cplusplus
321 
326 #if defined(LIBO_INTERNAL_ONLY) && defined(__COVERITY__)
327 # define COVERITY_NOEXCEPT_FALSE noexcept(false)
328 #else
329 # define COVERITY_NOEXCEPT_FALSE
330 #endif
331 
333 {
337 };
338 
339 namespace com { namespace sun { namespace star { } } }
340 
345 namespace css = ::com::sun::star;
346 
355 #if defined LIBO_INTERNAL_ONLY
356 #define SAL_DELETED_FUNCTION = delete
357 #else
358 #define SAL_DELETED_FUNCTION
359 #endif
360 
368 #if defined LIBO_INTERNAL_ONLY
369 #define SAL_OVERRIDE override
370 #else
371 #define SAL_OVERRIDE
372 #endif
373 
381 #if defined LIBO_INTERNAL_ONLY
382 #define SAL_CONSTEXPR constexpr
383 #else
384 #define SAL_CONSTEXPR
385 #endif
386 
393 #if __cplusplus >= 201103L
394 #define SAL_NOEXCEPT noexcept
395 #else
396 #define SAL_NOEXCEPT throw ()
397 #endif
398 
399 #endif /* __cplusplus */
400 
401 #ifdef __cplusplus
402 
403 namespace sal {
404 
416 template< typename T1, typename T2 > inline T1 static_int_cast(T2 n) {
417  return static_cast< T1 >(n);
418 }
419 
420 }
421 
422 #else /* __cplusplus */
423 
436 #define SAL_INT_CAST(type, expr) ((type) (expr))
437 
438 #endif /* __cplusplus */
439 
445 #if defined __GNUC__ || defined __clang__
446 #if defined LIBO_INTERNAL_ONLY
447 # define SAL_DEPRECATED(message) __attribute__((deprecated(message)))
448 #else
449 # define SAL_DEPRECATED(message) __attribute__((deprecated))
450 #endif
451 #elif defined(_MSC_VER)
452 # define SAL_DEPRECATED(message) __declspec(deprecated(message))
453 #else
454 # define SAL_DEPRECATED(message)
455 #endif
456 
468 #ifdef LIBO_INTERNAL_ONLY
469 # define SAL_DEPRECATED_INTERNAL(message)
470 #else
471 # define SAL_DEPRECATED_INTERNAL(message) SAL_DEPRECATED(message)
472 #endif
473 
481 #if defined LIBO_INTERNAL_ONLY && defined __GNUC__
482 #define SAL_WNODEPRECATED_DECLARATIONS_PUSH \
483  _Pragma(SAL_STRINGIFY_ARG(GCC diagnostic push)) \
484  _Pragma(SAL_STRINGIFY_ARG(GCC diagnostic ignored "-Wdeprecated-declarations"))
485 #define SAL_WNODEPRECATED_DECLARATIONS_POP \
486  _Pragma(SAL_STRINGIFY_ARG(GCC diagnostic pop))
487 #else
488 # define SAL_WNODEPRECATED_DECLARATIONS_PUSH
489 # define SAL_WNODEPRECATED_DECLARATIONS_POP
490 #endif
491 
508 #ifdef _MSC_VER
509 #define SAL_WNOUNREACHABLE_CODE_PUSH \
510  __pragma(warning(push)) \
511  __pragma(warning(disable:4702)) \
512  __pragma(warning(disable:4722))
513 #define SAL_WNOUNREACHABLE_CODE_POP \
514  __pragma(warning(pop))
515 #else
516 /* Add definitions for GCC and Clang if needed */
517 #define SAL_WNOUNREACHABLE_CODE_PUSH
518 #define SAL_WNOUNREACHABLE_CODE_POP
519 #endif
520 
544 #if defined __cplusplus
545 #if defined __GNUC__ || defined __clang__
546 #define SAL_UNUSED_PARAMETER __attribute__ ((unused))
547 #else
548 #define SAL_UNUSED_PARAMETER
549 #endif
550 #endif
551 
564 #if defined LIBO_INTERNAL_ONLY && (defined __GNUC__ || defined __clang__)
565 #define SAL_WARN_UNUSED __attribute__((warn_unused))
566 #else
567 #define SAL_WARN_UNUSED
568 #endif
569 
571 
572 #if defined __GNUC__ || defined __clang__
573 // Macro to try to catch and warn on assignments inside expr.
574 # define SAL_DETAIL_BOOLEAN_EXPR(expr) \
575  __extension__ ({ \
576  int sal_boolean_var_; \
577  if (expr) \
578  sal_boolean_var_ = 1; \
579  else \
580  sal_boolean_var_ = 0; \
581  sal_boolean_var_; \
582  })
583 
594 # define SAL_LIKELY(expr) __builtin_expect(SAL_DETAIL_BOOLEAN_EXPR((expr)), 1)
595 
606 # define SAL_UNLIKELY(expr) __builtin_expect(SAL_DETAIL_BOOLEAN_EXPR((expr)), 0)
607 
619 # define SAL_HOT __attribute__((hot))
620 
634 # define SAL_COLD __attribute__((cold))
635 #else
636 # define SAL_LIKELY(expr) (expr)
637 # define SAL_UNLIKELY(expr) (expr)
638 # define SAL_HOT
639 # define SAL_COLD
640 #endif
641 
643 
645 
654 #ifndef __has_attribute
655 #define __has_attribute(x) 0
656 #endif
657 
658 #if defined LIBO_INTERNAL_ONLY && ((defined __GNUC__ && !defined __clang__) || (defined __clang__ && __has_attribute(returns_nonnull)))
659 #define SAL_RETURNS_NONNULL __attribute__((returns_nonnull))
660 #else
661 #define SAL_RETURNS_NONNULL
662 #endif
663 
665 #if defined LIBO_INTERNAL_ONLY
666 // An annotation mechanism used by some loplugins. The id argument must be an ordinary string
667 // literal. For Clang, this expands to a clang::annotate attribute with an annotation consisting of
668 // the concatenation of a "loplugin:" prefix and the given id suffix. For non-Clang, this expands
669 // to nothing to avoid e.g. -Wattributes from GCC's -Wall.
670 #if defined __clang__
671 #define SAL_LOPLUGIN_ANNOTATE(id) [[clang::annotate("loplugin:" id)]]
672 #else
673 #define SAL_LOPLUGIN_ANNOTATE(id)
674 #endif
675 #endif
676 
677 #endif // INCLUDED_SAL_TYPES_H
678 
679 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
T1 static_int_cast(T2 n)
A static_cast between integral types, to avoid C++ compiler warnings.
Definition: types.h:416
unsigned char sal_Bool
Definition: types.h:18
unsigned char sal_uInt8
Definition: types.h:24
__sal_NoAcquire
Definition: types.h:332
char elements[1]
elements array
Definition: types.h:293
sal_uInt16 sal_Unicode
Definition: types.h:103
struct _sal_Sequence sal_Sequence
This is the binary specification of a SAL sequence.
definition of a no acquire enum for ctors
Definition: types.h:336
This is the binary specification of a SAL sequence.
Definition: types.h:283
sal_Int32 nRefCount
reference count of sequence
Definition: types.h:287
sal_Int32 nElements
element count
Definition: types.h:290
signed char sal_Int8
Definition: types.h:23
void * sal_Handle
Definition: types.h:106