00001 // -*- C++ -*- 00002 00003 //============================================================================= 00004 /** 00005 * @file TypeCode_Case_Base_T.h 00006 * 00007 * $Id: TypeCode_Case_Base_T.h 90386 2010-06-02 13:52:08Z vzykov $ 00008 * 00009 * Header file for @c TAO::TypeCode::Case type. 00010 * 00011 * @author Ossama Othman 00012 */ 00013 //============================================================================= 00014 00015 #ifndef TAO_TYPECODE_CASE_H 00016 #define TAO_TYPECODE_CASE_H 00017 00018 #include /**/ "ace/pre.h" 00019 00020 #include "ace/config-all.h" 00021 00022 #if !defined (ACE_LACKS_PRAGMA_ONCE) 00023 # pragma once 00024 #endif /* ACE_LACKS_PRAGMA_ONCE */ 00025 00026 #include "tao/AnyTypeCode/TypeCode.h" 00027 #include "tao/CORBA_String.h" 00028 00029 TAO_BEGIN_VERSIONED_NAMESPACE_DECL 00030 00031 namespace TAO 00032 { 00033 namespace TypeCode 00034 { 00035 00036 /** 00037 * @class Case 00038 * 00039 * @brief Abstract base class for that represents an IDL @c union 00040 * case/member. 00041 * 00042 * This class hides the actual IDL @c union member label value 00043 * from the @c TAO::TypeCode::Union class by relying on a 00044 * CORBA::Any return value that corresponds to the @c 00045 * CORBA::TypeCode::member_label() return type. It also allows 00046 * the @c TAO::TypeCode::Union class to marshal the member label 00047 * values into a CDR stream without knowledge of the underlying 00048 * member label values. 00049 */ 00050 template <typename StringType, typename TypeCodeType> 00051 class Case 00052 { 00053 public: 00054 00055 /// Constructor. 00056 /** 00057 * Constructor used when creating static @c union @c TypeCodes. 00058 */ 00059 Case (char const * name, TypeCodeType tc); 00060 00061 /// Constructor. 00062 /** 00063 * Constructor used when creating dynamic @c union @c TypeCodes. 00064 */ 00065 Case (void); 00066 00067 /// Destructor. 00068 virtual ~Case (void); 00069 00070 /// Cloning/copying operation. 00071 virtual Case * clone (void) const = 0; 00072 00073 /// Return the IDL @c union case label value embedded within a 00074 /// @c CORBA::Any. 00075 virtual CORBA::Any * label (void) const = 0; 00076 00077 /// Get the name of the @c union case/member. 00078 char const * name (void) const; 00079 00080 /// Set the name of the @c union case/member. 00081 void name (char const * the_name); 00082 00083 /// Get the @c CORBA::TypeCode of the @c union case/member. 00084 /** 00085 * @note The reference count is not manipulated by this method, 00086 * i.e., ownership is retained by this class. 00087 */ 00088 CORBA::TypeCode_ptr type (void) const; 00089 00090 /// Set the @c CORBA::TypeCode of the @c union case/member. 00091 /** 00092 * @note @c CORBA::TypeCode::_duplicate() is called on the 00093 * @c TypeCode @a tc. 00094 */ 00095 void type (CORBA::TypeCode_ptr tc); 00096 00097 /// Marshal this IDL @c union member into the given output CDR 00098 /// stream. 00099 bool marshal (TAO_OutputCDR & cdr, CORBA::ULong offset) const; 00100 00101 /// Check for equality of the @c case attributes contained by this 00102 /// class and the corresponding member attributes at index "@a 00103 /// index" in the given @c TypeCode @a tc. 00104 bool equal (CORBA::ULong index, CORBA::TypeCode_ptr tc) const; 00105 00106 /// Check for equivalence of the @c case attributes contained by 00107 /// this class and the corresponding member attributes at index 00108 /// "@a index" in the given @c TypeCode @a tc. 00109 bool equivalent (CORBA::ULong index, CORBA::TypeCode_ptr tc) const; 00110 00111 protected: 00112 00113 /// Marshal the IDL @c union @c case label value into the given 00114 /// output CDR stream. 00115 virtual bool marshal_label (TAO_OutputCDR & cdr) const = 0; 00116 00117 /// Verify equality of member labels. 00118 /** 00119 * Performing member label equality comparisons in the @c Case 00120 * subclass allows us to avoid performing interpretive 00121 * extraction of the value from the @c Any returned from the 00122 * "right hand side" operand @c TypeCode since the @c Case 00123 * subclass already knows what type and value should be 00124 * extracted from the @c Any. 00125 * 00126 * @param index Member index of given @c TypeCode @a tc being 00127 * tested. 00128 * @param tc The @c TypeCode whose member "@a index" label is 00129 * being tested. 00130 */ 00131 virtual bool equal_label (CORBA::ULong index, 00132 CORBA::TypeCode_ptr tc) const = 0; 00133 00134 private: 00135 00136 /// The name of the case. 00137 StringType name_; 00138 00139 /// Pointer to the @c CORBA::TypeCode of the case. 00140 /** 00141 * A pointer to the @c CORBA::TypeCode_ptr rather than the 00142 * @c CORBA::TypeCode_ptr itself is stored since that address is 00143 * well-defined. We may not know the value of the @c 00144 * CORBA::TypeCode_ptr when creating this @c Case statically at 00145 * compile-time, hence the indirection. 00146 * 00147 * @note This @c TypeCode is released upon destruction of this 00148 * @c Case. 00149 */ 00150 TypeCodeType type_; 00151 00152 }; 00153 00154 typedef Case<CORBA::String_var, CORBA::TypeCode_var> Case_Dynamic; 00155 00156 } // End namespace TypeCode 00157 } // End namespace TAO 00158 00159 TAO_END_VERSIONED_NAMESPACE_DECL 00160 00161 ACE_BEGIN_VERSIONED_NAMESPACE_DECL 00162 00163 namespace ACE 00164 { 00165 /// @see ace/Value_Ptr.h. 00166 template <typename T> struct VP_traits; 00167 00168 template <> 00169 struct TAO_AnyTypeCode_Export VP_traits<TAO::TypeCode::Case_Dynamic> 00170 { 00171 /// Copy the given object. 00172 static TAO::TypeCode::Case_Dynamic * clone ( 00173 TAO::TypeCode::Case_Dynamic const * p) 00174 { 00175 return p->clone (); 00176 } 00177 }; 00178 00179 } // End namespace ACE. 00180 00181 ACE_END_VERSIONED_NAMESPACE_DECL 00182 00183 00184 #ifdef __ACE_INLINE__ 00185 # include "tao/AnyTypeCode/TypeCode_Case_Base_T.inl" 00186 #endif /* __ACE_INLINE__ */ 00187 00188 #ifdef ACE_TEMPLATES_REQUIRE_SOURCE 00189 # include "tao/AnyTypeCode/TypeCode_Case_Base_T.cpp" 00190 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ 00191 00192 #ifdef ACE_TEMPLATES_REQUIRE_PRAGMA 00193 # pragma implementation ("TypeCode_Case_Base_T.cpp") 00194 #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */ 00195 00196 #include /**/ "ace/post.h" 00197 00198 #endif /* TAO_TYPECODE_CASE_H */