Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

CORBA_String.cpp

Go to the documentation of this file.
00001 #include "tao_pch.h"
00002 #include "tao/CORBA_String.h"
00003 
00004 #if !defined (__ACE_INLINE__)
00005 # include "tao/CORBA_String.inl"
00006 #endif /* ! __ACE_INLINE__ */
00007 
00008 
00009 ACE_RCSID (tao,
00010            CORBA_String,
00011            "$Id: CORBA_String.cpp,v 1.1.1.2.2.1 2003/03/14 16:05:12 chad Exp $")
00012 
00013 
00014 // String utility support; this needs to be integrated with the ORB's
00015 // own memory allocation subsystem.
00016 
00017 CORBA_String_var::CORBA_String_var (char *p)
00018   : ptr_ (p)
00019 {
00020   // NOTE: According to the CORBA spec this string must *not* be
00021   // copied, but it is non-compliant to use it/release it in the
00022   // calling code.  argument is consumed. p should never be NULL
00023 }
00024 
00025 CORBA_String_var::CORBA_String_var (const CORBA_String_var& r)
00026 {
00027   this->ptr_ = CORBA::string_dup (r.ptr_);
00028 }
00029 
00030 CORBA_String_var::~CORBA_String_var (void)
00031 {
00032   CORBA::string_free (this->ptr_);
00033   this->ptr_ = 0;
00034 }
00035 
00036 CORBA_String_var &
00037 CORBA_String_var::operator= (char *p)
00038 {
00039   if (this->ptr_ != p)
00040     {
00041       CORBA::string_free (this->ptr_);
00042       this->ptr_ = p;
00043     }
00044   return *this;
00045 }
00046 
00047 CORBA_String_var &
00048 CORBA_String_var::operator= (const char *p)
00049 {
00050   CORBA::string_free (this->ptr_);
00051 
00052   this->ptr_ = CORBA::string_dup (p);
00053   return *this;
00054 }
00055 
00056 CORBA_String_var &
00057 CORBA_String_var::operator= (const CORBA_String_var& r)
00058 {
00059   if (this != &r)
00060     {
00061       CORBA::string_free (this->ptr_);
00062       this->ptr_ = CORBA::string_dup (r.ptr_);
00063     }
00064   return *this;
00065 }
00066 
00067 // ****************************************************************
00068 
00069 CORBA_WString_var::CORBA_WString_var (CORBA::WChar *p)
00070   : ptr_ (p)
00071 {
00072   // NOTE: According to the CORBA spec this string must *not* be
00073   // copied, but it is non-compliant to use it/release it in the
00074   // calling code.  argument is consumed. p should never be NULL
00075 }
00076 
00077 CORBA_WString_var::CORBA_WString_var (const CORBA_WString_var& r)
00078 {
00079   this->ptr_ = CORBA::wstring_dup (r.ptr_);
00080 }
00081 
00082 CORBA_WString_var::~CORBA_WString_var (void)
00083 {
00084   CORBA::wstring_free (this->ptr_);
00085   this->ptr_ = 0;
00086 }
00087 
00088 CORBA_WString_var &
00089 CORBA_WString_var::operator= (CORBA::WChar *p)
00090 {
00091   if (this->ptr_ != p)
00092     {
00093       CORBA::wstring_free (this->ptr_);
00094       this->ptr_ = p;
00095     }
00096   return *this;
00097 }
00098 
00099 CORBA_WString_var &
00100 CORBA_WString_var::operator= (const CORBA::WChar *p)
00101 {
00102   CORBA::wstring_free (this->ptr_);
00103 
00104   this->ptr_ = CORBA::wstring_dup (p);
00105   return *this;
00106 }
00107 
00108 CORBA_WString_var &
00109 CORBA_WString_var::operator= (const CORBA_WString_var& r)
00110 {
00111   if (this != &r)
00112     {
00113       CORBA::wstring_free (this->ptr_);
00114       this->ptr_ = CORBA::wstring_dup (r.ptr_);
00115     }
00116   return *this;
00117 }
00118 
00119 // *************************************************************
00120 // C++ iostream operators for (W)String_var and (W)String_out
00121 // *************************************************************
00122 
00123 #if !defined (ACE_LACKS_IOSTREAM_TOTALLY)
00124 
00125 ostream &
00126 operator<< (ostream &os, const CORBA::String_var &sv)
00127 {
00128   os << sv.in ();
00129   return os;
00130 }
00131 
00132 istream &
00133 operator>> (istream &is, CORBA::String_var &sv)
00134 {
00135   is.seekg (0, ios::end);
00136   sv = CORBA::string_alloc (is.tellg ());
00137   is.seekg (0, ios::beg);
00138   is >> sv.inout ();
00139   return is;
00140 }
00141 
00142 ostream &
00143 operator<< (ostream &os, CORBA::String_out &so)
00144 {
00145   os << so.ptr ();
00146   return os;
00147 }
00148 
00149 istream &
00150 operator>> (istream &is, CORBA::String_out &so)
00151 {
00152   is.seekg (0, ios::end);
00153   so = CORBA::string_alloc (is.tellg ());
00154   is.seekg (0, ios::beg);
00155   is >> so.ptr ();
00156   return is;
00157 }
00158 
00159 // Until we implement WString support for platforms with a
00160 // 4-byte wchar_t, we just define the following to emit
00161 // the CORBA::WChars one by one.
00162 
00163 ostream &
00164 operator<< (ostream &os, const CORBA::WString_var &wsv)
00165 {
00166   CORBA::ULong len = ACE_OS::wslen (wsv.in ());
00167 
00168   for (CORBA::ULong i = 0; i < len; ++i)
00169     {
00170       os << wsv[i];
00171     }
00172 
00173   return os;
00174 }
00175 
00176 istream &
00177 operator>> (istream &is, CORBA::WString_var &wsv)
00178 {
00179   is.seekg (0, ios::end);
00180   // @@ is.tellg()/sizeof(CORBA::WChar) instead?
00181   CORBA::ULong len = is.tellg ();
00182   wsv = CORBA::wstring_alloc (len);
00183   is.seekg (0, ios::beg);
00184 
00185   for (CORBA::ULong i = 0; i < len; ++i)
00186     {
00187       CORBA::WChar wc = 0;
00188 
00189       // Unformatted input is used to work around overloaded
00190       // extraction operator (>>) ambiguities on some platforms.
00191       is.read (ACE_reinterpret_cast (char *, &wc), sizeof (wc));
00192 
00193       wsv[i] = wc;
00194     }
00195 
00196   wsv[len] = 0;  // NULL terminate
00197 
00198   return is;
00199 }
00200 
00201 ostream &
00202 operator<< (ostream &os, CORBA::WString_out &wso)
00203 {
00204   CORBA::WChar *tmp = wso.ptr ();
00205   CORBA::ULong len = ACE_OS::wslen (tmp);
00206 
00207   for (CORBA::ULong i = 0; i < len; ++i)
00208     {
00209       os << tmp[i];
00210     }
00211 
00212   return os;
00213 }
00214 
00215 istream &
00216 operator>> (istream &is, CORBA::WString_out &wso)
00217 {
00218   is.seekg (0, ios::end);
00219   // @@ is.tellg()/sizeof(CORBA::WChar) instead?
00220   CORBA::ULong len = is.tellg ();
00221   wso = CORBA::wstring_alloc (len);
00222   is.seekg (0, ios::beg);
00223 
00224   for (CORBA::ULong i = 0; i < len; ++i)
00225     {
00226       CORBA::WChar wc = 0;
00227 
00228       // Unformatted input is used to work around overloaded
00229       // extraction operator (>>) ambiguities on some platforms.
00230       is.read (ACE_reinterpret_cast (char *, &wc), sizeof (wc));
00231 
00232       wso.ptr ()[i] = wc;
00233     }
00234 
00235   wso.ptr ()[len] = 0;  // NULL terminate
00236 
00237   return is;
00238 }
00239 
00240 #endif /* ACE_LACKS_IOSTREAM_TOTALLY */

Generated on Mon Jun 16 13:48:10 2003 for TAO by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002