Public Member Functions | Static Public Member Functions | Private Attributes

TAO::Any_Special_Impl_T< T, from_T, to_T > Class Template Reference

Template Any class for bounded IDL (w)strings. More...

#include <Any_Special_Impl_T.h>

Inheritance diagram for TAO::Any_Special_Impl_T< T, from_T, to_T >:
Inheritance graph
[legend]
Collaboration diagram for TAO::Any_Special_Impl_T< T, from_T, to_T >:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 Any_Special_Impl_T (_tao_destructor destructor, CORBA::TypeCode_ptr, T *const, CORBA::ULong bound)
virtual ~Any_Special_Impl_T (void)
virtual CORBA::Boolean marshal_value (TAO_OutputCDR &)
CORBA::Boolean demarshal_value (TAO_InputCDR &)
virtual void _tao_decode (TAO_InputCDR &)
virtual const void * value (void) const
virtual void free_value (void)

Static Public Member Functions

static void insert (CORBA::Any &, _tao_destructor destructor, CORBA::TypeCode_ptr, T *const, CORBA::ULong bound)
static CORBA::Boolean extract (const CORBA::Any &, _tao_destructor, CORBA::TypeCode_ptr, const T *&, CORBA::ULong bound)

Private Attributes

T * value_
CORBA::ULong bound_

Detailed Description

template<typename T, typename from_T, typename to_T>
class TAO::Any_Special_Impl_T< T, from_T, to_T >

Template Any class for bounded IDL (w)strings.

Definition at line 35 of file Any_Special_Impl_T.h.


Constructor & Destructor Documentation

template<typename T , typename from_T , typename to_T >
TAO::Any_Special_Impl_T< T, from_T, to_T >::Any_Special_Impl_T ( _tao_destructor  destructor,
CORBA::TypeCode_ptr  tc,
T * const  val,
CORBA::ULong  bound 
)

Definition at line 19 of file Any_Special_Impl_T.cpp.

  : Any_Impl (destructor,
              tc),
    value_ (val),
    bound_ (bound)
{
}

template<typename T , typename from_T , typename to_T >
TAO::Any_Special_Impl_T< T, from_T, to_T >::~Any_Special_Impl_T ( void   )  [virtual]

Definition at line 33 of file Any_Special_Impl_T.cpp.

{
}


Member Function Documentation

template<typename T , typename from_T , typename to_T >
void TAO::Any_Special_Impl_T< T, from_T, to_T >::_tao_decode ( TAO_InputCDR cdr  )  [virtual]

Reimplemented from TAO::Any_Impl.

Definition at line 201 of file Any_Special_Impl_T.cpp.

{
  if (this->value_destructor_ != 0)
    {
      (*this->value_destructor_) (this->value_);
      this->value_ = 0;
    }

  if (! this->demarshal_value (cdr))
    {
      throw ::CORBA::MARSHAL ();
    }
}

template<typename T , typename from_T , typename to_T >
CORBA::Boolean TAO::Any_Special_Impl_T< T, from_T, to_T >::demarshal_value ( TAO_InputCDR cdr  ) 

Definition at line 10 of file Any_Special_Impl_T.inl.

{
  return (cdr >> to_T (this->value_, this->bound_));
}

template<typename T , typename from_T , typename to_T >
CORBA::Boolean TAO::Any_Special_Impl_T< T, from_T, to_T >::extract ( const CORBA::Any any,
_tao_destructor  destructor,
CORBA::TypeCode_ptr  tc,
const T *&  _tao_elem,
CORBA::ULong  bound 
) [static]

Definition at line 76 of file Any_Special_Impl_T.cpp.

{
  _tao_elem = 0;

  try
    {
      CORBA::TypeCode_ptr any_type = any._tao_get_typecode ();
      CORBA::TypeCode_var unaliased_any_type =
        TAO::unaliased_typecode (any_type
                                );

      CORBA::TCKind const any_kind =
        unaliased_any_type->kind ();

      CORBA::TCKind const try_kind = tc->kind ();

      if (any_kind != try_kind)
        {
          return false;
        }

      CORBA::ULong const length = unaliased_any_type->length ();

      if (length != bound)
        {
          return false;
        }

      TAO::Any_Impl * const impl = any.impl ();

      typedef TAO::Any_Special_Impl_T<T, from_T, to_T>
        BOUNDED_TSTRING_ANY_IMPL;

      if (impl && !impl->encoded ())
        {
          TAO::Any_Special_Impl_T<T, from_T, to_T> * const narrow_impl =
            dynamic_cast <BOUNDED_TSTRING_ANY_IMPL *> (impl);

          if (narrow_impl == 0)
            {
              return false;
            }

          _tao_elem = (T *) narrow_impl->value_;
          return true;
        }

      TAO::Any_Special_Impl_T<T, from_T, to_T> *replacement = 0;
      ACE_NEW_RETURN (replacement,
                      BOUNDED_TSTRING_ANY_IMPL (destructor,
                                                tc,
                                                0,
                                                bound),
                      false);

      auto_ptr<TAO::Any_Special_Impl_T<T, from_T, to_T> > replacement_safety (
          replacement
        );

      // We know this will work since the unencoded case is covered above.
      TAO::Unknown_IDL_Type * const unk =
        dynamic_cast<TAO::Unknown_IDL_Type *> (impl);

      if (!unk)
        return false;

      // We don't want the rd_ptr of unk to move, in case it is
      // shared by another Any. This copies the state, not the buffer.
      TAO_InputCDR for_reading (unk->_tao_get_cdr ());

      CORBA::Boolean const good_decode =
        replacement->demarshal_value (for_reading);

      if (good_decode)
        {
          _tao_elem = replacement->value_;
          const_cast<CORBA::Any &> (any).replace (replacement);
          replacement_safety.release ();
          return true;
        }

      // Duplicated by Any_Impl base class constructor.
      ::CORBA::release (tc);
    }
  catch (const ::CORBA::Exception&)
    {
    }

  return false;
}

template<typename T , typename from_T , typename to_T >
void TAO::Any_Special_Impl_T< T, from_T, to_T >::free_value ( void   )  [virtual]

Reimplemented from TAO::Any_Impl.

Definition at line 187 of file Any_Special_Impl_T.cpp.

{
  if (this->value_destructor_ != 0)
    {
      (*this->value_destructor_) (this->value_);
      this->value_destructor_ = 0;
    }

  ::CORBA::release (this->type_);
  this->value_ = 0;
}

template<typename T , typename from_T , typename to_T >
void TAO::Any_Special_Impl_T< T, from_T, to_T >::insert ( CORBA::Any any,
_tao_destructor  destructor,
CORBA::TypeCode_ptr  tc,
T * const  value,
CORBA::ULong  bound 
) [static]

Definition at line 39 of file Any_Special_Impl_T.cpp.

{
  CORBA::TypeCode_var bounded_tc;

  if (bound > 0)
    {
      CORBA::TCKind const kind = tc->kind ();

      bounded_tc =
        TAO::TypeCodeFactory::String_Traits<from_T>::create_typecode (kind,
                                                                      bound);
    }
  else
    {
      bounded_tc = CORBA::TypeCode::_duplicate (tc);
    }

  if (CORBA::is_nil (bounded_tc.in ()))
    return;

  Any_Special_Impl_T<T, from_T, to_T> * new_impl;
  ACE_NEW (new_impl,
           Any_Special_Impl_T (destructor,
                               bounded_tc.in (),
                               value,
                               bound));

  any.replace (new_impl);
}

template<typename T , typename from_T , typename to_T >
CORBA::Boolean TAO::Any_Special_Impl_T< T, from_T, to_T >::marshal_value ( TAO_OutputCDR cdr  )  [virtual]

Implements TAO::Any_Impl.

Definition at line 173 of file Any_Special_Impl_T.cpp.

{
  return (cdr << from_T (this->value_, this->bound_));
}

template<typename T , typename from_T , typename to_T >
const void * TAO::Any_Special_Impl_T< T, from_T, to_T >::value ( void   )  const [virtual]

Definition at line 180 of file Any_Special_Impl_T.cpp.

{
  return this->value_;
}


Member Data Documentation

template<typename T, typename from_T, typename to_T>
CORBA::ULong TAO::Any_Special_Impl_T< T, from_T, to_T >::bound_ [private]

Definition at line 65 of file Any_Special_Impl_T.h.

template<typename T, typename from_T, typename to_T>
T* TAO::Any_Special_Impl_T< T, from_T, to_T >::value_ [private]

Definition at line 64 of file Any_Special_Impl_T.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines