summaryrefslogtreecommitdiff
path: root/TAO/tao/CORBA_String.cpp
diff options
context:
space:
mode:
authorbala <bala@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2003-10-28 18:31:01 +0000
committerbala <bala@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2003-10-28 18:31:01 +0000
commitcdb6fd66611283a0314ab23e08472d11dae4f0e4 (patch)
treefd6ae8c3db752254802dfaafd1543974a4741e47 /TAO/tao/CORBA_String.cpp
parentf984aa2bff444f381570d2f97ac9ba958926fb6b (diff)
downloadATCD-cdb6fd66611283a0314ab23e08472d11dae4f0e4.tar.gz
ChangeLogTag:Tue Oct 28 12:02:47 2003 Balachandran Natarajan <bala@dre.vanderbilt.edu>
Diffstat (limited to 'TAO/tao/CORBA_String.cpp')
-rw-r--r--TAO/tao/CORBA_String.cpp120
1 files changed, 111 insertions, 9 deletions
diff --git a/TAO/tao/CORBA_String.cpp b/TAO/tao/CORBA_String.cpp
index 1012fffd777..6c173d9e436 100644
--- a/TAO/tao/CORBA_String.cpp
+++ b/TAO/tao/CORBA_String.cpp
@@ -1,20 +1,104 @@
-#include "tao/CORBA_String.h"
-
-#if !defined (__ACE_INLINE__)
-# include "tao/CORBA_String.inl"
-#endif /* ! __ACE_INLINE__ */
+#include "CORBA_String.h"
+#include "Managed_Types.h"
#include "ace/OS.h"
+#include "ace/OS_Memory.h"
#include "ace/streams.h"
+#if !defined (__ACE_INLINE__)
+# include "tao/CORBA_String.inl"
+#endif /* ! __ACE_INLINE__ */
ACE_RCSID (tao,
CORBA_String,
"$Id$")
+char *
+CORBA::string_dup (const char *str)
+{
+ if (!str)
+ {
+ errno = EINVAL;
+ return 0;
+ }
+
+ size_t len = ACE_OS_String::strlen (str);
+
+ // This allocates an extra byte for the '\0';
+ char * copy = CORBA::string_alloc (ACE_static_cast (CORBA::ULong, len));
+
+ // The memcpy() below assumes that the destination is a valid buffer.
+ if (copy == 0)
+ {
+ return 0;
+ }
+
+ ACE_OS_String::memcpy (copy,
+ str,
+ len + 1);
+ return copy;
+}
+
+char *
+CORBA::string_alloc (CORBA::ULong len)
+{
+ // Allocate 1 + strlen to accomodate the null terminating character.
+
+ char *s = 0;
+ ACE_NEW_RETURN (s,
+ char[size_t (len + 1)],
+ 0);
+
+ return s;
+}
+
+void
+CORBA::string_free (char *str)
+{
+ delete [] str;
+}
+
+// ****************************************************************
+
+CORBA::WChar*
+CORBA::wstring_dup (const WChar *const str)
+{
+ if (!str)
+ {
+ errno = EINVAL;
+ return 0;
+ }
+
+ CORBA::WChar* retval = CORBA::wstring_alloc (ACE_OS_String::strlen (str));
+
+ // The wscpy() below assumes that the destination is a valid buffer.
+ if (retval == 0)
+ {
+ return 0;
+ }
+
+ return ACE_OS::wscpy (retval,
+ str);
+}
+
+CORBA::WChar*
+CORBA::wstring_alloc (CORBA::ULong len)
+{
+ CORBA::WChar *s = 0;
+ ACE_NEW_RETURN (s,
+ CORBA::WChar [(size_t) (len + 1)],
+ 0);
-// String utility support; this needs to be integrated with the ORB's
-// own memory allocation subsystem.
+ return s;
+}
+
+void
+CORBA::wstring_free (CORBA::WChar *const str)
+{
+ delete [] str;
+}
+
+// ****************************************************************
CORBA::String_var::String_var (char *p)
: ptr_ (p)
@@ -118,6 +202,24 @@ CORBA::WString_var::operator= (const CORBA::WString_var& r)
return *this;
}
+// These methods moved to the CPP file to avoid cyclic dependencies.
+// ----------------------------------------------------
+// String_out type
+// ----------------------------------------------------
+CORBA::String_out::String_out (TAO_String_Manager &s)
+ : ptr_ (s.out ())
+{
+}
+
+// ----------------------------------------------------
+// WString_out type
+// ----------------------------------------------------
+CORBA::WString_out::WString_out (TAO_WString_Manager &s)
+ : ptr_ (s.out ())
+{
+}
+
+
// *************************************************************
// C++ iostream operators for (W)String_var and (W)String_out
// *************************************************************
@@ -165,7 +267,7 @@ operator>> (istream &is, CORBA::String_out &so)
ostream &
operator<< (ostream &os, const CORBA::WString_var &wsv)
{
- const CORBA::ULong len = ACE_OS::wslen (wsv.in ());
+ const CORBA::ULong len = ACE_OS_String::strlen (wsv.in ());
for (CORBA::ULong i = 0; i < len; ++i)
{
@@ -204,7 +306,7 @@ ostream &
operator<< (ostream &os, CORBA::WString_out &wso)
{
CORBA::WChar *tmp = wso.ptr ();
- const CORBA::ULong len = ACE_OS::wslen (tmp);
+ const CORBA::ULong len = ACE_OS_String::strlen (tmp);
for (CORBA::ULong i = 0; i < len; ++i)
{