TAO::details::range_checking< T, dummy > Struct Template Reference

Configurable traits to tradeoff safety vs. performance in the implementation of TAO sequences. More...

#include <Range_Checking_T.h>

List of all members.

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)


Detailed Description

template<typename T, bool dummy>
struct TAO::details::range_checking< T, dummy >

Configurable traits to tradeoff safety vs. performance in the implementation of TAO sequences.

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");
   };
 ...
 ..
 };
 

Todo:
There is no control on a per-sequence type basis, only on a per-underlying type basis, for example, the following two IDL sequences would get the same behavior: // IDL typedef sequence<MyStruct> MyStructSequence; typedef sequence<MyStruct> MyStructList;
Todo:
There is no way to control behavior on a per-sequence basis, i.e. to have some sequences of longs checked while others are not. This is easy to fix, simply:
  • make all members of safety_traits non-static
  • have each sequence contain their own instance of safety_traits
  • grant users read/write access to the safety_traits of each sequence but there are footprint consequences to that approach. Until there is more demand to justify the cost, I will not implement such a change.

Member Typedef Documentation

template<typename T , bool dummy>
typedef T TAO::details::range_checking< T, dummy >::value_type


Member Function Documentation

template<typename T , bool dummy>
static void TAO::details::range_checking< T, dummy >::check ( CORBA::ULong  ,
CORBA::ULong  ,
CORBA::ULong  ,
char const *   
) [inline, static]

template<typename T , bool dummy>
static void TAO::details::range_checking< T, dummy >::check_length ( CORBA::ULong ,
CORBA::ULong   
) [inline, static]


The documentation for this struct was generated from the following file:

Generated on Mon Jul 13 16:28:41 2009 for TAO by  doxygen 1.5.8