VirtualBox

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

Last change on this file since 67180 was 62476, checked in by vboxsync, 8 years ago

(C) 2016

  • 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-2016 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
29#include <iprt/assert.h>
30
31/** @defgroup grp_com_assert Assertion Macros for COM/XPCOM
32 * @ingroup grp_com
33 * @{
34 */
35
36
37/**
38 * Asserts that the COM result code is succeeded in strict builds.
39 * In non-strict builds the result code will be NOREF'ed to kill compiler warnings.
40 *
41 * @param hrc The COM result code
42 */
43#define AssertComRC(hrc) \
44 do { AssertMsg(SUCCEEDED(hrc), ("COM RC = %Rhrc (0x%08X)\n", hrc, hrc)); NOREF(hrc); } while (0)
45
46/**
47 * Same as AssertComRC, except the caller already knows we failed.
48 *
49 * @param hrc The COM result code
50 */
51#define AssertComRCFailed(hrc) \
52 do { AssertMsgFailed(("COM RC = %Rhrc (0x%08X)\n", hrc, hrc)); NOREF(hrc); } while (0)
53
54/**
55 * A special version of AssertComRC that returns the given expression
56 * if the result code is failed.
57 *
58 * @param hrc The COM result code
59 * @param RetExpr The expression to return
60 */
61#define AssertComRCReturn(hrc, RetExpr) \
62 AssertMsgReturn(SUCCEEDED(hrc), ("COM RC = %Rhrc (0x%08X)\n", hrc, hrc), RetExpr)
63
64/**
65 * A special version of AssertComRC that returns the given result code
66 * if it is failed.
67 *
68 * @param hrc The COM result code
69 */
70#define AssertComRCReturnRC(hrc) \
71 AssertMsgReturn(SUCCEEDED(hrc), ("COM RC = %Rhrc (0x%08X)\n", hrc, hrc), hrc)
72
73/**
74 * A special version of AssertComRC that returns if the result code is failed.
75 *
76 * @param hrc The COM result code
77 */
78#define AssertComRCReturnVoid(hrc) \
79 AssertMsgReturnVoid(SUCCEEDED(hrc), ("COM RC = %Rhrc (0x%08X)\n", hrc, hrc))
80
81/**
82 * A special version of AssertComRC that evaluates the given expression and
83 * breaks if the result code is failed.
84 *
85 * @param hrc The COM result code
86 * @param PreBreakExpr The expression to evaluate on failure.
87 */
88#define AssertComRCBreak(hrc, PreBreakExpr) \
89 if (!SUCCEEDED(hrc)) { AssertComRCFailed(hrc); PreBreakExpr; break; } else do {} while (0)
90
91/**
92 * A special version of AssertComRC that evaluates the given expression and
93 * throws it if the result code is failed.
94 *
95 * @param hrc The COM result code
96 * @param ThrowMeExpr The expression which result to be thrown on failure.
97 */
98#define AssertComRCThrow(hrc, ThrowMeExpr) \
99 do { if (SUCCEEDED(hrc)) { /*likely*/} else { AssertComRCFailed(hrc); throw (ThrowMeExpr); } } while (0)
100
101/**
102 * A special version of AssertComRC that just breaks if the result code is
103 * failed.
104 *
105 * @param hrc The COM result code
106 */
107#define AssertComRCBreakRC(hrc) \
108 if (!SUCCEEDED(hrc)) { AssertComRCFailed(hrc); break; } else do {} while (0)
109
110/**
111 * A special version of AssertComRC that just throws @a hrc if the result code
112 * is failed.
113 *
114 * @param hrc The COM result code
115 */
116#define AssertComRCThrowRC(hrc) \
117 do { if (SUCCEEDED(hrc)) { /*likely*/ } else { AssertComRCFailed(hrc); throw hrc; } } while (0)
118
119/** @} */
120
121#endif // !___VBox_com_assert_h
122
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