Merge pull request #2303 from jwillemsen/jwi-803
[ACE_TAO.git] / TAO / tests / Sequence_Unit_Tests / testing_range_checking.hpp
blob2d5986724b79cc56f86cbb2ac790b3dc0989b3a3
1 #ifndef guard_testing_range_checking_hpp
2 #define guard_testing_range_checking_hpp
3 /**
4 * @file
6 * @brief Specialize the range_checking traits in a manner suitable
7 * for testing.
9 * @author Carlos O'Ryan
12 #include "tao/Range_Checking_T.h"
14 #include <sstream>
15 #include <stdexcept>
17 template<typename T>
18 struct testing_range_checking
20 typedef T value_type;
22 inline static void check(
23 CORBA::ULong index,
24 CORBA::ULong length,
25 CORBA::ULong maximum,
26 char const * function_name)
28 if (index < length) {
29 return;
31 std::ostringstream error;
32 error << "Out of range access in " << function_name
33 << ", index=" << index
34 << ", length=" << length
35 << ", maximum=" << maximum;
36 throw std::range_error(error.str());
39 inline static void check_length(
40 CORBA::ULong & new_length,
41 CORBA::ULong maximum)
43 if (maximum < new_length)
45 std::ostringstream error;
46 error << "Invalid bounded sequence length "
47 << ", length=" << new_length
48 << ", maximum=" << maximum;
49 throw std::runtime_error(error.str());
54 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
55 namespace TAO
57 namespace details
60 template<typename T>
61 struct range_checking<T,true>
62 : public testing_range_checking<T>
66 } // namespace details
67 } // namespace TAO
69 TAO_END_VERSIONED_NAMESPACE_DECL
70 #endif // guard_testing_range_checking_hpp