Stun Server  Compliant with the latest RFCs including 5389, 5769, and 5780
discover the local host's own external IP address
chkmacros.h
Go to the documentation of this file.
1 /*
2  Copyright 2011 John Selbie
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 */
16 
17 
18 #ifndef CHKMACROS_H
19 #define CHKMACROS_H
20 
21 #include "hresult.h"
22 
23 
24 
25 template <typename T>
26 inline HRESULT CheckCore(const T t)
27 {
28  t.What_You_Passed_To_Chk_Is_Not_HRESULT();
29  return E_FAIL;
30 }
31 
32 template <typename T>
33 inline bool CheckIfCore(const T t)
34 {
35  t.What_You_Passed_To_ChkIf_Is_Not_bool();
36  return false;
37 }
38 
39 
40 template <>
42 {
43  return t;
44 }
45 
46 template <>
47 inline bool CheckIfCore<bool>(const bool t)
48 {
49  return t;
50 }
51 
52 
53 #define Chk(expr) \
54 { \
55  ((void)hr); \
56  hr = CheckCore((expr)); \
57  if (FAILED(hr)) \
58  { \
59  goto Cleanup; \
60  } \
61 }
62 
63 #define ChkIf(expr, hrerror) \
64 { \
65  ((void)hr); \
66  if (CheckIfCore((expr))) \
67  { \
68  hr = (hrerror); \
69  goto Cleanup; \
70  } \
71 }
72 
73 #define ChkA(expr) \
74 { \
75  ((void)hr); \
76  hr = CheckCore((expr)); \
77  if (FAILED(hr)) \
78  { \
79  ASSERT(false); \
80  goto Cleanup; \
81  } \
82 }
83 
84 #define ChkIfA(expr, hrerror) \
85 { \
86  ((void)hr); \
87  if (CheckIfCore((expr))) \
88  { \
89  ASSERT(false); \
90  hr = (hrerror); \
91  goto Cleanup; \
92  } \
93 }
94 
95 #endif
HRESULT CheckCore(const T t)
Definition: chkmacros.h:26
bool CheckIfCore< bool >(const bool t)
Definition: chkmacros.h:47
HRESULT CheckCore< HRESULT >(const HRESULT t)
Definition: chkmacros.h:41
int32_t HRESULT
Definition: hresult.h:22
bool CheckIfCore(const T t)
Definition: chkmacros.h:33
#define E_FAIL
Definition: hresult.h:56