SCIRun  5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Assert.h
Go to the documentation of this file.
1 /*
2  For more information, please see: http://software.sci.utah.edu
3 
4  The MIT License
5 
6  Copyright (c) 2009 Scientific Computing and Imaging Institute,
7  University of Utah.
8 
9 
10  Permission is hereby granted, free of charge, to any person obtaining a
11  copy of this software and associated documentation files (the "Software"),
12  to deal in the Software without restriction, including without limitation
13  the rights to use, copy, modify, merge, publish, distribute, sublicense,
14  and/or sell copies of the Software, and to permit persons to whom the
15  Software is furnished to do so, subject to the following conditions:
16 
17  The above copyright notice and this permission notice shall be included
18  in all copies or substantial portions of the Software.
19 
20  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26  DEALINGS IN THE SOFTWARE.
27 */
28 
29 
30 
31 ///
32 ///@file Assert.h
33 ///@brief Utility for specifying data invariants (Assertions)
34 ///
35 ///@author
36 /// Steven G. Parker
37 /// Department of Computer Science
38 /// University of Utah
39 ///@date Feb. 1994
40 ///
41 
42 #ifndef SCI_Containers_Assert_h
43 #define SCI_Containers_Assert_h 1
44 
45 #include <sci_defs/error_defs.h>
46 
49 
50 /// @todo: make sure default SCI_ASSERTION_LEVEL is consistent across platforms
51 
52 #define ASSERTFAIL(string) \
53  SCI_THROW(SCIRun::AssertionFailed(string, __FILE__, __LINE__));
54 
55 #define ASSERTMSG_LEGACY(condition,message) \
56  if(!(condition)){ \
57  SCI_THROW(SCIRun::AssertionFailed(message, __FILE__, __LINE__)); \
58  }
59 
60 #if SCI_ASSERTION_LEVEL >= 1
61 # define IFASSERT(x) x
62 # define ASSERTL1(condition) \
63  if(!(condition)){ \
64  SCI_THROW(SCIRun::AssertionFailed(#condition, __FILE__, __LINE__)); \
65  }
66 #else
67 # define ASSERTL1(condition)
68 #endif
69 
70 #if SCI_ASSERTION_LEVEL >= 2
71 # define ASSERTL2(condition) \
72  if(!(condition)){ \
73  SCI_THROW(SCIRun::AssertionFailed(#condition, __FILE__, __LINE__)); \
74  }
75 #else
76 # define ASSERTL2(condition)
77 #endif
78 
79 #if SCI_ASSERTION_LEVEL >= 3
80 # define ASSERTL3(condition) \
81  if(!(condition)){ \
82  SCI_THROW(SCIRun::AssertionFailed(#condition, __FILE__, __LINE__)); \
83  }
84 # define CHECKARRAYBOUNDS(value, lower, upper) \
85  if(value < lower || value >= upper){ \
86  SCI_THROW(SCIRun::ArrayIndexOutOfBounds(value, lower, upper, __FILE__, __LINE__)); \
87  }
88 #else
89 # define ASSERTL3(condition)
90 # define CHECKARRAYBOUNDS(value, lower, upper)
91 #endif
92 
93 #if SCI_ASSERTION_LEVEL == 0
94 # define USE_IF_ASSERTS_ON(line)
95 # define ASSERTL1(condition)
96 # define ASSERTL2(condition)
97 # define ASSERTL3(condition)
98 # define ASSERTEQ(c1, c2)
99 # define ASSERTRANGE(c, l, h)
100 # define IFASSERT(x)
101 #else
102 # define USE_IF_ASSERTS_ON(line) line
103 #endif
104 
105 /* USE_IF_ASSERTS_ON allows us to remove lines that are necessary for
106  code that is needed if asserts are on but causes warnings if
107  asserts are off (ie: in optimized builds). All it does it remove
108  the line or put the line in. */
109 
110 #define ASSERT(condition) ASSERTL2(condition)
111 
112 #endif
Generic exception for internal errors.
Exception to indicate a failed bounds check.