Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef TAO_CORBA_STRING_H
00015 #define TAO_CORBA_STRING_H
00016
00017 #include "ace/pre.h"
00018
00019 #include "tao/TAO_Export.h"
00020 #include "tao/Basic_Types.h"
00021
00022 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00023 # pragma once
00024 #endif
00025
00026 #include "tao/String_Traits_Base_T.h"
00027
00028 #include "ace/iosfwd.h"
00029
00030 #include <algorithm>
00031
00032 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00033
00034 namespace TAO
00035 {
00036 template <typename charT> class String_Manager_T;
00037 typedef String_Manager_T<CORBA::Char> String_Manager;
00038 typedef String_Manager_T<CORBA::WChar> WString_Manager;
00039 }
00040
00041 namespace TAO
00042 {
00043
00044
00045
00046
00047
00048
00049 template <typename charT>
00050 class String_var
00051 {
00052 public:
00053 typedef charT character_type;
00054 typedef TAO::details::string_traits_base <character_type> s_traits;
00055
00056
00057 inline String_var (void) : ptr_ (0)
00058 {
00059 }
00060
00061
00062 inline String_var (character_type *p) : ptr_ (p)
00063 {
00064 }
00065
00066
00067 inline String_var (const character_type *p) : ptr_ (s_traits::duplicate (p))
00068 {
00069 }
00070
00071
00072 inline String_var (String_var<charT> const &s) : ptr_(s_traits::duplicate(s.ptr_))
00073 {
00074 }
00075
00076
00077 inline ~String_var (void)
00078 {
00079 s_traits::release (this->ptr_);
00080 }
00081
00082
00083 inline String_var &operator= (character_type *p)
00084 {
00085 String_var <charT> tmp (p);
00086 std::swap (this->ptr_, tmp.ptr_);
00087 return *this;
00088 }
00089
00090
00091 inline String_var &operator= (const character_type *p)
00092 {
00093 String_var <charT> tmp (p);
00094 std::swap (this->ptr_, tmp.ptr_);
00095 return *this;
00096 }
00097
00098
00099 inline String_var &operator= (String_var<character_type> const &s)
00100 {
00101 String_var <charT> tmp (s);
00102 std::swap (this->ptr_, tmp.ptr_);
00103 return *this;
00104 }
00105
00106
00107 inline operator character_type *&()
00108 {
00109 return this->ptr_;
00110 }
00111
00112
00113 inline operator const character_type *() const
00114 {
00115 return this->ptr_;
00116 }
00117
00118
00119 inline character_type &operator[] (CORBA::ULong slot)
00120 {
00121
00122 return this->ptr_[slot];
00123 }
00124
00125
00126 inline character_type operator[] (CORBA::ULong slot) const
00127 {
00128
00129 return this->ptr_[slot];
00130 }
00131
00132
00133 inline const character_type *in (void) const
00134 {
00135 return this->ptr_;
00136 }
00137
00138
00139 inline character_type *&inout (void)
00140 {
00141 return this->ptr_;
00142 }
00143
00144
00145 inline character_type *&out (void)
00146 {
00147 s_traits::release (this->ptr_);
00148 this->ptr_ = 0;
00149 return this->ptr_;
00150 }
00151
00152
00153 inline character_type *_retn (void)
00154 {
00155 character_type *temp = this->ptr_;
00156 this->ptr_ = 0;
00157 return temp;
00158 }
00159
00160 private:
00161
00162 character_type *ptr_;
00163 };
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173 template <typename charT>
00174 class String_out
00175 {
00176 public:
00177 typedef charT character_type;
00178 typedef TAO::details::string_traits_base <character_type> s_traits;
00179 typedef typename s_traits::string_mgr string_mgr;
00180
00181
00182 inline String_out (character_type *&p) : ptr_ (p)
00183 {
00184 this->ptr_ = 0;
00185 }
00186
00187
00188 inline String_out (String_var <character_type> &p) : ptr_ (p.out ())
00189 {
00190 }
00191
00192
00193 inline String_out (string_mgr &p) : ptr_ (p.out ())
00194 {
00195 }
00196
00197
00198 inline String_out (const String_out<charT> &s) : ptr_ (s.ptr_)
00199 {
00200 }
00201
00202
00203 inline String_out &operator= (String_out<charT> const &s)
00204 {
00205 this->ptr_ = s.ptr_;
00206 return *this;
00207 }
00208
00209
00210 inline String_out &operator= (character_type *p)
00211 {
00212 this->ptr_ = p;
00213 return *this;
00214 }
00215
00216
00217 inline String_out& operator= (const character_type* p)
00218 {
00219 this->ptr_ = s_traits::duplicate (p);
00220 return *this;
00221 }
00222
00223
00224 inline operator character_type *&()
00225 {
00226 return this->ptr_;
00227 }
00228
00229
00230 inline character_type *&ptr (void)
00231 {
00232 return this->ptr_;
00233 }
00234
00235 private:
00236
00237 character_type *&ptr_;
00238
00239
00240 void operator= (const typename s_traits::string_var &);
00241 };
00242
00243
00244
00245
00246
00247
00248
00249 struct String_Var_Equal_To
00250 {
00251 bool operator() (CORBA::String_var const & lhs,
00252 CORBA::String_var const & rhs) const;
00253
00254 bool operator() (CORBA::WString_var const & lhs,
00255 CORBA::WString_var const & rhs) const;
00256 };
00257 }
00258
00259 namespace CORBA
00260 {
00261 typedef TAO::String_var <char> String_var;
00262 typedef TAO::String_out <char> String_out;
00263 typedef TAO::String_var <CORBA::WChar> WString_var;
00264 typedef TAO::String_out <CORBA::WChar> WString_out;
00265 }
00266
00267
00268 # if !defined (ACE_LACKS_IOSTREAM_TOTALLY)
00269
00270 TAO_Export ostream &
00271 operator<< (ostream &, const CORBA::String_var &);
00272 TAO_Export istream &
00273 operator>> (istream &, CORBA::String_var &);
00274 TAO_Export ostream &
00275 operator<< (ostream &, CORBA::String_out &);
00276 TAO_Export istream &
00277 operator>> (istream &, CORBA::String_out &);
00278 TAO_Export ostream &
00279 operator<< (ostream &, const CORBA::WString_var &);
00280 TAO_Export istream &
00281 operator>> (istream &, CORBA::WString_var &);
00282 TAO_Export ostream &
00283 operator<< (ostream &, CORBA::WString_out &);
00284 TAO_Export istream &
00285 operator>> (istream &, CORBA::WString_out &);
00286
00287 # endif
00288
00289 TAO_END_VERSIONED_NAMESPACE_DECL
00290
00291 #if defined (__ACE_INLINE__)
00292 # include "tao/CORBA_String.inl"
00293 #endif
00294
00295 #include "ace/post.h"
00296
00297 #endif