summaryrefslogtreecommitdiff
path: root/TAO/tao/String_Sequence_Element_T.h
blob: 66f77ecb7b70149956577fefe5b60b966d098459 (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
#ifndef guard_string_sequence_element_hpp
#define guard_string_sequence_element_hpp
/**
 * @file
 *
 * @brief Implement the type returned by operator[] in string
 * sequences.
 *
 * $Id$
 *
 * @author Carlos O'Ryan
 */

#include "tao/Basic_Types.h"

#include <algorithm>

TAO_BEGIN_VERSIONED_NAMESPACE_DECL

namespace TAO
{
namespace details
{

template<typename traits>
class string_sequence_element
{
public:
  typedef typename traits::char_type character_type;
  typedef character_type * value_type;
  typedef character_type const * const_value_type;
  typedef typename traits::string_var string_var;
  typedef typename traits::string_out string_out;
  typedef typename traits::string_mgr string_mgr;

private:
  inline string_sequence_element<traits> & pseudo_copy_swap(string_var & rhs)
  {
    if (release())
      {
        traits::release(*element_);
      }
    *element_ = rhs._retn();
    return *this;
  }

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

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

  ~string_sequence_element()
  {
  }

  string_sequence_element & operator=(const_value_type rhs)
  {
    string_var tmp(rhs);
    return pseudo_copy_swap(tmp);
  }

  string_sequence_element & operator=(value_type rhs)
  {
    string_var tmp(rhs);
    return pseudo_copy_swap(tmp);
  }

  string_sequence_element & operator=(string_sequence_element const & rhs)
  {
    string_var tmp(static_cast<const_value_type>(rhs));
    return pseudo_copy_swap(tmp);
  }

  string_sequence_element & operator=(string_var const & rhs)
  {
    string_var tmp(rhs);
    return pseudo_copy_swap(tmp);
  }

  string_sequence_element & operator=(string_mgr const & rhs)
  {
    string_var tmp(rhs.in());
    return pseudo_copy_swap(tmp);
  }

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

  inline const character_type *in (void) const {
    return *this->element_;
  }

  inline character_type *&inout (void) const {
    return *this->element_;
  }

  inline string_out out (void) const {

    if (release())
      {
        traits::release(*element_);
      }

    return *this->element_;
  }

  inline character_type *_retn (void) {
    character_type * copy = *this->element_;
    *this->element_ = traits::default_initializer();
    return copy;
  }

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

  CORBA::Boolean release() const
  {
    return this->release_;
  }

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

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

} // namespace details
} // namespace CORBA

TAO_END_VERSIONED_NAMESPACE_DECL

#endif // guard_string_sequence_element_hpp