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
00009 #include "ace/streams.h"
00010
00011 #if !defined (__ACE_INLINE__)
00012 # include "tao/CORBA_String.inl"
00013 #endif
00014
00015 ACE_RCSID (tao,
00016 CORBA_String,
00017 "$Id: CORBA_String.cpp 72136 2006-04-19 09:10:19Z jwillemsen $")
00018
00019 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00020
00021
00022
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
00062
00063
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
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
00093
00094 is.read (reinterpret_cast<char *> (&wc), sizeof (wc));
00095
00096 wsv[i] = wc;
00097 }
00098
00099 wsv[len] = 0;
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
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
00132
00133 is.read (reinterpret_cast<char *> (&wc), sizeof (wc));
00134
00135 wso.ptr ()[i] = wc;
00136 }
00137
00138 wso.ptr ()[len] = 0;
00139
00140 return is;
00141 }
00142
00143 #endif
00144
00145 TAO_END_VERSIONED_NAMESPACE_DECL