#include <Range_Checking_T.h>
Public Types | |
typedef T | value_type |
Static Public Member Functions | |
static void | check (CORBA::ULong, CORBA::ULong, CORBA::ULong, char const *) |
static void | check_length (CORBA::ULong &, CORBA::ULong) |
The CORBA specification grants certain latitude to implementors by not defining the behavior of sequences under certain conditions. Probably the most clear example is the operator[] access, where the application must set the length to a high enough value before using the operator[].
Implementors that cater to high-performance applications tend to exploit this latitude to the extreme, basically reasoning that correct applications will behave normally, while incorrect applications will crash, but those crashes will be detected during development/testing.
Realizing that this may be a bad tradeoff some implementors offer compile-time hooks to control the behavior of sequences when used improperly, some implementors may go as far as using run-time hooks.
The implementation of sequences calls the following template class in points where the application may trigger undefined behavior. The application developer can use partial (or full) template specialization to introduce her own code at these critical points.
Some examples may help, suppose you want to change your application so for all sequence types the operator[] raises an exception if the index is out of range. Then you would provide the following (partial) template specialization:
template<typename T> struct range_checking<T,true> { void check(CORBA::ULong index, CORBA::ULong length) { if (index < length) return; throw std::range_error("CORBA sequence range error"); }; ... .. };
This specialization must be introduced before any sequence code is seen, therefore, the application would also need to define the following macro in their $ACE_ROOT/ace/config.h file:
Likewise, if the application only wanted to check the range for a special type, say some structure MyStruct, then they would provide a full specialization. Just for giggles, we will also introduce run-time controls to this example:
template<> struct safety_traits<tao::details::value_traits<MyStruct>,true> { bool enable_range_checking; void check_range(CORBA::ULong index, CORBA::ULong length) { if (!enable_range_checking || index < length) return; throw std::range_error("CORBA sequence range error"); }; ... .. };
typedef T TAO::details::range_checking< T, dummy >::value_type |
static void TAO::details::range_checking< T, dummy >::check | ( | CORBA::ULong | , | |
CORBA::ULong | , | |||
CORBA::ULong | , | |||
char const * | ||||
) | [inline, static] |
static void TAO::details::range_checking< T, dummy >::check_length | ( | CORBA::ULong & | , | |
CORBA::ULong | ||||
) | [inline, static] |