summaryrefslogtreecommitdiff
path: root/TAO/tao/PortableServer/PortableServer_WFunctions.cpp
diff options
context:
space:
mode:
authorJohnny Willemsen <jwillemsen@remedy.nl>2005-02-18 09:07:14 +0000
committerJohnny Willemsen <jwillemsen@remedy.nl>2005-02-18 09:07:14 +0000
commit685cbd31f0c2b28e550cff1226b6dea3f3150136 (patch)
tree91ba7fc4584511f31379702bdcf543da966f7f78 /TAO/tao/PortableServer/PortableServer_WFunctions.cpp
parent872553f0d5680b863cd6b1948c68ca20a7269e46 (diff)
downloadATCD-685cbd31f0c2b28e550cff1226b6dea3f3150136.tar.gz
ChangeLogTag: Fri Feb 18 17:04:12 UTC 2005 Johnny Willemsen <jwillemsen@remedy.nl>
Diffstat (limited to 'TAO/tao/PortableServer/PortableServer_WFunctions.cpp')
-rw-r--r--TAO/tao/PortableServer/PortableServer_WFunctions.cpp68
1 files changed, 68 insertions, 0 deletions
diff --git a/TAO/tao/PortableServer/PortableServer_WFunctions.cpp b/TAO/tao/PortableServer/PortableServer_WFunctions.cpp
new file mode 100644
index 00000000000..d37374d5062
--- /dev/null
+++ b/TAO/tao/PortableServer/PortableServer_WFunctions.cpp
@@ -0,0 +1,68 @@
+#include "PortableServer_WFunctions.h"
+
+ACE_RCSID (PortableServer,
+ PortableServer_WFunctions,
+ "$Id$")
+
+#include "ace/OS_NS_string.h"
+
+namespace PortableServer
+{
+ PortableServer::ObjectId *
+ wstring_to_ObjectId (const CORBA::WChar *string)
+ {
+ // Size of Id
+ //
+ // We DO NOT include the zero terminator, as this is simply an
+ // artifact of the way strings are stored in C.
+ //
+ CORBA::ULong string_length = ACE_OS::wslen (string);
+
+ CORBA::ULong buffer_size = string_length * sizeof (CORBA::WChar);
+
+ // Create the buffer for the Id
+ CORBA::Octet *buffer = PortableServer::ObjectId::allocbuf (buffer_size);
+
+ // Copy contents
+ ACE_OS::memcpy (buffer, string, buffer_size);
+
+ // Create a new ID
+ PortableServer::ObjectId *id = 0;
+ ACE_NEW_RETURN (id,
+ PortableServer::ObjectId (buffer_size,
+ buffer_size,
+ buffer,
+ 1),
+ 0);
+
+ return id;
+ }
+
+ CORBA::WChar *
+ ObjectId_to_wstring (const PortableServer::ObjectId &id)
+ {
+ // Compute resulting wide string's length.
+ CORBA::ULong string_length =
+ id.length () / sizeof (CORBA::WChar) + 1;
+
+ // Allocate an extra slot if the id's length is not "aligned" on a
+ // CORBA::WChar.
+ if (id.length () % sizeof (CORBA::WChar))
+ string_length++;
+
+ // Create space.
+ CORBA::WChar* string = CORBA::wstring_alloc (string_length);
+
+ // Copy the data
+ ACE_OS::memcpy (string,
+ id.get_buffer (),
+ id.length ());
+
+ // Null terminate the string
+ string[string_length] = '\0';
+
+ // Return string.
+ return string;
+ }
+}
+