String_Sequence_Element_T.h

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

Generated on Tue Feb 2 17:37:52 2010 for TAO by  doxygen 1.4.7