Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / tao / String_Sequence_Element_T.h
blobd0aabbb4343cf880ff8e24f6a811fc1613ab0dc9
1 #ifndef guard_string_sequence_element_hpp
2 #define guard_string_sequence_element_hpp
3 /**
4 * @file
6 * @brief Implement the type returned by operator[] in string
7 * sequences.
9 * @author Carlos O'Ryan
12 #include "tao/Basic_Types.h"
14 #include <algorithm>
16 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
18 namespace TAO
20 namespace details
22 template<typename traits>
23 class string_sequence_element
25 public:
26 typedef typename traits::char_type character_type;
27 typedef character_type * value_type;
28 typedef character_type const * const_value_type;
29 typedef typename traits::string_var string_var;
30 typedef typename traits::string_out string_out;
31 typedef typename traits::string_mgr string_mgr;
33 private:
34 inline string_sequence_element<traits> & pseudo_copy_swap(string_var & rhs)
36 if (release())
38 traits::release(*element_);
40 *element_ = rhs._retn();
41 return *this;
44 public:
45 string_sequence_element(
46 value_type & e, CORBA::Boolean release)
47 : element_(&e)
48 , release_(release)
52 string_sequence_element(
53 string_sequence_element const & rhs)
54 : element_(rhs.element_)
55 , release_(rhs.release_)
59 ~string_sequence_element() = default;
61 string_sequence_element & operator=(const_value_type rhs)
63 string_var tmp(rhs);
64 return pseudo_copy_swap(tmp);
67 string_sequence_element & operator=(value_type rhs)
69 string_var tmp(rhs);
70 return pseudo_copy_swap(tmp);
73 string_sequence_element & operator=(string_sequence_element const & rhs)
75 string_var tmp(static_cast<const_value_type>(rhs));
76 return pseudo_copy_swap(tmp);
79 string_sequence_element & operator=(string_var const & rhs)
81 string_var tmp(rhs);
82 return pseudo_copy_swap(tmp);
85 string_sequence_element & operator=(string_mgr const & rhs)
87 string_var tmp(rhs.in());
88 return pseudo_copy_swap(tmp);
91 inline operator const_value_type() const
93 return *this->element_;
96 inline const character_type *in () const {
97 return *this->element_;
100 inline character_type *&inout () const {
101 return *this->element_;
104 inline string_out out () const {
105 if (release())
107 traits::release(*element_);
110 return *this->element_;
113 inline character_type *_retn () {
114 character_type * copy = *this->element_;
115 *this->element_ = traits::default_initializer();
116 return copy;
119 void swap(string_sequence_element & rhs)
121 std::swap(element_, rhs.element_);
122 std::swap(release_, rhs.release_);
125 CORBA::Boolean release() const
127 return this->release_;
130 private:
131 // This function is not implemented
132 string_sequence_element();
134 private:
135 value_type * element_;
136 CORBA::Boolean release_;
138 } // namespace details
139 } // namespace CORBA
141 TAO_END_VERSIONED_NAMESPACE_DECL
143 #endif // guard_string_sequence_element_hpp