diff options
author | Ossama Othman <ossama-othman@users.noreply.github.com> | 2004-09-25 22:57:20 +0000 |
---|---|---|
committer | Ossama Othman <ossama-othman@users.noreply.github.com> | 2004-09-25 22:57:20 +0000 |
commit | 61c98059e3803fd5fd8782711862a69546f18902 (patch) | |
tree | ed034b18ee649fc196ebd68a2dfb607f08a62cd8 | |
parent | 4409846b58d730cd34faf4cc0286d4bfb03c5e41 (diff) | |
download | ATCD-61c98059e3803fd5fd8782711862a69546f18902.tar.gz |
*** empty log message ***
-rw-r--r-- | TAO/tao/TypeCode/TypeCode_Case_Base.cpp | 21 | ||||
-rw-r--r-- | TAO/tao/TypeCode/TypeCode_Case_Base.h | 128 | ||||
-rw-r--r-- | TAO/tao/TypeCode/TypeCode_Case_Base.inl | 55 | ||||
-rw-r--r-- | TAO/tao/TypeCode/TypeCode_Non_Default_Case.cpp | 94 | ||||
-rw-r--r-- | TAO/tao/TypeCode/TypeCode_Non_Default_Case.h | 128 | ||||
-rw-r--r-- | TAO/tao/TypeCode/TypeCode_Non_Default_Case.inl | 16 | ||||
-rw-r--r-- | TAO/tao/TypeCode/Union_TypeCode.h | 2 | ||||
-rw-r--r-- | TAO/tao/TypeCode/Union_TypeCode.inl | 2 |
8 files changed, 240 insertions, 206 deletions
diff --git a/TAO/tao/TypeCode/TypeCode_Case_Base.cpp b/TAO/tao/TypeCode/TypeCode_Case_Base.cpp deleted file mode 100644 index 161d362e452..00000000000 --- a/TAO/tao/TypeCode/TypeCode_Case_Base.cpp +++ /dev/null @@ -1,21 +0,0 @@ -// $Id$ - -#ifndef TAO_TYPECODE_CASE_BASE_CPP -#define TAO_TYPECODE_CASE_BASE_CPP - -#include "TypeCode_Case_Base.h" - -#ifndef __ACE_INLINE__ -# include "tao/TypeCode_Case_Base.inl" -#endif /* __ACE_INLINE__ */ - - -template <typename DISCRIMINATOR, typename STRING_TYPE> -char const * -TAO::TypeCode::Case_Base<DISCRIMINATOR, STRING_TYPE>::~Case_Base (void) -{ - if (this->type_) - CORBA::release (*(this->type_)); -} - -#endif /* TAO_TYPECODE_CASE_BASE_CPP */ diff --git a/TAO/tao/TypeCode/TypeCode_Case_Base.h b/TAO/tao/TypeCode/TypeCode_Case_Base.h deleted file mode 100644 index a397ab6f097..00000000000 --- a/TAO/tao/TypeCode/TypeCode_Case_Base.h +++ /dev/null @@ -1,128 +0,0 @@ -// -*- C++ -*- - -//============================================================================= -/** - * @file TypeCode_Case_Base.h - * - * $Id$ - * - * Header file for @c TAO::TypeCode::Case_Base type. - * - * @author Ossama Othman - */ -//============================================================================= - -#ifndef TAO_TYPECODE_CASE_BASE_H -#define TAO_TYPECODE_CASE_BASE_H - -#include /**/ "ace/pre.h" - -#include "ace/config.h" - -#if !defined (ACE_LACKS_PRAGMA_ONCE) -# pragma once -#endif /* ACE_LACKS_PRAGMA_ONCE */ - - -namespace CORBA -{ - class TypeCode; - typedef TypeCode* TypeCode_ptr; - - class Any; -} - -namespace TAO -{ - namespace TypeCode - { - - /** - * @class Case_Base - * - * @brief Abstract base class for that represents an IDL @c union - * case/member. - * - * This class hides the actual IDL @c union member label value - * from the @c TAO::TypeCode::Union class by relying on a - * CORBA::Any return value that corresponds to the @c - * CORBA::TypeCode::member_label() return type. It also allows - * the @c TAO::TypeCode::Union class to marshal the member label - * values into a CDR stream without knowledge of the underlying - * member label values. - */ - template <typename STRING_TYPE> - class Case_Base - { - public: - - /// Constructor. - Case_Base (char const * name, - CORBA::TypeCode_ptr * tc); - - /// Destructor. - virtual ~Case_Base (void); - - /// Return the IDL @c union case label value embedded within a - /// @c CORBA::Any. - virtual CORBA::Any * label (ACE_ENV_SINGLE_ARG_DECL) const = 0; - - /// Get the name of the @c union case/member. - char const * name (void) const; - - /// Get the @c CORBA::TypeCode of the @c union case/member. - /** - * @note The reference count is not manipulated by this method, - * i.e., ownership is retained by this class. - */ - CORBA::TypeCode_ptr type (void) const; - - /// Marshal this IDL @c union member into the given output CDR - /// stream. - bool marshal (TAO_OutputCDR & cdr) const; - - protected: - - /// Marshal the IDL @c union @c case label value into the given - /// output CDR stream. - virtual bool marshal_label (TAO_OutputCDR & cdr) const = 0; - - private: - - /// The name of the case. - STRING_TYPE const name_; - - /// Pointer to the @c CORBA::TypeCode of the case. - /** - * A pointer to the @c CORBA::TypeCode_ptr rather than the - * @c CORBA::TypeCode_ptr itself is stored since that address is - * well-defined. We may not know the value of the @c - * CORBA::TypeCode_ptr when creating this @c Case statically at - * compile-time, hence the indirection. - * - * @note This @c TypeCode is released upon destruction of this - * @c Case. - */ - CORBA::TypeCode_ptr * const type_; - - }; - - } // End namespace TypeCode -} // End namespace TAO - - -#ifdef __ACE_INLINE__ -# include "tao/TypeCode_Case_Base.inl" -#endif /* __ACE_INLINE__ */ - -#ifdef ACE_TEMPLATES_REQUIRE_SOURCE -# include "tao/TypeCode_Case_Base.cpp" -#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ - -#ifdef ACE_TEMPLATES_REQUIRE_PRAGMA -# pragma implementation ("TypeCode_Case_Base.cpp") -#endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */ - -#include /**/ "ace/post.h" - -#endif /* TAO_TYPECODE_CASE_BASE_H */ diff --git a/TAO/tao/TypeCode/TypeCode_Case_Base.inl b/TAO/tao/TypeCode/TypeCode_Case_Base.inl deleted file mode 100644 index bdf0fc125f6..00000000000 --- a/TAO/tao/TypeCode/TypeCode_Case_Base.inl +++ /dev/null @@ -1,55 +0,0 @@ -// -*- C++ -*- -// -// $Id$ - -#include "tao/CDR.h" - - -template <typename STRING_TYPE> -ACE_INLINE char const * -TAO::TypeCode::Case_Base<STRING_TYPE>::Case_Base ( - char const * member_name, - CORBA::TypeCode_ptr * member_type) - : name_ (member_name) - , type_ (member_type) -{ -} - -template <typename STRING_TYPE> -ACE_INLINE char const * -TAO::TypeCode::Case_Base<STRING_TYPE>::name (void) const -{ - return this->name_; -} - -template <typename STRING_TYPE> -ACE_INLINE CORBA::TypeCode_ptr -TAO::TypeCode::Case_Base<STRING_TYPE>::type (void) const -{ - return *this->type_; -} - -template <typename DISCRIMINATOR, typename STRING_TYPE> -ACE_INLINE bool -TAO::TypeCode::Case<DISCRIMINATOR, STRING_TYPE>::marshal ( - TAO_OutputCDR & cdr) const -{ - return - this->marshal_label () - && (cdr << this->name ()) - && (cdr << this->type ()); -} - - -// ----------------------------------------------------------------- -// Some compilers exhibit warnings about better conversion sequence -// from a CORBA::String_var to a char const *. This member -// specialization works around them by performing explicit -// conversions. -// ----------------------------------------------------------------- - -ACE_INLINE char const * -TAO::TypeCode::Case_Base<CORBA::String_var>::name (void) const -{ - return this->name_.in (); -} diff --git a/TAO/tao/TypeCode/TypeCode_Non_Default_Case.cpp b/TAO/tao/TypeCode/TypeCode_Non_Default_Case.cpp new file mode 100644 index 00000000000..b6ef3d1d35b --- /dev/null +++ b/TAO/tao/TypeCode/TypeCode_Non_Default_Case.cpp @@ -0,0 +1,94 @@ +// $Id$ + +#ifndef TAO_TYPECODE_NON_DEFAULT_CASE_CPP +#define TAO_TYPECODE_NON_DEFAULT_CASE_CPP + +#include "TypeCode_Non_Default_Case.h" + +#include "tao/CDR.h" +#include "tao/Any.h" + +#ifndef __ACE_INLINE__ +# include "tao/TypeCode_Non_Default_Case.inl" +#endif /* __ACE_INLINE__ */ + +namespace TAO +{ + namespace TypeCode + { + template <typename T> + struct Case_Traits + { + inline static T any_from (T v) + { + return v; + } + }; + + // Specializations for types that require wrapper for Any + // insertion. Note that we only define specializations for types + // that can be used in an IDL union discriminator. + + template <> + struct Case_Traits<CORBA::Boolean> + { + inline static CORBA::Any::from_boolean any_from (CORBA::Boolean v) + { + return CORBA::Any::from_boolean (v); + } + }; + + template <> + struct Case_Traits<CORBA::Char> + { + inline static CORBA::Any::from_char any_from (CORBA::Char v) + { + return CORBA::Any::from_char (v); + } + }; + + template <> + struct Case_Traits<CORBA::WChar> + { + inline static CORBA::Any::from_wchar any_from (CORBA::WChar v) + { + return CORBA::Any::from_wchar (v); + } + }; + + } // End TypeCode namespace +} // End TAO namespace + +// ---------------------------------------------------------------- + +template <typename DISCRIMINATOR_TYPE, typename STRING_TYPE> +bool +TAO::TypeCode::Non_Default_Case<DISCRIMINATOR_TYPE, STRING_TYPE>::marshal_label ( + TAO_OutputCDR & cdr) const +{ + return (cdr << this->label_); +} + +template <typename DISCRIMINATOR_TYPE, typename STRING_TYPE> +CORBA::Any * +TAO::TypeCode::Non_Default_Case<DISCRIMINATOR_TYPE, STRING_TYPE>::label ( + ACE_ENV_SINGLE_ARG_DECL) const +{ + CORBA::Any * value; + + ACE_NEW_THROW_EX (value, + CORBA::Any, + CORBA::NO_MEMORY ()); + ACE_CHECK_RETURN (0); + + CORBA::Any_var safe_value (value); + + *value <<= + TAO::TypeCode::Case_Traits<DISCRIMINATOR_TYPE>::any_from (this->label_); + + return safe_value._retn (); +} + + + +#endif /* TAO_TYPECODE_NON_DEFAULT_CASE_CPP */ diff --git a/TAO/tao/TypeCode/TypeCode_Non_Default_Case.h b/TAO/tao/TypeCode/TypeCode_Non_Default_Case.h new file mode 100644 index 00000000000..efd6eb3a675 --- /dev/null +++ b/TAO/tao/TypeCode/TypeCode_Non_Default_Case.h @@ -0,0 +1,128 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file TypeCode_Non_Default_Case.h + * + * $Id$ + * + * Header file for @c TAO::TypeCode::Non_Default_Case type. + * + * @author Ossama Othman + */ +//============================================================================= + +#ifndef TAO_TYPECODE_NON_DEFAULT_CASE_H +#define TAO_TYPECODE_NON_DEFAULT_CASE_H + +#include /**/ "ace/pre.h" + +#include "ace/config.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "tao/TypeCode_Case.h" + + +namespace TAO +{ + namespace TypeCode + { + + /** + * @class Non_Default_Case + * + * @brief Representation of an OMG IDL defined @c union @c case. + * + * A @c Non_Default_Case contains the corresponding case label value, name and + * pointer to the @c CORBA::TypeCode for a given OMG IDL @c union + * @c case. For + * example, the cases in following OMG IDL @c union: + * + * \code + * union Foo switch (short) + * { + * case 0: + * case 1: short a; + * case 2: long b; + * default: octet c; + * }; + * \endcode + * + * would be represented using the following statically instantiated + * @c TAO::TypeCode::Non_Default_Case array: + * + * \code + * typedef TAO::TypeCode::Non_Default_Case<CORBA::Short, + char const *> Foo_Case; + * Foo_Case _tao_cases_Foo[] = + * { + * { Foo_Case (0, "a", &CORBA::_tc_short), + * { Foo_Case (1, "b", &CORBA::_tc_short), + * { Foo_Case (2, "c", &CORBA::_tc_long) + * }; + * \endcode + * + * The @c default case is passed directly to the + * @c TAO::TypeCode::Union constructor. + * + * The template parameter @a DISCRIMINATOR_TYPE is the + * corresponding C++ type for the IDL defined @c union + * discriminator type. For example, a @c union with an IDL @c + * short discriminator will have a corresponding @c CORBA::Short + * C++ type. This template parameter is necessary to allow the + * actual @c case label value to be stored as its actual type, + * which is particularly important when marshaling that value into + * a CDR stream. + * + * The template parameter @a STRING_TYPE is either @c char @c + * const @c * or @c CORBA::String_var. The latter is only used + * when creating @c CORBA::tk_union @c TypeCode dynamically, such + * as through the TypeCodeFactory. + */ + template <typename DISCRIMINATOR_TYPE, typename STRING_TYPE> + class Non_Default_Case : public Case<STRING_TYPE> + { + public: + + /// Constructor. + Non_Default_Case (DISCRIMINATOR_TYPE member_label, + char const * member_name, + CORBA::TypeCode_ptr * member_type); + + /// Return the IDL @c union case label value embedded within a + /// @c CORBA::Any. + virtual CORBA::Any * label (ACE_ENV_SINGLE_ARG_DECL) const; + + /// Marshal this IDL @c union member into the given output CDR + /// stream. + virtual bool marshal_label (TAO_OutputCDR & cdr) const; + + private: + + /// IDL @c union case/member label value. + DISCRIMINATOR_TYPE const label_; + + }; + + } // End namespace TypeCode +} // End namespace TAO + + +#ifdef __ACE_INLINE__ +# include "tao/TypeCode_Non_Default_Case.inl" +#endif /* __ACE_INLINE__ */ + +#ifdef ACE_TEMPLATES_REQUIRE_SOURCE +# include "tao/TypeCode_Non_Default_Case.cpp" +#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ + +#ifdef ACE_TEMPLATES_REQUIRE_PRAGMA +# pragma implementation ("TypeCode_Non_Default_Case.cpp") +#endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */ + +#include /**/ "ace/post.h" + +#endif /* TAO_TYPECODE_NON_DEFAULT_CASE_H */ diff --git a/TAO/tao/TypeCode/TypeCode_Non_Default_Case.inl b/TAO/tao/TypeCode/TypeCode_Non_Default_Case.inl new file mode 100644 index 00000000000..1e4c69eff34 --- /dev/null +++ b/TAO/tao/TypeCode/TypeCode_Non_Default_Case.inl @@ -0,0 +1,16 @@ +// -*- C++ -*- +// +// $Id$ + +template <typename DISCRIMINATOR_TYPE, typename STRING_TYPE> +ACE_INLINE char const * +TAO::TypeCode::Non_Default_Case<DISCRIMINATOR_TYPE, + STRING_TYPE>::Non_Default_Case ( + DISCRIMINATOR_TYPE member_label, + char const * member_name, + CORBA::TypeCode_ptr * member_type) + : Case_Base<STRING_TYPE> (member_name, + member_type) + , label_ (member_label) +{ +} diff --git a/TAO/tao/TypeCode/Union_TypeCode.h b/TAO/tao/TypeCode/Union_TypeCode.h index 0d44d7c5026..4c0f79f7f0a 100644 --- a/TAO/tao/TypeCode/Union_TypeCode.h +++ b/TAO/tao/TypeCode/Union_TypeCode.h @@ -47,7 +47,7 @@ namespace TAO { public: - typedef TAO::TypeCode::Case_Base<StringType> Case; + typedef TAO::TypeCode::Case<StringType> Case; /// Constructor. Union (char const * id, diff --git a/TAO/tao/TypeCode/Union_TypeCode.inl b/TAO/tao/TypeCode/Union_TypeCode.inl index bdf30ac3044..4a1915dbed4 100644 --- a/TAO/tao/TypeCode/Union_TypeCode.inl +++ b/TAO/tao/TypeCode/Union_TypeCode.inl @@ -57,7 +57,7 @@ TAO::TypeCode::Union<StringType, // below. } - return this->cases_[index]; + return this->cases_[index]; } |