summaryrefslogtreecommitdiff
path: root/TAO/tao/Object_Reference_Sequence_Element_T.h
blob: 7e9d04a4595507292eaf513b226a0648e9eafff5 (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
#ifndef guard_object_reference_sequence_element_hpp
#define guard_object_reference_sequence_element_hpp
/**
 * @file
 *
 * @brief Implement the type returned by operator[] in object_reference
 * sequences.
 *
 * $Id$
 *
 * @author Carlos O'Ryan
 */
#include "tao/Basic_Types.h"

TAO_BEGIN_VERSIONED_NAMESPACE_DECL

namespace TAO
{
namespace details
{

template<typename obj_ref_traits>
class object_reference_sequence_element
{
public:
  typedef typename obj_ref_traits::object_type object_reference_type;
  typedef object_reference_type * value_type;
  typedef object_reference_type const * const_value_type;
  typedef typename obj_ref_traits::object_type_var object_reference_var;

private:
  inline object_reference_sequence_element<obj_ref_traits> & pseudo_copy_swap(
      object_reference_var & rhs)
  {
    if (release())
    {
      obj_ref_traits::release(*element_);
    }
    *element_ = rhs._retn();
    return *this;
  }

public:
  object_reference_sequence_element(
      value_type & e, CORBA::Boolean release)
    : element_(&e)
    , release_(release)
  {
  }

  object_reference_sequence_element(
      object_reference_sequence_element const & rhs)
    : element_(rhs.element_)
    , release_(rhs.release_)
  {
  }

  ~object_reference_sequence_element()
  {
  }

  object_reference_sequence_element & operator=(
      object_reference_var const & rhs)
  {
    object_reference_var tmp(rhs);
    return pseudo_copy_swap(tmp);
  }

  object_reference_sequence_element & operator=(
      object_reference_sequence_element const & rhs)
  {
    object_reference_var tmp(obj_ref_traits::duplicate(*rhs.element_));
    return pseudo_copy_swap(tmp);
  }

  object_reference_sequence_element & operator=(value_type rhs)
  {
    object_reference_var tmp(rhs);
    return pseudo_copy_swap(tmp);
  }

  inline operator value_type()
  {
    return *element_;
  }

  inline operator const_value_type() const
  {
    return *element_;
  }

  inline value_type operator->()
  {
    return *element_;
  }

  inline value_type operator->() const
  {
    return *element_;
  }

  void swap(object_reference_sequence_element & rhs)
  {
    std::swap(element_, rhs.element_);
    std::swap(release_, rhs.release_);
  }

  inline CORBA::Boolean release() const
  {
    return release_;
  }

private:
  // This function is not implemented
  object_reference_sequence_element();

private:
  value_type * element_;
  CORBA::Boolean release_;
};

} // namespace details
} // namespace CORBA

TAO_END_VERSIONED_NAMESPACE_DECL

#endif // guard_object_reference_sequence_element_hpp