00001 #ifndef guard_string_sequence_element_hpp 00002 #define guard_string_sequence_element_hpp 00003 /** 00004 * @file 00005 * 00006 * @brief Implement the type returned by operator[] in string 00007 * sequences. 00008 * 00009 * $Id: String_Sequence_Element_T.h 90386 2010-06-02 13:52:08Z vzykov $ 00010 * 00011 * @author Carlos O'Ryan 00012 */ 00013 00014 #include "tao/Basic_Types.h" 00015 00016 #include <algorithm> 00017 00018 TAO_BEGIN_VERSIONED_NAMESPACE_DECL 00019 00020 namespace TAO 00021 { 00022 namespace details 00023 { 00024 00025 template<typename traits> 00026 class string_sequence_element 00027 { 00028 public: 00029 typedef typename traits::char_type character_type; 00030 typedef character_type * value_type; 00031 typedef character_type const * const_value_type; 00032 typedef typename traits::string_var string_var; 00033 typedef typename traits::string_out string_out; 00034 typedef typename traits::string_mgr string_mgr; 00035 00036 private: 00037 inline string_sequence_element<traits> & pseudo_copy_swap(string_var & rhs) 00038 { 00039 if (release()) 00040 { 00041 traits::release(*element_); 00042 } 00043 *element_ = rhs._retn(); 00044 return *this; 00045 } 00046 00047 public: 00048 string_sequence_element( 00049 value_type & e, CORBA::Boolean release) 00050 : element_(&e) 00051 , release_(release) 00052 { 00053 } 00054 00055 string_sequence_element( 00056 string_sequence_element const & rhs) 00057 : element_(rhs.element_) 00058 , release_(rhs.release_) 00059 { 00060 } 00061 00062 ~string_sequence_element() 00063 { 00064 } 00065 00066 string_sequence_element & operator=(const_value_type rhs) 00067 { 00068 string_var tmp(rhs); 00069 return pseudo_copy_swap(tmp); 00070 } 00071 00072 string_sequence_element & operator=(value_type rhs) 00073 { 00074 string_var tmp(rhs); 00075 return pseudo_copy_swap(tmp); 00076 } 00077 00078 string_sequence_element & operator=(string_sequence_element const & rhs) 00079 { 00080 string_var tmp(static_cast<const_value_type>(rhs)); 00081 return pseudo_copy_swap(tmp); 00082 } 00083 00084 string_sequence_element & operator=(string_var const & rhs) 00085 { 00086 string_var tmp(rhs); 00087 return pseudo_copy_swap(tmp); 00088 } 00089 00090 string_sequence_element & operator=(string_mgr const & rhs) 00091 { 00092 string_var tmp(rhs.in()); 00093 return pseudo_copy_swap(tmp); 00094 } 00095 00096 inline operator const_value_type() const 00097 { 00098 return *this->element_; 00099 } 00100 00101 inline const character_type *in (void) const { 00102 return *this->element_; 00103 } 00104 00105 inline character_type *&inout (void) const { 00106 return *this->element_; 00107 } 00108 00109 inline string_out out (void) const { 00110 00111 if (release()) 00112 { 00113 traits::release(*element_); 00114 } 00115 00116 return *this->element_; 00117 } 00118 00119 inline character_type *_retn (void) { 00120 character_type * copy = *this->element_; 00121 *this->element_ = traits::default_initializer(); 00122 return copy; 00123 } 00124 00125 void swap(string_sequence_element & rhs) 00126 { 00127 std::swap(element_, rhs.element_); 00128 std::swap(release_, rhs.release_); 00129 } 00130 00131 CORBA::Boolean release() const 00132 { 00133 return this->release_; 00134 } 00135 00136 private: 00137 // This function is not implemented 00138 string_sequence_element(); 00139 00140 private: 00141 value_type * element_; 00142 CORBA::Boolean release_; 00143 }; 00144 00145 } // namespace details 00146 } // namespace CORBA 00147 00148 TAO_END_VERSIONED_NAMESPACE_DECL 00149 00150 #endif // guard_string_sequence_element_hpp