Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tao / CORBA_String.cpp
bloba0fe07ad8958df256558efd9c5ad2e7459283ecd
1 #include "tao/CORBA_String.h"
2 #include "tao/String_Manager_T.h"
4 #include "ace/OS_NS_string.h"
5 #include "ace/OS_NS_wchar.h"
6 #include "ace/OS_Memory.h"
8 // FUZZ: disable check_for_streams_include
9 #include "ace/streams.h"
11 #if !defined (__ACE_INLINE__)
12 # include "tao/CORBA_String.inl"
13 #endif /* ! __ACE_INLINE__ */
15 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
17 // *************************************************************
18 // C++ iostream operators for (W)String_var and (W)String_out
19 // *************************************************************
21 #if !defined (ACE_LACKS_IOSTREAM_TOTALLY)
23 ostream &
24 operator<< (ostream &os, const CORBA::String_var &sv)
26 os << sv.in ();
27 return os;
30 istream &
31 operator>> (istream &is, CORBA::String_var &sv)
33 is.seekg (0, ios::end);
34 std::streamsize const n = is.tellg ();
35 sv = CORBA::string_alloc (static_cast<CORBA::ULong> (n));
36 is.seekg (0, ios::beg);
37 is.read (sv.inout (), n);
38 return is;
41 ostream &
42 operator<< (ostream &os, CORBA::String_out &so)
44 os << so.ptr ();
45 return os;
48 istream &
49 operator>> (istream &is, CORBA::String_out &so)
51 is.seekg (0, ios::end);
52 std::streamsize const n = is.tellg ();
53 so = CORBA::string_alloc (static_cast<CORBA::ULong> (n));
54 is.seekg (0, ios::beg);
55 is.read (so.ptr (), n);
56 return is;
59 #ifndef ACE_HAS_CPP20
61 // Until we implement WString support for platforms with a
62 // 4-byte wchar_t, we just define the following to emit
63 // the CORBA::WChars one by one.
65 ostream &
66 operator<< (ostream &os, const CORBA::WString_var &wsv)
68 CORBA::ULong const len =
69 static_cast <CORBA::ULong> (ACE_OS::strlen (wsv.in ()));
71 for (CORBA::ULong i = 0; i < len; ++i)
73 os << wsv[i];
76 return os;
79 istream &
80 operator>> (istream &is, CORBA::WString_var &wsv)
82 is.seekg (0, ios::end);
83 // @@ is.tellg()/sizeof(CORBA::WChar) instead?
84 CORBA::ULong const len = static_cast<CORBA::ULong> (is.tellg ());
85 wsv = CORBA::wstring_alloc (len);
86 is.seekg (0, ios::beg);
88 for (CORBA::ULong i = 0; i < len; ++i)
90 CORBA::WChar wc = 0;
92 // Unformatted input is used to work around overloaded
93 // extraction operator (>>) ambiguities on some platforms.
94 is.read (reinterpret_cast<char *> (&wc), sizeof (wc));
96 wsv[i] = wc;
99 wsv[len] = 0; // NULL terminate
101 return is;
104 ostream &
105 operator<< (ostream &os, CORBA::WString_out &wso)
107 CORBA::WChar *tmp = wso.ptr ();
108 const size_t len = ACE_OS::strlen (tmp);
110 for (size_t i = 0; i < len; ++i)
112 os << tmp[i];
115 return os;
118 istream &
119 operator>> (istream &is, CORBA::WString_out &wso)
121 is.seekg (0, ios::end);
122 // @@ is.tellg()/sizeof(CORBA::WChar) instead?
123 const CORBA::ULong len = static_cast<CORBA::ULong> (is.tellg ());
124 wso = CORBA::wstring_alloc (len);
125 is.seekg (0, ios::beg);
127 for (CORBA::ULong i = 0; i < len; ++i)
129 CORBA::WChar wc = 0;
131 // Unformatted input is used to work around overloaded
132 // extraction operator (>>) ambiguities on some platforms.
133 is.read (reinterpret_cast<char *> (&wc), sizeof (wc));
135 wso.ptr ()[i] = wc;
138 wso.ptr ()[len] = 0; // NULL terminate
140 return is;
143 #endif /* ACE_HAS_CPP20 */
145 #endif /* ACE_LACKS_IOSTREAM_TOTALLY */
147 TAO_END_VERSIONED_NAMESPACE_DECL