1 /* |
|
2 * Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Implementation for Assert Macros |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef MULASSERT_H_ |
|
20 #define MULASSERT_H_ |
|
21 |
|
22 #include <stdexcept> |
|
23 #include <e32std.h> |
|
24 |
|
25 /** |
|
26 * Assert macro. |
|
27 * It checks expression if expression is evaluated false then panic with specified code. |
|
28 * |
|
29 * @param x Result after expression is evaluated |
|
30 * @param y Error code for Assertion fail |
|
31 */ |
|
32 #define __MUL_ASSERT(x,y) __ASSERT_ALWAYS(x,User::Panic(y,0)) |
|
33 |
|
34 |
|
35 |
|
36 /** |
|
37 * Assert Macro for debug version. |
|
38 * It checks expression if expression is evaluated false then panic with specified code. |
|
39 * |
|
40 * @param x bool result after expression is evaluated |
|
41 * @param y Error code for Assertion fail |
|
42 */ |
|
43 #define __MUL_ASSERT_DEBUG(x,y) __ASSERT_DEBUG(x,User::Panic(y,0)) |
|
44 |
|
45 namespace Alf |
|
46 { |
|
47 |
|
48 /** |
|
49 * Assert function. |
|
50 * It takes tamplate argument that is used kind of expceton that need to be thrown. |
|
51 * It checks expression if expression is evaluated false then it throws logic exception. |
|
52 * |
|
53 * @param aExpression bool result after expression is evaluated |
|
54 * @param aExceptionString description of error |
|
55 */ |
|
56 template<class X> |
|
57 static void MUL_ASSERT(bool aExpression, const char* aExceptionString) |
|
58 { |
|
59 if( !aExpression ) |
|
60 { |
|
61 throw X(aExceptionString); |
|
62 } |
|
63 } |
|
64 |
|
65 |
|
66 |
|
67 /** |
|
68 * Assert function for debug version. |
|
69 * It takes tamplate argument that is used kind of expceton that need to be thrown. |
|
70 * It checks expression if expression is evaluated false then it throws logic exception. |
|
71 * |
|
72 * @param aExpression bool result after expression is evaluated |
|
73 * @param aExceptionString description of error |
|
74 */ |
|
75 template<class X> |
|
76 static void MUL_ASSERT_DEBUG(bool aExpression, const char* aExceptionString) |
|
77 { |
|
78 #ifdef _DEBUG |
|
79 |
|
80 if( !aExpression ) |
|
81 { |
|
82 throw X( aExceptionString ); |
|
83 } |
|
84 |
|
85 #endif // _DEBUG |
|
86 } |
|
87 |
|
88 |
|
89 |
|
90 } // namespace Alf |
|
91 |
|
92 #endif // MULASSERT_H_ |
|
93 |
|
94 // End of file |
|
95 |
|