summaryrefslogtreecommitdiff
path: root/TAO/tao/TypeCode_Case.h
blob: 7b5042b6a14d7cae94ae044e3118fcd01e8de933 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
// -*- C++ -*-

//=============================================================================
/**
 *  @file    TypeCode_Case.h
 *
 *  $Id$
 *
 *  Header file for @c TAO::TypeCode::Case type.
 *
 *  @author Ossama Othman
 */
//=============================================================================

#ifndef TAO_TYPECODE_CASE_H
#define TAO_TYPECODE_CASE_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
     *
     * @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
    {
    public:

      /// Constructor.
      Case (char const * name,
            CORBA::TypeCode_ptr * tc);

      /// Destructor.
      virtual ~Case (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;

      /// Check for equality of the @c case attributes contained by this
      /// class and the corresponding member attributes at index "@a
      /// index" in the given @c TypeCode @a tc.
      bool equal (CORBA::ULong index,
                  CORBA::TypeCode_ptr tc
                  ACE_ENV_ARG_DECL) const;

      /// Check for equivalence of the @c case attributes contained by
      /// this class and the corresponding member attributes at index
      /// "@a index" in the given @c TypeCode @a tc.
      bool equivalent (CORBA::TypeCode_ptr tc
                       ACE_ENV_ARG_DECL) 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;

      /// Verify equality of member labels.
      /**
       * Performing member label equality comparisons in the @c Case
       * subclass allows us to avoid performing interpretive
       * extraction of the value from the @c Any returned from the
       * "right hand side" operand @c TypeCode since the @c Case
       * subclass already knows what type and value should be
       * extracted from the @c Any.
       *
       * @param index Member index of given @c TypeCode @a tc being
       *              tested.
       * @param tc    The @c TypeCode whose member "@a index" label is
       *              being tested.
       */
      virtual bool equal_label (CORBA::ULong index,
                                CORBA::TypeCode_ptr tc
                                ACE_ENV_ARG_DECL) 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.inl"
#endif /* __ACE_INLINE__ */

#ifdef ACE_TEMPLATES_REQUIRE_SOURCE
# include "tao/TypeCode_Case.cpp"
#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */

#ifdef ACE_TEMPLATES_REQUIRE_PRAGMA
# pragma implementation ("TypeCode_Case.cpp")
#endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */

#include /**/ "ace/post.h"

#endif /* TAO_TYPECODE_CASE_H */