00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef VCSN_MISC_CONTRACT_HH
00018 # define VCSN_MISC_CONTRACT_HH
00019
00025 # ifndef VCSN_NDEBUG
00026 # include <vaucanson/config/system.hh>
00027 # include <vaucanson/misc/static.hh>
00028
00029 # include <iostream>
00030 # include <string>
00031
00032 namespace vcsn {
00033 namespace misc {
00034 namespace contract {
00035
00112
00113 void trap (const char *file, int line,
00114 const char *location,
00115 const std::string& message);
00116
00117 template<typename T>
00118 struct fail;
00119 }
00120 }
00121 }
00122
00123 # define vcsn_trap_(Message, Cond) \
00124 vcsn::misc::contract::trap (__FILE__, __LINE__, PRETTY_FUNCTION (), \
00125 std::string (Message) + ": " #Cond)
00126 # define vcsn_trap__(Message, Cond, Explanation) \
00127 vcsn::misc::contract::trap (__FILE__, __LINE__, PRETTY_FUNCTION (), \
00128 std::string (Message) + ": " #Cond " // " + Explanation)
00129 # define vcsn_trap_2(Message1, Message2) \
00130 vcsn::misc::contract::trap (__FILE__, __LINE__, PRETTY_FUNCTION (), \
00131 std::string (Message1) + ": " + Message2)
00132
00133 # define assertion(Cond) static_cast<void> ((Cond) ? static_cast<void> (0) : vcsn_trap_ ("Assertion failed", Cond))
00134 # define precondition(Cond) static_cast<void> ((Cond) ? static_cast<void> (0) : vcsn_trap_ ("Precondition failed", Cond))
00135 # define postcondition(Cond) static_cast<void> ((Cond) ? static_cast<void> (0) : vcsn_trap_ ("Postcondition failed", Cond))
00136
00137 # define unreachable(Explanation) vcsn_trap_2 ("Unreachable code reached", Explanation)
00138
00139 # define assertion_(Cond, Explanation_if_false) static_cast<void> ((Cond) ? static_cast<void> (0) : vcsn_trap__ ("Assertion failed", Cond, Explanation_if_false))
00140 # define precondition_(Cond, Explanation_if_false) static_cast<void> ((Cond) ? static_cast<void> (0) : vcsn_trap__ ("Precondition failed", Cond, Explanation_if_false))
00141 # define postcondition_(Cond, Explanation_if_false) static_cast<void> ((Cond) ? static_cast<void> (0) : vcsn_trap__ ("Postcondition failed", Cond, Explanation_if_false))
00142
00143 # define result_not_computable_if(Cond) static_cast<void> ((Cond) ? vcsn_trap_ ("Result is not computable", Cond) : static_cast<void> (0))
00144 # define result_not_computable(Message) vcsn_trap_2 ("Result is not computable", Message)
00145
00146 # define pure_service_call(Service) vcsn_trap_ ("Pure abstract service called", Service)
00147
00148 # define static_assertion(Cond, Message) \
00149 { vcsn::misc::static_if<Cond, int, vcsn::misc::contract::fail<void> >::t Message; Message = 0; }
00150 # define static_assertion_(Cond, Message) \
00151 { typename vcsn::misc::static_if<Cond, int, vcsn::misc::contract::fail<void> >::t Message; Message = 0; }
00152
00153 # define static_error(Message) \
00154 { \
00155 struct Message; \
00156 vcsn::misc::contract::fail<Message> Message; \
00157 }
00158
00159 # ifndef INTERNAL_CHECKS
00160
00161 # define recommendation(Cond) static_cast<void> (0)
00162 # define deprecation(Feature) static_cast<void> (0)
00163 # define weakness(Feature) static_cast<void> (0)
00164 # define incompletion(Feature) static_cast<void> (0)
00165
00166 # define WARNING(Message) static_cast<void> (0)
00167
00168 # else // ! INTERNAL_CHECKS
00169
00170 # ifdef STRICT
00171 # define __inconsistency(Message1, Message2) vcsn_trap_2 (Message1, Message2)
00172 # else // ! STRICT
00173 # define __inconsistency(Message1, Message2) \
00174 static_cast<void> (std::cerr << __FILE__ << ':' << __LINE__ << ": " \
00175 << Message1 << ": " << Message2 << std::endl)
00176 # endif // STRICT
00177
00178 # define recommendation(Cond) \
00179 static_cast<void> ((Cond) ? \
00180 static_cast<void> (0) : \
00181 __inconsistency ("Recommendation", #Cond " Failed."))
00182 # define deprecation(Feature) __inconsistency ("Deprecated feature", Feature)
00183 # define weakness(Feature) __inconsistency ("Weak feature", Feature)
00184 # define incompletion(Feature) __inconsistency ("Incomplete implementation", Feature)
00185 # define WARNING(Message) __inconsistency ("Warning", Message)
00186
00187 # endif // INTERNAL_CHECKS
00188
00189 # else // VCSN_NDEBUG
00190
00191 # define static_assertion(Cond, Message) typedef void Message
00192 # define static_assertion_(Cond, Message) typedef void Message
00193 # define static_error(Message) typedef void Message
00194
00195 # define assertion(Cond) static_cast<void> (0)
00196 # define precondition(Cond) static_cast<void> (0)
00197 # define postcondition(Cond) static_cast<void> (0)
00198 # define assertion_(Cond, Explanation_if_false) static_cast<void> (0)
00199 # define precondition_(Cond, Explanation_if_false) static_cast<void> (0)
00200 # define postcondition_(Cond, Explanation_if_false) static_cast<void> (0)
00201
00202 # define unreachable(Explanation) static_cast<void> (0)
00203
00204 # define result_not_computable_if(Cond) static_cast<void> (0)
00205 # define result_not_computable(Message) static_cast<void> (0)
00206
00207 # define pure_service_call(Service) static_cast<void> (0)
00208
00209 # define recommendation(Cond) static_cast<void> (0)
00210 # define deprecation(Feature) static_cast<void> (0)
00211 # define weakness(Feature) static_cast<void> (0)
00212 # define incompletion(Feature) static_cast<void> (0)
00213
00214 # define WARNING(Message) static_cast<void> (0)
00215
00216 # endif // ! VCSN_NDEBUG
00217
00218 #endif // ! VCSN_MISC_CONTRACT_HH