VirtualBox

source: vbox/trunk/include/VBox/com/assert.h@ 76507

Last change on this file since 76507 was 76507, checked in by vboxsync, 6 years ago

/include: scm --fix-header-guards. bugref:9344

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.0 KB
Line 
1/** @file
2 * MS COM / XPCOM Abstraction Layer - Assertion macros for COM/XPCOM.
3 */
4
5/*
6 * Copyright (C) 2006-2017 Oracle Corporation
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 (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 */
25
26#ifndef ___VBox_com_assert_h
27#define ___VBox_com_assert_h
28#ifndef RT_WITHOUT_PRAGMA_ONCE
29# pragma once
30#endif
31
32#include <iprt/assert.h>
33
34/** @defgroup grp_com_assert Assertion Macros for COM/XPCOM
35 * @ingroup grp_com
36 * @{
37 */
38
39
40/**
41 * Asserts that the COM result code is succeeded in strict builds.
42 * In non-strict builds the result code will be NOREF'ed to kill compiler warnings.
43 *
44 * @param hrc The COM result code
45 */
46#define AssertComRC(hrc) \
47 do { AssertMsg(SUCCEEDED(hrc), ("COM RC = %Rhrc (0x%08X)\n", hrc, hrc)); NOREF(hrc); } while (0)
48
49/**
50 * Same as AssertComRC, except the caller already knows we failed.
51 *
52 * @param hrc The COM result code
53 */
54#define AssertComRCFailed(hrc) \
55 do { AssertMsgFailed(("COM RC = %Rhrc (0x%08X)\n", hrc, hrc)); NOREF(hrc); } while (0)
56
57/**
58 * A special version of AssertComRC that returns the given expression
59 * if the result code is failed.
60 *
61 * @param hrc The COM result code
62 * @param RetExpr The expression to return
63 */
64#define AssertComRCReturn(hrc, RetExpr) \
65 AssertMsgReturn(SUCCEEDED(hrc), ("COM RC = %Rhrc (0x%08X)\n", hrc, hrc), RetExpr)
66
67/**
68 * A special version of AssertComRC that returns the given result code
69 * if it is failed.
70 *
71 * @param hrc The COM result code
72 */
73#define AssertComRCReturnRC(hrc) \
74 AssertMsgReturn(SUCCEEDED(hrc), ("COM RC = %Rhrc (0x%08X)\n", hrc, hrc), hrc)
75
76/**
77 * A special version of AssertComRC that returns if the result code is failed.
78 *
79 * @param hrc The COM result code
80 */
81#define AssertComRCReturnVoid(hrc) \
82 AssertMsgReturnVoid(SUCCEEDED(hrc), ("COM RC = %Rhrc (0x%08X)\n", hrc, hrc))
83
84/**
85 * A special version of AssertComRC that evaluates the given expression and
86 * breaks if the result code is failed.
87 *
88 * @param hrc The COM result code
89 * @param PreBreakExpr The expression to evaluate on failure.
90 */
91#define AssertComRCBreak(hrc, PreBreakExpr) \
92 if (!SUCCEEDED(hrc)) { AssertComRCFailed(hrc); PreBreakExpr; break; } else do {} while (0)
93
94/**
95 * A special version of AssertComRC that evaluates the given expression and
96 * throws it if the result code is failed.
97 *
98 * @param hrc The COM result code
99 * @param ThrowMeExpr The expression which result to be thrown on failure.
100 */
101#define AssertComRCThrow(hrc, ThrowMeExpr) \
102 do { if (SUCCEEDED(hrc)) { /*likely*/} else { AssertComRCFailed(hrc); throw (ThrowMeExpr); } } while (0)
103
104/**
105 * A special version of AssertComRC that just breaks if the result code is
106 * failed.
107 *
108 * @param hrc The COM result code
109 */
110#define AssertComRCBreakRC(hrc) \
111 if (!SUCCEEDED(hrc)) { AssertComRCFailed(hrc); break; } else do {} while (0)
112
113/**
114 * A special version of AssertComRC that just throws @a hrc if the result code
115 * is failed.
116 *
117 * @param hrc The COM result code
118 */
119#define AssertComRCThrowRC(hrc) \
120 do { if (SUCCEEDED(hrc)) { /*likely*/ } else { AssertComRCFailed(hrc); throw hrc; } } while (0)
121
122/** @} */
123
124#endif // !___VBox_com_assert_h
125
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