Go to the documentation of this file.
17 #ifndef VCSN_MISC_CONTRACT_HH
18 # define VCSN_MISC_CONTRACT_HH
113 void trap (
const char *file,
int line,
114 const char *location,
115 const std::string& message);
123 # define vcsn_trap_(Message, Cond) \
124 vcsn::misc::contract::trap (__FILE__, __LINE__, PRETTY_FUNCTION (), \
125 std::string (Message) + ": " #Cond)
126 # define vcsn_trap__(Message, Cond, Explanation) \
127 vcsn::misc::contract::trap (__FILE__, __LINE__, PRETTY_FUNCTION (), \
128 std::string (Message) + ": " #Cond " // " + Explanation)
129 # define vcsn_trap_2(Message1, Message2) \
130 vcsn::misc::contract::trap (__FILE__, __LINE__, PRETTY_FUNCTION (), \
131 std::string (Message1) + ": " + Message2)
133 # define assertion(Cond) static_cast<void> ((Cond) ? static_cast<void> (0) : vcsn_trap_ ("Assertion failed", Cond))
134 # define precondition(Cond) static_cast<void> ((Cond) ? static_cast<void> (0) : vcsn_trap_ ("Precondition failed", Cond))
135 # define postcondition(Cond) static_cast<void> ((Cond) ? static_cast<void> (0) : vcsn_trap_ ("Postcondition failed", Cond))
137 # define unreachable(Explanation) vcsn_trap_2 ("Unreachable code reached", Explanation)
139 # define assertion_(Cond, Explanation_if_false) static_cast<void> ((Cond) ? static_cast<void> (0) : vcsn_trap__ ("Assertion failed", Cond, Explanation_if_false))
140 # define precondition_(Cond, Explanation_if_false) static_cast<void> ((Cond) ? static_cast<void> (0) : vcsn_trap__ ("Precondition failed", Cond, Explanation_if_false))
141 # define postcondition_(Cond, Explanation_if_false) static_cast<void> ((Cond) ? static_cast<void> (0) : vcsn_trap__ ("Postcondition failed", Cond, Explanation_if_false))
143 # define result_not_computable_if(Cond) static_cast<void> ((Cond) ? vcsn_trap_ ("Result is not computable", Cond) : static_cast<void> (0))
144 # define result_not_computable(Message) vcsn_trap_2 ("Result is not computable", Message)
146 # define pure_service_call(Service) vcsn_trap_ ("Pure abstract service called", Service)
148 # define static_assertion(Cond, Message) \
149 { vcsn::misc::static_if<Cond, int, vcsn::misc::contract::fail<void> >::t Message; Message = 0; }
150 # define static_assertion_(Cond, Message) \
151 { typename vcsn::misc::static_if<Cond, int, vcsn::misc::contract::fail<void> >::t Message; Message = 0; }
153 # define static_error(Message) \
156 vcsn::misc::contract::fail<Message> Message; \
159 # ifndef INTERNAL_CHECKS
161 # define recommendation(Cond) static_cast<void> (0)
162 # define deprecation(Feature) static_cast<void> (0)
163 # define weakness(Feature) static_cast<void> (0)
164 # define incompletion(Feature) static_cast<void> (0)
166 # define WARNING(Message) static_cast<void> (0)
168 # else // ! INTERNAL_CHECKS
171 # define __inconsistency(Message1, Message2) vcsn_trap_2 (Message1, Message2)
173 # define __inconsistency(Message1, Message2) \
174 static_cast<void> (std::cerr << __FILE__ << ':' << __LINE__ << ": " \
175 << Message1 << ": " << Message2 << std::endl)
178 # define recommendation(Cond) \
179 static_cast<void> ((Cond) ? \
180 static_cast<void> (0) : \
181 __inconsistency ("Recommendation", #Cond " Failed."))
182 # define deprecation(Feature) __inconsistency ("Deprecated feature", Feature)
183 # define weakness(Feature) __inconsistency ("Weak feature", Feature)
184 # define incompletion(Feature) __inconsistency ("Incomplete implementation", Feature)
185 # define WARNING(Message) __inconsistency ("Warning", Message)
187 # endif // INTERNAL_CHECKS
189 # else // VCSN_NDEBUG
191 # define static_assertion(Cond, Message) typedef void Message
192 # define static_assertion_(Cond, Message) typedef void Message
193 # define static_error(Message) typedef void Message
195 # define assertion(Cond) static_cast<void> (0)
196 # define precondition(Cond) static_cast<void> (0)
197 # define postcondition(Cond) static_cast<void> (0)
198 # define assertion_(Cond, Explanation_if_false) static_cast<void> (0)
199 # define precondition_(Cond, Explanation_if_false) static_cast<void> (0)
200 # define postcondition_(Cond, Explanation_if_false) static_cast<void> (0)
202 # define unreachable(Explanation) static_cast<void> (0)
204 # define result_not_computable_if(Cond) static_cast<void> (0)
205 # define result_not_computable(Message) static_cast<void> (0)
207 # define pure_service_call(Service) static_cast<void> (0)
209 # define recommendation(Cond) static_cast<void> (0)
210 # define deprecation(Feature) static_cast<void> (0)
211 # define weakness(Feature) static_cast<void> (0)
212 # define incompletion(Feature) static_cast<void> (0)
214 # define WARNING(Message) static_cast<void> (0)
216 # endif // ! VCSN_NDEBUG
218 #endif // ! VCSN_MISC_CONTRACT_HH