TypeCode_Case_Base_T.h

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

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