VirtualBox

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

Last change on this file since 97964 was 96407, checked in by vboxsync, 2 years ago

scm copyright and license note update

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