TypeCode_Case_T.cpp

Go to the documentation of this file.
00001 // $Id: TypeCode_Case_T.cpp 76999 2007-02-12 07:13:45Z johnnyw $
00002 
00003 #ifndef TAO_TYPECODE_CASE_T_CPP
00004 #define TAO_TYPECODE_CASE_T_CPP
00005 
00006 #include "tao/AnyTypeCode/TypeCode_Case_T.h"
00007 
00008 #include "tao/CDR.h"
00009 #include "tao/SystemException.h"
00010 #include "tao/AnyTypeCode/Any.h"
00011 #include "ace/CORBA_macros.h"
00012 
00013 #ifndef __ACE_INLINE__
00014 # include "tao/AnyTypeCode/TypeCode_Case_T.inl"
00015 #endif /* __ACE_INLINE__ */
00016 
00017 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00018 
00019 namespace TAO
00020 {
00021   namespace TypeCode
00022   {
00023     template <typename T>
00024     struct Case_Traits
00025     {
00026       inline static T any_from (T v)
00027       {
00028         return v;
00029       }
00030 
00031       inline static T & any_to (T & v)
00032       {
00033         return v;
00034       }
00035     };
00036 
00037     // Specializations for types that require wrapper for Any
00038     // insertion.  Note that we only define specializations for types
00039     // that can be used in an IDL union discriminator.
00040 
00041     template <>
00042     struct Case_Traits<CORBA::Boolean>
00043     {
00044       inline static CORBA::Any::from_boolean any_from (CORBA::Boolean v)
00045       {
00046         return CORBA::Any::from_boolean (v);
00047       }
00048 
00049       inline static CORBA::Any::to_boolean any_to (CORBA::Boolean & v)
00050       {
00051         return CORBA::Any::to_boolean (v);
00052       }
00053     };
00054 
00055     template <>
00056     struct Case_Traits<CORBA::Char>
00057     {
00058       inline static CORBA::Any::from_char any_from (CORBA::Char v)
00059       {
00060         return CORBA::Any::from_char (v);
00061       }
00062 
00063       inline static CORBA::Any::to_char any_to (CORBA::Char & v)
00064       {
00065         return CORBA::Any::to_char (v);
00066       }
00067     };
00068 
00069   } // End TypeCode namespace
00070 }  // End TAO namespace
00071 
00072 // ----------------------------------------------------------------
00073 
00074 
00075 template <typename DiscriminatorType,
00076           typename StringType,
00077           typename TypeCodeType>
00078 TAO::TypeCode::Case<StringType, TypeCodeType> *
00079 TAO::TypeCode::Case_T<DiscriminatorType,
00080                       StringType,
00081                       TypeCodeType>::clone (void) const
00082 {
00083   Case<StringType, TypeCodeType> * p = 0;
00084 
00085   typedef Case_T<DiscriminatorType,
00086                  StringType,
00087                  TypeCodeType> case_type;
00088 
00089   // The compiler generated memberwise copy constructor is sufficient.
00090   ACE_NEW_RETURN (p,
00091                   case_type (*this),
00092                   p);
00093 
00094   return p;
00095 }
00096 
00097 template <typename DiscriminatorType,
00098           typename StringType,
00099           typename TypeCodeType>
00100 bool
00101 TAO::TypeCode::Case_T<DiscriminatorType,
00102                       StringType,
00103                       TypeCodeType>::marshal_label (TAO_OutputCDR & cdr) const
00104 {
00105   return
00106     (cdr <<
00107      TAO::TypeCode::Case_Traits<DiscriminatorType>::any_from (this->label_));
00108 }
00109 
00110 template <typename DiscriminatorType,
00111           typename StringType,
00112           typename TypeCodeType>
00113 bool
00114 TAO::TypeCode::Case_T<DiscriminatorType,
00115                       StringType,
00116                       TypeCodeType>::equal_label (CORBA::ULong index,
00117                                                   CORBA::TypeCode_ptr tc
00118                                                   ) const
00119 {
00120   CORBA::Any_var const any = tc->member_label (index);
00121 
00122   // The equality operator == below is guaranteed to be defined for
00123   // the discriminator type since an IDL union discriminator type must
00124   // be any of the following: (1) an integer, (2) a character, (3) a
00125   // boolean, or (4) an enumeration.
00126 
00127   DiscriminatorType tc_label;
00128   if ((any.in ()
00129        >>= TAO::TypeCode::Case_Traits<DiscriminatorType>::any_to (tc_label))
00130       && this->label_ == tc_label)
00131     {
00132       return true;
00133     }
00134 
00135   return false;
00136 }
00137 
00138 template <typename DiscriminatorType,
00139           typename StringType,
00140           typename TypeCodeType>
00141 CORBA::Any *
00142 TAO::TypeCode::Case_T<DiscriminatorType,
00143                       StringType,
00144                       TypeCodeType>::label (void) const
00145 {
00146   CORBA::Any * value = 0;
00147 
00148   ACE_NEW_THROW_EX (value,
00149                     CORBA::Any,
00150                     CORBA::NO_MEMORY ());
00151 
00152   CORBA::Any_var safe_value (value);
00153 
00154   *value <<=
00155     TAO::TypeCode::Case_Traits<DiscriminatorType>::any_from (this->label_);
00156 
00157   return safe_value._retn ();
00158 }
00159 
00160 TAO_END_VERSIONED_NAMESPACE_DECL
00161 
00162 #endif  /* TAO_TYPECODE_CASE_T_CPP */

Generated on Sun Jan 27 13:21:07 2008 for TAO_AnyTypeCode by doxygen 1.3.6