TypeCode_Traits.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    TypeCode_Traits.h
00006  *
00007  *  $Id: TypeCode_Traits.h 69182 2005-11-03 17:38:46Z ossama $
00008  *
00009  *  @author Ossama Othman <ossama@dre.vanderbilt.edu>
00010  */
00011 //=============================================================================
00012 
00013 #ifndef TAO_TYPECODE_TRAITS_H
00014 #define TAO_TYPECODE_TRAITS_H
00015 
00016 #include /**/ "ace/pre.h"
00017 
00018 #include "tao/CORBA_String.h"
00019 #include "tao/AnyTypeCode/TypeCode.h"
00020 
00021 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00022 # pragma once
00023 #endif /* ACE_LACKS_PRAGMA_ONCE */
00024 
00025 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00026 
00027 namespace TAO
00028 {
00029   class Null_RefCount_Policy;
00030   class True_RefCount_Policy;
00031 
00032   namespace TypeCode
00033   {
00034 
00035 //     enum Storage { STATIC_TYPECODE, DYNAMIC_TYPECODE };
00036 
00037 //     template<Storage S> struct Traits;
00038 
00039     // ----
00040     // @@ Work around limitations in MSVC++ 6.
00041     typedef char const * STATIC_TYPECODE;
00042     typedef CORBA::String_var DYNAMIC_TYPECODE;
00043 
00044     template<typename S> struct Traits;
00045     // ----
00046 
00047     template<>
00048     struct Traits<STATIC_TYPECODE>
00049     {
00050       typedef char const * string_type;
00051 
00052       /**
00053        * A pointer to the @c CORBA::TypeCode_ptr rather than the
00054        * @c CORBA::TypeCode_ptr itself is stored since that address is
00055        * well-defined.  We may not know the value of the
00056        * @c CORBA::TypeCode_ptr when creating a static object that
00057        * refers to it, hence the indirection.
00058        */
00059       typedef CORBA::TypeCode_ptr const * typecode_type;
00060 
00061       typedef TAO::Null_RefCount_Policy refcount_policy_type;
00062 
00063       static char const * get_string (string_type const & str)
00064       {
00065         return str;
00066       }
00067 
00068       static CORBA::TypeCode_ptr get_typecode (typecode_type const & tc)
00069       {
00070         return (tc == 0 ? CORBA::TypeCode::_nil () : *tc);
00071       }
00072     };
00073 
00074     template<>
00075     struct Traits<DYNAMIC_TYPECODE>
00076     {
00077       typedef CORBA::String_var string_type;
00078       typedef CORBA::TypeCode_var typecode_type;
00079       typedef TAO::True_RefCount_Policy refcount_policy_type;
00080 
00081       static char const * get_string (string_type const & str)
00082       {
00083         return str.in ();
00084       }
00085 
00086       static CORBA::TypeCode_ptr get_typecode (typecode_type const & tc)
00087       {
00088         return tc.in ();
00089       }
00090     };
00091 
00092     // ---------------
00093 
00094     // Traits based on TypeCode type template parameters.
00095 
00096     template<>
00097     struct Traits<Traits<STATIC_TYPECODE>::typecode_type>
00098     {
00099       typedef Traits<STATIC_TYPECODE>::typecode_type typecode_type;
00100 
00101       static CORBA::TypeCode_ptr get_typecode (typecode_type const & tc)
00102       {
00103         return (tc == 0 ? CORBA::TypeCode::_nil () : *tc);
00104       }
00105     };
00106 
00107     template<>
00108     struct Traits<Traits<DYNAMIC_TYPECODE>::typecode_type>
00109     {
00110       typedef Traits<DYNAMIC_TYPECODE>::typecode_type typecode_type;
00111 
00112       static CORBA::TypeCode_ptr get_typecode (typecode_type const & tc)
00113       {
00114         return tc.in ();
00115       }
00116 
00117     };
00118 
00119   }  // End namespace TypeCode
00120 }  // End namespace TAO
00121 
00122 TAO_END_VERSIONED_NAMESPACE_DECL
00123 
00124 #include /**/ "ace/post.h"
00125 
00126 #endif /* TAO_TYPECODE_TRAITS_H */

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