VirtualBox

source: vbox/trunk/include/iprt/cdefs.h@ 4697

Last change on this file since 4697 was 4697, checked in by vboxsync, 17 years ago

Force R3 context for DECLCALLBACKMEMBER & DECLCALLBACKPTR

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 41.9 KB
Line 
1/** @file
2 * innotek Portable Runtime - Common C and C++ definitions.
3 */
4
5/*
6 * Copyright (C) 2006-2007 innotek GmbH
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License as published by the Free Software Foundation,
12 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
13 * distribution. VirtualBox OSE is distributed in the hope that it will
14 * be useful, but WITHOUT ANY WARRANTY of any kind.
15 */
16
17#ifndef ___iprt_cdefs_h
18#define ___iprt_cdefs_h
19
20
21/** @defgroup grp_rt_cdefs innotek Portable Runtime Common Definitions and Macros
22 * @{
23 */
24
25/*
26 * Include sys/cdefs.h if present, if not define the stuff we need.
27 */
28#ifdef HAVE_SYS_CDEFS_H
29# if defined(RT_ARCH_LINUX) && defined(__KERNEL__)
30# error "oops"
31# endif
32# include <sys/cdefs.h>
33#else
34
35 /** @def __BEGIN_DECLS
36 * Used to start a block of function declarations which are shared
37 * between C and C++ program.
38 */
39
40 /** @def __END_DECLS
41 * Used to end a block of function declarations which are shared
42 * between C and C++ program.
43 */
44
45 #if defined(__cplusplus)
46 # define __BEGIN_DECLS extern "C" {
47 # define __END_DECLS }
48 #else
49 # define __BEGIN_DECLS
50 # define __END_DECLS
51 #endif
52
53#endif
54
55
56/*
57 * Shut up DOXYGEN warnings and guide it properly thru the code.
58 */
59#ifdef __DOXYGEN__
60#define __AMD64__
61#define __X86__
62#define RT_ARCH_AMD64
63#define RT_ARCH_X86
64#define IN_RING0
65#define IN_RING3
66#define IN_GC
67#define IN_RT_GC
68#define IN_RT_R0
69#define IN_RT_R3
70#define RT_STRICT
71#define Breakpoint
72#define RT_NO_DEPRECATED_MACROS
73#define ARCH_BITS
74#define HC_ARCH_BITS
75#define R3_ARCH_BITS
76#define R0_ARCH_BITS
77#define GC_ARCH_BITS
78#endif /* __DOXYGEN__ */
79
80/* A temporary hack. */
81#ifndef RT_OS_LINUX
82# ifdef __LINUX__
83# define RT_OS_LINUX
84# warning "__LINUX__ without RT_OS_LINUX!"
85# endif
86#endif
87
88/** @def RT_ARCH_X86
89 * Indicates that we're compiling for the X86 architecture.
90 */
91
92/** @def RT_ARCH_AMD64
93 * Indicates that we're compiling for the AMD64 architecture.
94 */
95#if !defined(RT_ARCH_X86) && !defined(RT_ARCH_AMD64)
96# if defined(__amd64__) || defined(__x86_64__) || defined(_M_X64) || defined(__AMD64__)
97# define RT_ARCH_AMD64
98# elif defined(__i386__) || defined(_M_IX86) || defined(__X86__)
99# define RT_ARCH_X86
100# else /* PORTME: append test for new archs. */
101# error "Check what predefined stuff your compiler uses to indicate architecture."
102# endif
103#elif defined(RT_ARCH_X86) && defined(RT_ARCH_AMD64) /* PORTME: append new archs. */
104# error "Both RT_ARCH_X86 and RT_ARCH_AMD64 cannot be defined at the same time!"
105#endif
106
107
108/** @def __X86__
109 * Indicates that we're compiling for the X86 architecture.
110 * @deprecated
111 */
112
113/** @def __AMD64__
114 * Indicates that we're compiling for the AMD64 architecture.
115 * @deprecated
116 */
117#if !defined(__X86__) && !defined(__AMD64__)
118# if defined(RT_ARCH_AMD64)
119# define __AMD64__
120# elif defined(RT_ARCH_X86)
121# define __X86__
122# else
123# error "Check what predefined stuff your compiler uses to indicate architecture."
124# endif
125#elif defined(__X86__) && defined(__AMD64__)
126# error "Both __X86__ and __AMD64__ cannot be defined at the same time!"
127#elif defined(__X86__) && !defined(RT_ARCH_X86)
128# error "Both __X86__ without RT_ARCH_X86!"
129#elif defined(__AMD64__) && !defined(RT_ARCH_AMD64)
130# error "Both __AMD64__ without RT_ARCH_AMD64!"
131#endif
132
133/** @def IN_RING0
134 * Used to indicate that we're compiling code which is running
135 * in Ring-0 Host Context.
136 */
137
138/** @def IN_RING3
139 * Used to indicate that we're compiling code which is running
140 * in Ring-3 Host Context.
141 */
142
143/** @def IN_GC
144 * Used to indicate that we're compiling code which is running
145 * in Guest Context (implies R0).
146 */
147#if !defined(IN_RING3) && !defined(IN_RING0) && !defined(IN_GC)
148# error "You must defined which context the compiled code should run in; IN_RING3, IN_RING0 or IN_GC"
149#endif
150#if (defined(IN_RING3) && (defined(IN_RING0) || defined(IN_GC)) ) \
151 || (defined(IN_RING0) && (defined(IN_RING3) || defined(IN_GC)) ) \
152 || (defined(IN_GC) && (defined(IN_RING3) || defined(IN_RING0)) )
153# error "Only one of the IN_RING3, IN_RING0, IN_GC defines should be defined."
154#endif
155
156
157/** @def ARCH_BITS
158 * Defines the bit count of the current context.
159 */
160#ifndef ARCH_BITS
161# if defined(RT_ARCH_AMD64)
162# define ARCH_BITS 64
163# else
164# define ARCH_BITS 32
165# endif
166#endif
167
168/** @def HC_ARCH_BITS
169 * Defines the host architechture bit count.
170 */
171#ifndef HC_ARCH_BITS
172# ifndef IN_GC
173# define HC_ARCH_BITS ARCH_BITS
174# else
175# define HC_ARCH_BITS 32
176# endif
177#endif
178
179/** @def R3_ARCH_BITS
180 * Defines the host ring-3 architechture bit count.
181 */
182#ifndef R3_ARCH_BITS
183# ifdef IN_RING3
184# define R3_ARCH_BITS ARCH_BITS
185# else
186# define R3_ARCH_BITS HC_ARCH_BITS
187# endif
188#endif
189
190/** @def R0_ARCH_BITS
191 * Defines the host ring-0 architechture bit count.
192 */
193#ifndef R0_ARCH_BITS
194# ifdef IN_RING0
195# define R0_ARCH_BITS ARCH_BITS
196# else
197# define R0_ARCH_BITS HC_ARCH_BITS
198# endif
199#endif
200
201/** @def GC_ARCH_BITS
202 * Defines the guest architechture bit count.
203 */
204#ifndef GC_ARCH_BITS
205# ifdef IN_GC
206# define GC_ARCH_BITS ARCH_BITS
207# else
208# define GC_ARCH_BITS 32
209# endif
210#endif
211
212
213/** @def CTXTYPE
214 * Declare a type differently in GC, R3 and R0.
215 *
216 * @param GCType The GC type.
217 * @param R3Type The R3 type.
218 * @param R0Type The R0 type.
219 * @remark For pointers used only in one context use GCPTRTYPE(), HCPTRTYPE(), R3PTRTYPE() or R0PTRTYPE().
220 */
221#ifdef IN_GC
222# define CTXTYPE(GCType, R3Type, R0Type) GCType
223#elif defined(IN_RING3)
224# define CTXTYPE(GCType, R3Type, R0Type) R3Type
225#else
226# define CTXTYPE(GCType, R3Type, R0Type) R0Type
227#endif
228
229/** @def GCTYPE
230 * Declare a type differently in GC and HC.
231 *
232 * @param GCType The GC type.
233 * @param HCType The HC type.
234 * @remark For pointers used only in one context use GCPTRTYPE(), HCPTRTYPE(), R3PTRTYPE() or R0PTRTYPE().
235 */
236#define GCTYPE(GCType, HCType) CTXTYPE(GCType, HCType, HCType)
237
238/** @def GCPTRTYPE
239 * Declare a pointer which is used in GC but appears in structure(s) used by
240 * both HC and GC. The main purpose is to make sure structures have the same
241 * size when built for different architectures.
242 *
243 * @param GCType The GC type.
244 */
245#define GCPTRTYPE(GCType) CTXTYPE(GCType, RTGCPTR, RTGCPTR)
246
247/** @def HCPTRTYPE
248 * Declare a pointer which is used in HC but appears in structure(s) used by
249 * both HC and GC. The main purpose is to make sure structures have the same
250 * size when built for different architectures.
251 *
252 * @param HCType The HC type.
253 */
254#define HCPTRTYPE(HCType) CTXTYPE(RTHCPTR, HCType, HCType)
255
256/** @def R3PTRTYPE
257 * Declare a pointer which is used in R3 but appears in structure(s) used by
258 * both HC and GC. The main purpose is to make sure structures have the same
259 * size when built for different architectures.
260 *
261 * @param R3Type The R3 type.
262 */
263#define R3PTRTYPE(R3Type) CTXTYPE(RTHCUINTPTR, R3Type, RTHCUINTPTR)
264
265/** @def R0PTRTYPE
266 * Declare a pointer which is used in R0 but appears in structure(s) used by
267 * both HC and GC. The main purpose is to make sure structures have the same
268 * size when built for different architectures.
269 *
270 * @param R0Type The R0 type.
271 */
272#define R0PTRTYPE(R0Type) CTXTYPE(RTHCUINTPTR, RTHCUINTPTR, R0Type)
273
274/** @def CTXSUFF
275 * Adds the suffix of the current context to the passed in
276 * identifier name. The suffix is HC or GC.
277 *
278 * This is macro should only be used in shared code to avoid a forrest of ifdefs.
279 * @param var Identifier name.
280 */
281/** @def OTHERCTXSUFF
282 * Adds the suffix of the other context to the passed in
283 * identifier name. The suffix is HC or GC.
284 *
285 * This is macro should only be used in shared code to avoid a forrest of ifdefs.
286 * @param var Identifier name.
287 */
288#ifdef IN_GC
289# define CTXSUFF(var) var##GC
290# define OTHERCTXSUFF(var) var##HC
291#else
292# define CTXSUFF(var) var##HC
293# define OTHERCTXSUFF(var) var##GC
294#endif
295
296/** @def CTXALLSUFF
297 * Adds the suffix of the current context to the passed in
298 * identifier name. The suffix is R3, R0 or GC.
299 *
300 * This is macro should only be used in shared code to avoid a forrest of ifdefs.
301 * @param var Identifier name.
302 */
303#ifdef IN_GC
304# define CTXALLSUFF(var) var##GC
305#elif defined(IN_RING0)
306# define CTXALLSUFF(var) var##R0
307#else
308# define CTXALLSUFF(var) var##R3
309#endif
310
311/** @def CTXMID
312 * Adds the current context as a middle name of an identifier name
313 * The middle name is HC or GC.
314 *
315 * This is macro should only be used in shared code to avoid a forrest of ifdefs.
316 * @param first First name.
317 * @param last Surname.
318 */
319/** @def OTHERCTXMID
320 * Adds the other context as a middle name of an identifier name
321 * The middle name is HC or GC.
322 *
323 * This is macro should only be used in shared code to avoid a forrest of ifdefs.
324 * @param first First name.
325 * @param last Surname.
326 */
327#ifdef IN_GC
328# define CTXMID(first, last) first##GC##last
329# define OTHERCTXMID(first, last) first##HC##last
330#else
331# define CTXMID(first, last) first##HC##last
332# define OTHERCTXMID(first, last) first##GC##last
333#endif
334
335/** @def CTXALLMID
336 * Adds the current context as a middle name of an identifier name
337 * The middle name is R3, R0 or GC.
338 *
339 * This is macro should only be used in shared code to avoid a forrest of ifdefs.
340 * @param first First name.
341 * @param last Surname.
342 */
343#ifdef IN_GC
344# define CTXALLMID(first, last) first##GC##last
345#elif defined(IN_RING0)
346# define CTXALLMID(first, last) first##R0##last
347#else
348# define CTXALLMID(first, last) first##R3##last
349#endif
350
351
352/** @def R3STRING
353 * A macro which in GC and R0 will return a dummy string while in R3 it will return
354 * the parameter.
355 *
356 * This is typically used to wrap description strings in structures shared
357 * between R3, R0 and/or GC. The intention is to avoid the \#ifdef IN_RING3 mess.
358 *
359 * @param pR3String The R3 string. Only referenced in R3.
360 * @see R0STRING and GCSTRING
361 */
362#ifdef IN_RING3
363# define R3STRING(pR3String) (pR3String)
364#else
365# define R3STRING(pR3String) ("<R3_STRING>")
366#endif
367
368/** @def R0STRING
369 * A macro which in GC and R3 will return a dummy string while in R0 it will return
370 * the parameter.
371 *
372 * This is typically used to wrap description strings in structures shared
373 * between R3, R0 and/or GC. The intention is to avoid the \#ifdef IN_RING0 mess.
374 *
375 * @param pR0String The R0 string. Only referenced in R0.
376 * @see R3STRING and GCSTRING
377 */
378#ifdef IN_RING0
379# define R0STRING(pR0String) (pR0String)
380#else
381# define R0STRING(pR0String) ("<R0_STRING>")
382#endif
383
384/** @def GCSTRING
385 * A macro which in R3 and R0 will return a dummy string while in GC it will return
386 * the parameter.
387 *
388 * This is typically used to wrap description strings in structures shared
389 * between R3, R0 and/or GC. The intention is to avoid the \#ifdef IN_GC mess.
390 *
391 * @param pR0String The GC string. Only referenced in GC.
392 * @see R3STRING, R0STRING
393 */
394#ifdef IN_GC
395# define GCSTRING(pR0String) (pGCString)
396#else
397# define GCSTRING(pR0String) ("<GC_STRING>")
398#endif
399
400/** @def HCSTRING
401 * Macro which in GC will return a dummy string while in HC will return
402 * the parameter.
403 *
404 * This is typically used to wrap description strings in structures shared
405 * between HC and GC. The intention is to avoid the \#ifdef IN_GC kludge.
406 *
407 * @param pHCString The HC string. Only referenced in HC.
408 * @deprecated Use R3STRING or R0STRING instead.
409 */
410#ifdef IN_GC
411# define HCSTRING(pHCString) ("<HC_STRING>")
412#else
413# define HCSTRING(pHCString) (pHCString)
414#endif
415
416
417/** @def RTCALL
418 * The standard calling convention for the Runtime interfaces.
419 */
420#ifdef _MSC_VER
421# define RTCALL __cdecl
422#elif defined(__GNUC__) && defined(IN_RING0) && !(defined(RT_OS_OS2) || defined(RT_ARCH_AMD64)) /* the latter is kernel/gcc */
423# define RTCALL __attribute__((cdecl,regparm(0)))
424#else
425# define RTCALL
426#endif
427
428/** @def DECLEXPORT
429 * How to declare an exported function.
430 * @param type The return type of the function declaration.
431 */
432#if defined(_MSC_VER) || defined(RT_OS_OS2)
433# define DECLEXPORT(type) __declspec(dllexport) type
434#else
435# ifdef VBOX_HAVE_VISIBILITY_HIDDEN
436# define DECLEXPORT(type) __attribute__((visibility("default"))) type
437# else
438# define DECLEXPORT(type) type
439# endif
440#endif
441
442/** @def DECLIMPORT
443 * How to declare an imported function.
444 * @param type The return type of the function declaration.
445 */
446#if defined(_MSC_VER) || (defined(RT_OS_OS2) && !defined(__IBMC__) && !defined(__IBMCPP__))
447# define DECLIMPORT(type) __declspec(dllimport) type
448#else
449# define DECLIMPORT(type) type
450#endif
451
452/** @def DECLASM
453 * How to declare an internal assembly function.
454 * @param type The return type of the function declaration.
455 */
456#ifdef __cplusplus
457# ifdef _MSC_VER
458# define DECLASM(type) extern "C" type __cdecl
459# else
460# define DECLASM(type) extern "C" type
461# endif
462#else
463# ifdef _MSC_VER
464# define DECLASM(type) type __cdecl
465# else
466# define DECLASM(type) type
467# endif
468#endif
469
470/** @def DECLASMTYPE
471 * How to declare an internal assembly function type.
472 * @param type The return type of the function.
473 */
474#ifdef _MSC_VER
475# define DECLASMTYPE(type) type __cdecl
476#else
477# define DECLASMTYPE(type) type
478#endif
479
480/** @def DECLCALLBACK
481 * How to declare an call back function type.
482 * @param type The return type of the function declaration.
483 */
484#define DECLCALLBACK(type) type RTCALL
485
486/** @def DECLCALLBACKPTR
487 * How to declare an call back function pointer.
488 * @param type The return type of the function declaration.
489 * @param name The name of the variable member.
490 */
491#ifdef IN_RING3
492# define DECLCALLBACKPTR(type, name) type (RTCALL * name)
493#else
494# define DECLCALLBACKPTR(type, name) RTR3PTR name
495#endif
496
497/** @def DECLCALLBACKMEMBER
498 * How to declare an call back function pointer member.
499 * @param type The return type of the function declaration.
500 * @param name The name of the struct/union/class member.
501 */
502#ifdef IN_RING3
503# define DECLCALLBACKMEMBER(type, name) type (RTCALL * name)
504#else
505# define DECLCALLBACKMEMBER(type, name) RTR3PTR name
506#endif
507
508/** @def DECLR3CALLBACKMEMBER
509 * How to declare an call back function pointer member - R3 Ptr.
510 * @param type The return type of the function declaration.
511 * @param name The name of the struct/union/class member.
512 * @param args The argument list enclosed in parentheses.
513 */
514#ifdef IN_RING3
515# define DECLR3CALLBACKMEMBER(type, name, args) type (RTCALL * name) args
516#else
517# define DECLR3CALLBACKMEMBER(type, name, args) RTR3PTR name
518#endif
519
520/** @def DECLGCCALLBACKMEMBER
521 * How to declare an call back function pointer member - GC Ptr.
522 * @param type The return type of the function declaration.
523 * @param name The name of the struct/union/class member.
524 * @param args The argument list enclosed in parentheses.
525 */
526#ifdef IN_GC
527# define DECLGCCALLBACKMEMBER(type, name, args) type (RTCALL * name) args
528#else
529# define DECLGCCALLBACKMEMBER(type, name, args) RTGCPTR name
530#endif
531
532/** @def DECLR0CALLBACKMEMBER
533 * How to declare an call back function pointer member - R0 Ptr.
534 * @param type The return type of the function declaration.
535 * @param name The name of the struct/union/class member.
536 * @param args The argument list enclosed in parentheses.
537 */
538#ifdef IN_RING0
539# define DECLR0CALLBACKMEMBER(type, name, args) type (RTCALL * name) args
540#else
541# define DECLR0CALLBACKMEMBER(type, name, args) RTR0PTR name
542#endif
543
544/** @def DECLINLINE
545 * How to declare a function as inline.
546 * @param type The return type of the function declaration.
547 */
548#ifdef __GNUC__
549# define DECLINLINE(type) static inline type
550#elif defined(__cplusplus)
551# define DECLINLINE(type) inline type
552#elif defined(_MSC_VER)
553# define DECLINLINE(type) _inline type
554#elif defined(__IBMC__)
555# define DECLINLINE(type) _Inline type
556#else
557# define DECLINLINE(type) inline type
558#endif
559
560
561/** @def IN_RT_R0
562 * Used to indicate whether we're inside the same link module as
563 * the HC Ring-0 Runtime Library.
564 */
565/** @def RTR0DECL(type)
566 * Runtime Library HC Ring-0 export or import declaration.
567 * @param type The return type of the function declaration.
568 */
569#ifdef IN_RT_R0
570# define RTR0DECL(type) DECLEXPORT(type) RTCALL
571#else
572# define RTR0DECL(type) DECLIMPORT(type) RTCALL
573#endif
574
575/** @def IN_RT_R3
576 * Used to indicate whether we're inside the same link module as
577 * the HC Ring-3 Runtime Library.
578 */
579/** @def RTR3DECL(type)
580 * Runtime Library HC Ring-3 export or import declaration.
581 * @param type The return type of the function declaration.
582 */
583#ifdef IN_RT_R3
584# define RTR3DECL(type) DECLEXPORT(type) RTCALL
585#else
586# define RTR3DECL(type) DECLIMPORT(type) RTCALL
587#endif
588
589/** @def IN_RT_GC
590 * Used to indicate whether we're inside the same link module as
591 * the GC Runtime Library.
592 */
593/** @def RTGCDECL(type)
594 * Runtime Library HC Ring-3 export or import declaration.
595 * @param type The return type of the function declaration.
596 */
597#ifdef IN_RT_GC
598# define RTGCDECL(type) DECLEXPORT(type) RTCALL
599#else
600# define RTGCDECL(type) DECLIMPORT(type) RTCALL
601#endif
602
603/** @def RTDECL(type)
604 * Runtime Library export or import declaration.
605 * Functions declared using this macro exists in all contexts.
606 * @param type The return type of the function declaration.
607 */
608#if defined(IN_RT_R3) || defined(IN_RT_GC) || defined(IN_RT_R0)
609# define RTDECL(type) DECLEXPORT(type) RTCALL
610#else
611# define RTDECL(type) DECLIMPORT(type) RTCALL
612#endif
613
614/** @def RTDATADECL(type)
615 * Runtime Library export or import declaration.
616 * Data declared using this macro exists in all contexts.
617 * @param type The return type of the function declaration.
618 */
619#if defined(IN_RT_R3) || defined(IN_RT_GC) || defined(IN_RT_R0)
620# define RTDATADECL(type) DECLEXPORT(type)
621#else
622# define RTDATADECL(type) DECLIMPORT(type)
623#endif
624
625
626/** @def RT_NOCRT
627 * Symbol name wrapper for the No-CRT bits.
628 *
629 * In order to coexist in the same process as other CRTs, we need to
630 * decorate the symbols such that they don't conflict the ones in the
631 * other CRTs. The result of such conflicts / duplicate symbols can
632 * confuse the dynamic loader on unix like systems.
633 *
634 * Define RT_WITHOUT_NOCRT_WRAPPERS to drop the wrapping.
635 */
636/** @def RT_NOCRT_STR
637 * Same as RT_NOCRT only it'll return a double quoted string of the result.
638 */
639#ifndef RT_WITHOUT_NOCRT_WRAPPERS
640# define RT_NOCRT(name) nocrt_ ## name
641# define RT_NOCRT_STR(name) "nocrt_" # name
642#else
643# define RT_NOCRT(name) name
644# define RT_NOCRT_STR(name) #name
645#endif
646
647
648
649/** @def RT_LIKELY
650 * Give the compiler a hint that an expression is very likely to hold true.
651 *
652 * Some compilers support explicit branch prediction so that the CPU backend
653 * can hint the processor and also so that code blocks can be reordered such
654 * that the predicted path sees a more linear flow, thus improving cache
655 * behaviour, etc.
656 *
657 * IPRT provides the macros RT_LIKELY() and RT_UNLIKELY() as a way to utilize
658 * this compiler feature when present.
659 *
660 * A few notes about the usage:
661 *
662 * - Generally, use RT_UNLIKELY() with error condition checks (unless you
663 * have some _strong_ reason to do otherwise, in which case document it),
664 * and/or RT_LIKELY() with success condition checks, assuming you want
665 * to optimize for the success path.
666 *
667 * - Other than that, if you don't know the likelihood of a test succeeding
668 * from empirical or other 'hard' evidence, don't make predictions unless
669 * you happen to be a Dirk Gently.
670 *
671 * - These macros are meant to be used in places that get executed a lot. It
672 * is wasteful to make predictions in code that is executed seldomly (e.g.
673 * at subsystem initialization time) as the basic block reording that this
674 * affecs can often generate larger code.
675 *
676 * - Note that RT_SUCCESS() and RT_FAILURE() already makes use of RT_LIKELY()
677 * and RT_UNLIKELY(). Should you wish for prediction free status checks,
678 * use the RT_SUCCESS_NP() and RT_FAILURE_NP() macros instead.
679 *
680 *
681 * @returns the boolean result of the expression.
682 * @param expr The expression that's very likely to be true.
683 * @see RT_UNLIKELY
684 */
685/** @def RT_UNLIKELY
686 * Give the compiler a hint that an expression is highly unlikely hold true.
687 *
688 * See the usage instructions give in the RT_LIKELY() docs.
689 *
690 * @returns the boolean result of the expression.
691 * @param expr The expression that's very unlikely to be true.
692 * @see RT_LIKELY
693 */
694#if defined(__GNUC__)
695# if __GNUC__ >= 3
696# define RT_LIKELY(expr) __builtin_expect(!!(expr), 1)
697# define RT_UNLIKELY(expr) __builtin_expect(!!(expr), 0)
698# else
699# define RT_LIKELY(expr) (expr)
700# define RT_UNLIKELY(expr) (expr)
701# endif
702#else
703# define RT_LIKELY(expr) (expr)
704# define RT_UNLIKELY(expr) (expr)
705#endif
706
707
708/** @def RT_BIT
709 * Make a bitmask for one integer sized bit.
710 * @param bit Bit number.
711 */
712#define RT_BIT(bit) (1U << (bit))
713
714/** @def RT_BIT_32
715 * Make a 32-bit bitmask for one bit.
716 * @param bit Bit number.
717 */
718#define RT_BIT_32(bit) (UINT32_C(1) << (bit))
719
720/** @def RT_BIT_64
721 * Make a 64-bit bitmask for one bit.
722 * @param bit Bit number.
723 */
724#define RT_BIT_64(bit) (UINT64_C(1) << (bit))
725
726/** @def RT_ALIGN
727 * Align macro.
728 * @param u Value to align.
729 * @param uAlignment The alignment. Power of two!
730 *
731 * @remark Be extremely careful when using this macro with type which sizeof != sizeof int.
732 * When possible use any of the other RT_ALIGN_* macros. And when that's not
733 * possible, make 101% sure that uAlignment is specified with a right sized type.
734 *
735 * Specifying an unsigned 32-bit alignment constant with a 64-bit value will give
736 * you a 32-bit return value!
737 *
738 * In short: Don't use this macro. Use RT_ALIGN_T() instead.
739 */
740#define RT_ALIGN(u, uAlignment) ( ((u) + ((uAlignment) - 1)) & ~((uAlignment) - 1) )
741
742/** @def RT_ALIGN_T
743 * Align macro.
744 * @param u Value to align.
745 * @param uAlignment The alignment. Power of two!
746 * @param type Integer type to use while aligning.
747 * @remark This macro is the prefered alignment macro, it doesn't have any of the pitfalls RT_ALIGN has.
748 */
749#define RT_ALIGN_T(u, uAlignment, type) ( ((type)(u) + ((uAlignment) - 1)) & ~(type)((uAlignment) - 1) )
750
751/** @def RT_ALIGN_32
752 * Align macro for a 32-bit value.
753 * @param u32 Value to align.
754 * @param uAlignment The alignment. Power of two!
755 */
756#define RT_ALIGN_32(u32, uAlignment) RT_ALIGN_T(u32, uAlignment, uint32_t)
757
758/** @def RT_ALIGN_64
759 * Align macro for a 64-bit value.
760 * @param u64 Value to align.
761 * @param uAlignment The alignment. Power of two!
762 */
763#define RT_ALIGN_64(u64, uAlignment) RT_ALIGN_T(u64, uAlignment, uint64_t)
764
765/** @def RT_ALIGN_Z
766 * Align macro for size_t.
767 * @param cb Value to align.
768 * @param uAlignment The alignment. Power of two!
769 */
770#define RT_ALIGN_Z(cb, uAlignment) RT_ALIGN_T(cb, uAlignment, size_t)
771
772/** @def RT_ALIGN_P
773 * Align macro for pointers.
774 * @param pv Value to align.
775 * @param uAlignment The alignment. Power of two!
776 */
777#define RT_ALIGN_P(pv, uAlignment) RT_ALIGN_PT(pv, uAlignment, void *)
778
779/** @def RT_ALIGN_PT
780 * Align macro for pointers with type cast.
781 * @param u Value to align.
782 * @param uAlignment The alignment. Power of two!
783 * @param CastType The type to cast the result to.
784 */
785#define RT_ALIGN_PT(u, uAlignment, CastType) ((CastType)RT_ALIGN_T(u, uAlignment, uintptr_t))
786
787/** @def RT_ALIGN_R3PT
788 * Align macro for ring-3 pointers with type cast.
789 * @param u Value to align.
790 * @param uAlignment The alignment. Power of two!
791 * @param CastType The type to cast the result to.
792 */
793#define RT_ALIGN_R3PT(u, uAlignment, CastType) ((CastType)RT_ALIGN_T(u, uAlignment, RTR3UINTPTR))
794
795/** @def RT_ALIGN_R0PT
796 * Align macro for ring-0 pointers with type cast.
797 * @param u Value to align.
798 * @param uAlignment The alignment. Power of two!
799 * @param CastType The type to cast the result to.
800 */
801#define RT_ALIGN_R0PT(u, uAlignment, CastType) ((CastType)RT_ALIGN_T(u, uAlignment, RTR0UINTPTR))
802
803/** @def RT_ALIGN_GCPT
804 * Align macro for GC pointers with type cast.
805 * @param u Value to align.
806 * @param uAlignment The alignment. Power of two!
807 * @param CastType The type to cast the result to.
808 */
809#define RT_ALIGN_GCPT(u, uAlignment, CastType) ((CastType)RT_ALIGN_T(u, uAlignment, RTGCUINTPTR))
810
811
812/** @def RT_OFFSETOF
813 * Our own special offsetof() variant.
814 *
815 * This differs from the usual offsetof() in that it's not relying on builtin
816 * compiler stuff and thus can use variables in arrays the structure may
817 * contain. If in this usful to determin the sizes of structures ending
818 * with a variable length field.
819 *
820 * @returns offset into the structure of the specified member.
821 * @param type Structure type.
822 * @param member Member.
823 */
824#define RT_OFFSETOF(type, member) ( (int)(uintptr_t)&( ((type *)(void *)0)->member) )
825
826/** @def RT_SIZEOFMEMB
827 * Get the size of a structure member.
828 *
829 * @returns size of the structure member.
830 * @param type Structure type.
831 * @param member Member.
832 */
833#define RT_SIZEOFMEMB(type, member) ( sizeof(((type *)(void *)0)->member) )
834
835/** @def RT_ELEMENTS
836 * Calcs the number of elements in an array.
837 * @returns Element count.
838 * @param aArray Array in question.
839 */
840#define RT_ELEMENTS(aArray) ( sizeof(aArray) / sizeof((aArray)[0]) )
841
842#ifdef RT_OS_OS2
843/* Undefine RT_MAX since there is an unfortunate clash with the max
844 resource type define in os2.h. */
845# undef RT_MAX
846#endif
847
848/** @def RT_MAX
849 * Finds the maximum value.
850 * @returns The higher of the two.
851 * @param Value1 Value 1
852 * @param Value2 Value 2
853 */
854#define RT_MAX(Value1, Value2) ((Value1) >= (Value2) ? (Value1) : (Value2))
855
856/** @def RT_MIN
857 * Finds the minimum value.
858 * @returns The lower of the two.
859 * @param Value1 Value 1
860 * @param Value2 Value 2
861 */
862#define RT_MIN(Value1, Value2) ((Value1) <= (Value2) ? (Value1) : (Value2))
863
864/** @def RT_ABS
865 * Get the absolute (non-negative) value.
866 * @returns The absolute value of Value.
867 * @param Value The value.
868 */
869#define RT_ABS(Value) ((Value) >= 0 ? (Value) : -(Value))
870
871/** @def RT_LOWORD
872 * Gets the low word (=uint16_t) of something. */
873#define RT_LOWORD(a) ((a) & 0xffff)
874
875/** @def RT_HIWORD
876 * Gets the high word (=uint16_t) of a 32 bit something. */
877#define RT_HIWORD(a) ((a) >> 16)
878
879/** @def RT_LOBYTE
880 * Gets the low byte of something. */
881#define RT_LOBYTE(a) ((a) & 0xff)
882
883/** @def RT_HIBYTE
884 * Gets the low byte of a 16 bit something. */
885#define RT_HIBYTE(a) ((a) >> 8)
886
887/** @def RT_BYTE1
888 * Gets first byte of something. */
889#define RT_BYTE1(a) ((a) & 0xff)
890
891/** @def RT_BYTE2
892 * Gets second byte of something. */
893#define RT_BYTE2(a) (((a) >> 8) & 0xff)
894
895/** @def RT_BYTE3
896 * Gets second byte of something. */
897#define RT_BYTE3(a) (((a) >> 16) & 0xff)
898
899/** @def RT_BYTE4
900 * Gets fourth byte of something. */
901#define RT_BYTE4(a) (((a) >> 24) & 0xff)
902
903
904/** @def RT_MAKE_U64
905 * Constructs a uint64_t value from two uint32_t values.
906 */
907#define RT_MAKE_U64(Lo, Hi) ( (uint64_t)((uint32_t)(Hi)) << 32 | (uint32_t)(Lo) )
908
909/** @def RT_MAKE_U64_FROM_U16
910 * Constructs a uint64_t value from four uint16_t values.
911 */
912#define RT_MAKE_U64_FROM_U16(w0, w1, w2, w3) \
913 ( (uint64_t)((uint16_t)(w3)) << 48 \
914 | (uint64_t)((uint16_t)(w2)) << 32 \
915 | (uint32_t)((uint16_t)(w1)) << 16 \
916 | (uint16_t)(w0) )
917
918/** @def RT_MAKE_U64_FROM_U8
919 * Constructs a uint64_t value from eight uint8_t values.
920 */
921#define RT_MAKE_U64_FROM_U8(b0, b1, b2, b3, b4, b5, b6, b7) \
922 ( (uint64_t)((uint8_t)(b7)) << 56 \
923 | (uint64_t)((uint8_t)(b6)) << 48 \
924 | (uint64_t)((uint8_t)(b5)) << 40 \
925 | (uint64_t)((uint8_t)(b4)) << 32 \
926 | (uint32_t)((uint8_t)(b3)) << 24 \
927 | (uint32_t)((uint8_t)(b2)) << 16 \
928 | (uint16_t)((uint8_t)(b1)) << 8 \
929 | (uint8_t)(b0) )
930
931/** @def RT_MAKE_U32
932 * Constructs a uint32_t value from two uint16_t values.
933 */
934#define RT_MAKE_U32(Lo, Hi) ( (uint32_t)((uint16_t)(Hi)) << 16 | (uint16_t)(Lo) )
935
936/** @def RT_MAKE_U32_FROM_U8
937 * Constructs a uint32_t value from four uint8_t values.
938 */
939#define RT_MAKE_U32_FROM_U8(b0, b1, b2, b3) \
940 ( (uint32_t)((uint8_t)(b3)) << 24 \
941 | (uint32_t)((uint8_t)(b2)) << 16 \
942 | (uint16_t)((uint8_t)(b1)) << 8 \
943 | (uint8_t)(b0) )
944/** @todo remove this after uses in VUSBUrb.cpp has been corrected. */
945#define MAKE_U32_FROM_U8(b0,b1,b2,b3) RT_MAKE_U32_FROM_U8(b0,b1,b2,b3)
946
947/** @def RT_MAKE_U16
948 * Constructs a uint32_t value from two uint16_t values.
949 */
950#define RT_MAKE_U16(Lo, Hi) ( (uint16_t)((uint8_t)(Hi)) << 8 | (uint8_t)(Lo) )
951
952
953/** @def RT_H2LE_U64
954 * Converts uint64_t value from host to little endian byte order. */
955#define RT_H2LE_U64(u64) (u64)
956
957/** @def RT_H2LE_U32
958 * Converts uint32_t value from host to little endian byte order. */
959#define RT_H2LE_U32(u32) (u32)
960
961/** @def RT_H2LE_U16
962 * Converts uint16_t value from host to little endian byte order. */
963#define RT_H2LE_U16(u16) (u16)
964
965/** @def RT_LE2H_U64
966 * Converts uint64_t value from little endian to host byte order. */
967#define RT_LE2H_U64(u64) (u64)
968
969/** @def RT_LE2H_U32
970 * Converts uint32_t value from little endian to host byte order. */
971#define RT_LE2H_U32(u32) (u32)
972
973/** @def RT_LE2H_U16
974 * Converts uint16_t value from little endian to host byte order. */
975#define RT_LE2H_U16(u16) (u16)
976
977
978/** @def RT_H2BE_U64
979 * Converts uint64_t value from host to big endian byte order. */
980#define RT_H2BE_U64(u64) RT_MAKE_U64_FROM_U32(RT_H2BE_U32((u64) >> 32), RT_H2BE_U32((u64) & 0xffffffff))
981
982/** @def RT_H2BE_U32
983 * Converts uint32_t value from host to big endian byte order. */
984#define RT_H2BE_U32(u32) (RT_BYTE4(u32) | (RT_BYTE3(u32) << 8) | (RT_BYTE2(u32) << 16) | (RT_BYTE1(u32) << 24))
985
986/** @def RT_H2BE_U16
987 * Converts uint16_t value from host to big endian byte order. */
988#define RT_H2BE_U16(u16) (RT_HIBYTE(u16) | (RT_LOBYTE(u16) << 8))
989
990/** @def RT_BE2H_U64
991 * Converts uint64_t value from big endian to host byte order. */
992#define RT_BE2H_U64(u64) RT_MAKE_U64_FROM_U32(RT_H2BE_U32((u64) >> 32), RT_H2BE_U32((u64) & 0xffffffff))
993
994/** @def RT_BE2H_U32
995 * Converts uint32_t value from big endian to host byte order. */
996#define RT_BE2H_U32(u32) (RT_BYTE4(u32) | (RT_BYTE3(u32) << 8) | (RT_BYTE2(u32) << 16) | (RT_BYTE1(u32) << 24))
997
998/** @def RT_BE2H_U16
999 * Converts uint16_t value from big endian to host byte order. */
1000#define RT_BE2H_U16(u16) (RT_HIBYTE(u16) | (RT_LOBYTE(u16) << 8))
1001
1002
1003/** @def RT_H2N_U32
1004 * Converts uint32_t value from host to network byte order. */
1005#define RT_H2N_U32(u32) RT_H2BE_U32(u32)
1006
1007/** @def RT_H2N_U16
1008 * Converts uint16_t value from host to network byte order. */
1009#define RT_H2N_U16(u16) RT_H2BE_U16(u16)
1010
1011/** @def RT_N2H_U32
1012 * Converts uint32_t value from network to host byte order. */
1013#define RT_N2H_U32(u32) RT_BE2H_U32(u32)
1014
1015/** @def RT_N2H_U16
1016 * Converts uint16_t value from network to host byte order. */
1017#define RT_N2H_U16(u16) RT_BE2H_U16(u16)
1018
1019
1020/** @def RT_NO_DEPRECATED_MACROS
1021 * Define RT_NO_DEPRECATED_MACROS to not define deprecated macros.
1022 */
1023#ifndef RT_NO_DEPRECATED_MACROS
1024/** @copydoc BIT
1025 * @deprecated Use RT_BIT.
1026 */
1027# define BIT(bit) RT_BIT(bit)
1028/** @deprecated Use RT_BIT64. */
1029# define BIT64(bit) (1ULL << (bit))
1030/** @copydoc RT_ALIGN_P
1031 * @deprecated use RT_ALIGN_P. */
1032# define ALIGNP(pv, uAlignment) RT_ALIGN_P(pv, uAlignment)
1033/** @copydoc RT_SIZEOFMEMB
1034 * @deprecated Use RT_SIZEOFMEMB. */
1035# define SIZEOFMEMB(type, member) RT_SIZEOFMEMB(type, member)
1036/** @copydoc RT_ELEMENTS
1037 * @deprecated use RT_ELEMENTS. */
1038# define ELEMENTS(aArray) RT_ELEMENTS(aArray)
1039#endif
1040
1041
1042/*
1043 * The BSD sys/param.h + machine/param.h file is a major source of
1044 * namespace pollution. Kill off some of the worse ones unless we're
1045 * compiling kernel code.
1046 */
1047#if defined(RT_OS_DARWIN) \
1048 && !defined(KERNEL) \
1049 && !defined(RT_NO_BSD_PARAM_H_UNDEFING) \
1050 && ( defined(_SYS_PARAM_H_) || defined(_I386_PARAM_H_) )
1051/* sys/param.h: */
1052# undef PSWP
1053# undef PVM
1054# undef PINOD
1055# undef PRIBO
1056# undef PVFS
1057# undef PZERO
1058# undef PSOCK
1059# undef PWAIT
1060# undef PLOCK
1061# undef PPAUSE
1062# undef PUSER
1063# undef PRIMASK
1064# undef MINBUCKET
1065# undef MAXALLOCSAVE
1066# undef FSHIFT
1067# undef FSCALE
1068
1069/* i386/machine.h: */
1070# undef ALIGN
1071# undef ALIGNBYTES
1072# undef DELAY
1073# undef STATUS_WORD
1074# undef USERMODE
1075# undef BASEPRI
1076# undef MSIZE
1077# undef CLSIZE
1078# undef CLSIZELOG2
1079#endif
1080
1081
1082/** @def NULL
1083 * NULL pointer.
1084 */
1085#ifndef NULL
1086# ifdef __cplusplus
1087# define NULL 0
1088# else
1089# define NULL ((void*)0)
1090# endif
1091#endif
1092
1093/** @def NIL_OFFSET
1094 * NIL offset.
1095 * Whenever we use offsets instead of pointers to save space and relocation effort
1096 * NIL_OFFSET shall be used as the equivalent to NULL.
1097 */
1098#define NIL_OFFSET (~0U)
1099
1100/** @def NOREF
1101 * Keeps the compiler from bitching about an unused parameters.
1102 */
1103#define NOREF(var) (void)(var)
1104
1105/** @def Breakpoint
1106 * Emit a debug breakpoint instruction.
1107 *
1108 * Use this for instrumenting a debugging session only!
1109 * No comitted code shall use Breakpoint().
1110 */
1111#ifdef __GNUC__
1112# define Breakpoint() __asm__ __volatile__("int $3\n\t")
1113#endif
1114#ifdef _MSC_VER
1115# define Breakpoint() __asm int 3
1116#endif
1117#if defined(__IBMC__) || defined(__IBMCPP__)
1118# define Breakpoint() __interrupt(3)
1119#endif
1120#ifndef Breakpoint
1121# error "This compiler is not supported!"
1122#endif
1123
1124
1125/** Size Constants
1126 * (Of course, these are binary computer terms, not SI.)
1127 * @{
1128 */
1129/** 1 K (Kilo) (1 024). */
1130#define _1K 0x00000400
1131/** 4 K (Kilo) (4 096). */
1132#define _4K 0x00001000
1133/** 32 K (Kilo) (32 678). */
1134#define _32K 0x00008000
1135/** 64 K (Kilo) (65 536). */
1136#define _64K 0x00010000
1137/** 128 K (Kilo) (131 072). */
1138#define _128K 0x00020000
1139/** 256 K (Kilo) (262 144). */
1140#define _256K 0x00040000
1141/** 512 K (Kilo) (524 288). */
1142#define _512K 0x00080000
1143/** 1 M (Mega) (1 048 576). */
1144#define _1M 0x00100000
1145/** 2 M (Mega) (2 097 152). */
1146#define _2M 0x00200000
1147/** 4 M (Mega) (4 194 304). */
1148#define _4M 0x00400000
1149/** 1 G (Giga) (1 073 741 824). */
1150#define _1G 0x40000000
1151/** 2 G (Giga) (2 147 483 648). (32-bit) */
1152#define _2G32 0x80000000U
1153/** 2 G (Giga) (2 147 483 648). (64-bit) */
1154#define _2G 0x0000000080000000LL
1155/** 4 G (Giga) (4 294 967 296). */
1156#define _4G 0x0000000100000000LL
1157/** 1 T (Tera) (1 099 511 627 776). */
1158#define _1T 0x0000010000000000LL
1159/** 1 P (Peta) (1 125 899 906 842 624). */
1160#define _1P 0x0004000000000000LL
1161/** 1 E (Exa) (1 152 921 504 606 846 976). */
1162#define _1E 0x1000000000000000LL
1163/** 2 E (Exa) (2 305 843 009 213 693 952). */
1164#define _2E 0x2000000000000000ULL
1165/** @} */
1166
1167/** @def VALID_PTR
1168 * Pointer validation macro.
1169 * @param ptr
1170 */
1171#if defined(RT_ARCH_AMD64)
1172# ifdef IN_RING3
1173# if defined(RT_OS_DARWIN) /* first 4GB is reserved for legacy kernel. */
1174# define VALID_PTR(ptr) ( (uintptr_t)(ptr) >= _4G \
1175 && !((uintptr_t)(ptr) & 0xffff800000000000ULL) )
1176# else
1177# define VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U \
1178 && !((uintptr_t)(ptr) & 0xffff800000000000ULL) )
1179# endif
1180# else /* !IN_RING3 */
1181# define VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U \
1182 && ( ((uintptr_t)(ptr) & 0xffff800000000000ULL) == 0xffff800000000000ULL \
1183 || ((uintptr_t)(ptr) & 0xffff800000000000ULL) == 0) )
1184# endif /* !IN_RING3 */
1185#elif defined(RT_ARCH_X86)
1186# define VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U )
1187#else
1188# error "Architecture identifier missing / not implemented."
1189#endif
1190
1191
1192/** @def N_
1193 * The \#define N_ is used mark a string for translation. This is usable in
1194 * any part of the code, as it is only used by the tools that create message
1195 * catalogs. This macro is a no-op as far as the compiler and code generation
1196 * is concerned.
1197 *
1198 * If you want to both mark a string for translation and translate it, use _.
1199 */
1200#define N_(s) (s)
1201
1202/** @def _
1203 * The \#define _ is used mark a string for translation and to translate it in
1204 * one step.
1205 *
1206 * If you want to only mark a string for translation, use N_.
1207 */
1208#define _(s) gettext(s)
1209
1210
1211/** @def __PRETTY_FUNCTION__
1212 * With GNU C we'd like to use the builtin __PRETTY_FUNCTION__, so define that for the other compilers.
1213 */
1214#if !defined(__GNUC__) && !defined(__PRETTY_FUNCTION__)
1215# define __PRETTY_FUNCTION__ __FUNCTION__
1216#endif
1217
1218
1219/** @def RT_STRICT
1220 * The \#define RT_STRICT controls whether or not assertions and other runtime checks
1221 * should be compiled in or not.
1222 *
1223 * If you want assertions which are not a subject to compile time options use
1224 * the AssertRelease*() flavors.
1225 */
1226#if !defined(RT_STRICT) && defined(DEBUG)
1227# define RT_STRICT
1228#endif
1229
1230/** Source position. */
1231#define RT_SRC_POS __FILE__, __LINE__, __PRETTY_FUNCTION__
1232
1233/** Source position declaration. */
1234#define RT_SRC_POS_DECL const char *pszFile, unsigned iLine, const char *pszFunction
1235
1236/** Source position arguments. */
1237#define RT_SRC_POS_ARGS pszFile, iLine, pszFunction
1238
1239/** @} */
1240
1241
1242/** @defgroup grp_rt_cdefs_cpp Special Macros for C++
1243 * @ingroup grp_rt_cdefs
1244 * @{
1245 */
1246
1247#ifdef __cplusplus
1248
1249/** @def WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP
1250 * Macro to work around error C2593 of the not-so-smart MSVC 7.x ambiguity
1251 * resolver. The following snippet clearly demonstrates the code causing this
1252 * error:
1253 * @code
1254 * class A
1255 * {
1256 * public:
1257 * operator bool() const { return false; }
1258 * operator int*() const { return NULL; }
1259 * };
1260 * int main()
1261 * {
1262 * A a;
1263 * if (!a);
1264 * if (a && 0);
1265 * return 0;
1266 * }
1267 * @endcode
1268 * The code itself seems pretty valid to me and GCC thinks the same.
1269 *
1270 * This macro fixes the compiler error by explicitly overloading implicit
1271 * global operators !, && and || that take the given class instance as one of
1272 * their arguments.
1273 *
1274 * The best is to use this macro right after the class declaration.
1275 *
1276 * @note The macro expands to nothing for compilers other than MSVC.
1277 *
1278 * @param Cls Class to apply the workaround to
1279 */
1280#if defined(_MSC_VER)
1281# define WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP(Cls) \
1282 inline bool operator! (const Cls &that) { return !bool (that); } \
1283 inline bool operator&& (const Cls &that, bool b) { return bool (that) && b; } \
1284 inline bool operator|| (const Cls &that, bool b) { return bool (that) || b; } \
1285 inline bool operator&& (bool b, const Cls &that) { return b && bool (that); } \
1286 inline bool operator|| (bool b, const Cls &that) { return b || bool (that); }
1287#else
1288# define WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP(Cls)
1289#endif
1290
1291/** @def WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP_TPL
1292 * Version of WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP for template classes.
1293 *
1294 * @param Tpl Name of the template class to apply the workaround to
1295 * @param ArgsDecl arguments of the template, as declared in |<>| after the
1296 * |template| keyword, including |<>|
1297 * @param Args arguments of the template, as specified in |<>| after the
1298 * template class name when using the, including |<>|
1299 *
1300 * Example:
1301 * @code
1302 * // template class declaration
1303 * template <class C>
1304 * class Foo { ... };
1305 * // applied workaround
1306 * WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP_TPL (Foo, <class C>, <C>)
1307 * @endcode
1308 */
1309#if defined(_MSC_VER)
1310# define WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP_TPL(Tpl, ArgsDecl, Args) \
1311 template ArgsDecl \
1312 inline bool operator! (const Tpl Args &that) { return !bool (that); } \
1313 template ArgsDecl \
1314 inline bool operator&& (const Tpl Args &that, bool b) { return bool (that) && b; } \
1315 template ArgsDecl \
1316 inline bool operator|| (const Tpl Args &that, bool b) { return bool (that) || b; } \
1317 template ArgsDecl \
1318 inline bool operator&& (bool b, const Tpl Args &that) { return b && bool (that); } \
1319 template ArgsDecl \
1320 inline bool operator|| (bool b, const Tpl Args &that) { return b || bool (that); }
1321#else
1322# define WORKAROUND_MSVC7_ERROR_C2593_FOR_BOOL_OP_TPL(Tpl, ArgsDecl, Args)
1323#endif
1324
1325
1326/** @def DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP
1327 * Declares the copy constructor and the assignment operation as inlined no-ops
1328 * (non-existent functions) for the given class. Use this macro inside the
1329 * private section if you want to effectively disable these operations for your
1330 * class.
1331 *
1332 * @param Cls class name to declare for
1333 */
1334
1335#define DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP(Cls) \
1336 inline Cls (const Cls &); \
1337 inline Cls &operator= (const Cls &);
1338
1339
1340/** @def DECLARE_CLS_NEW_DELETE_NOOP
1341 * Declares the new and delete operations as no-ops (non-existent functions)
1342 * for the given class. Use this macro inside the private section if you want
1343 * to effectively limit creating class instances on the stack only.
1344 *
1345 * @note The destructor of the given class must not be virtual, otherwise a
1346 * compile time error will occur. Note that this is not a drawback: having
1347 * the virtual destructor for a stack-based class is absolutely useless
1348 * (the real class of the stack-based instance is always known to the compiler
1349 * at compile time, so it will always call the correct destructor).
1350 *
1351 * @param Cls class name to declare for
1352 */
1353#define DECLARE_CLS_NEW_DELETE_NOOP(Cls) \
1354 inline static void *operator new (size_t); \
1355 inline static void operator delete (void *);
1356
1357#endif /* defined(__cplusplus) */
1358
1359/** @} */
1360
1361#endif
1362
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette