CORBA_String.cpp

Go to the documentation of this file.
00001 #include "tao/CORBA_String.h"
00002 #include "tao/String_Manager_T.h"
00003 
00004 #include "ace/OS_NS_string.h"
00005 #include "ace/OS_NS_wchar.h"
00006 #include "ace/OS_Memory.h"
00007 
00008 // FUZZ: disable check_for_streams_include
00009 #include "ace/streams.h"
00010 
00011 #if !defined (__ACE_INLINE__)
00012 # include "tao/CORBA_String.inl"
00013 #endif /* ! __ACE_INLINE__ */
00014 
00015 ACE_RCSID (tao,
00016            CORBA_String,
00017            "CORBA_String.cpp,v 1.21 2006/04/19 08:34:34 jwillemsen Exp")
00018 
00019 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00020 
00021 // *************************************************************
00022 // C++ iostream operators for (W)String_var and (W)String_out
00023 // *************************************************************
00024 
00025 #if !defined (ACE_LACKS_IOSTREAM_TOTALLY)
00026 
00027 ostream &
00028 operator<< (ostream &os, const CORBA::String_var &sv)
00029 {
00030   os << sv.in ();
00031   return os;
00032 }
00033 
00034 istream &
00035 operator>> (istream &is, CORBA::String_var &sv)
00036 {
00037   is.seekg (0, ios::end);
00038   sv = CORBA::string_alloc (is.tellg ());
00039   is.seekg (0, ios::beg);
00040   is >> sv.inout ();
00041   return is;
00042 }
00043 
00044 ostream &
00045 operator<< (ostream &os, CORBA::String_out &so)
00046 {
00047   os << so.ptr ();
00048   return os;
00049 }
00050 
00051 istream &
00052 operator>> (istream &is, CORBA::String_out &so)
00053 {
00054   is.seekg (0, ios::end);
00055   so = CORBA::string_alloc (is.tellg ());
00056   is.seekg (0, ios::beg);
00057   is >> so.ptr ();
00058   return is;
00059 }
00060 
00061 // Until we implement WString support for platforms with a
00062 // 4-byte wchar_t, we just define the following to emit
00063 // the CORBA::WChars one by one.
00064 
00065 ostream &
00066 operator<< (ostream &os, const CORBA::WString_var &wsv)
00067 {
00068   CORBA::ULong const len =
00069     static_cast <CORBA::ULong> (ACE_OS::strlen (wsv.in ()));
00070 
00071   for (CORBA::ULong i = 0; i < len; ++i)
00072     {
00073       os << wsv[i];
00074     }
00075 
00076   return os;
00077 }
00078 
00079 istream &
00080 operator>> (istream &is, CORBA::WString_var &wsv)
00081 {
00082   is.seekg (0, ios::end);
00083   // @@ is.tellg()/sizeof(CORBA::WChar) instead?
00084   CORBA::ULong const len = is.tellg ();
00085   wsv = CORBA::wstring_alloc (len);
00086   is.seekg (0, ios::beg);
00087 
00088   for (CORBA::ULong i = 0; i < len; ++i)
00089     {
00090       CORBA::WChar wc = 0;
00091 
00092       // Unformatted input is used to work around overloaded
00093       // extraction operator (>>) ambiguities on some platforms.
00094       is.read (reinterpret_cast<char *> (&wc), sizeof (wc));
00095 
00096       wsv[i] = wc;
00097     }
00098 
00099   wsv[len] = 0;  // NULL terminate
00100 
00101   return is;
00102 }
00103 
00104 ostream &
00105 operator<< (ostream &os, CORBA::WString_out &wso)
00106 {
00107   CORBA::WChar *tmp = wso.ptr ();
00108   const size_t len = ACE_OS::strlen (tmp);
00109 
00110   for (size_t i = 0; i < len; ++i)
00111     {
00112       os << tmp[i];
00113     }
00114 
00115   return os;
00116 }
00117 
00118 istream &
00119 operator>> (istream &is, CORBA::WString_out &wso)
00120 {
00121   is.seekg (0, ios::end);
00122   // @@ is.tellg()/sizeof(CORBA::WChar) instead?
00123   const CORBA::ULong len = is.tellg ();
00124   wso = CORBA::wstring_alloc (len);
00125   is.seekg (0, ios::beg);
00126 
00127   for (CORBA::ULong i = 0; i < len; ++i)
00128     {
00129       CORBA::WChar wc = 0;
00130 
00131       // Unformatted input is used to work around overloaded
00132       // extraction operator (>>) ambiguities on some platforms.
00133       is.read (reinterpret_cast<char *> (&wc), sizeof (wc));
00134 
00135       wso.ptr ()[i] = wc;
00136     }
00137 
00138   wso.ptr ()[len] = 0;  // NULL terminate
00139 
00140   return is;
00141 }
00142 
00143 #endif /* ACE_LACKS_IOSTREAM_TOTALLY */
00144 
00145 TAO_END_VERSIONED_NAMESPACE_DECL

Generated on Thu Nov 9 11:54:09 2006 for TAO by doxygen 1.3.6