Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / tao / PortableServer / PortableServer_WFunctions.cpp
blob25fcbaf373840c6093fac64fbe922f230a6eb188
1 #include "tao/PortableServer/PortableServer_WFunctions.h"
3 #include "ace/OS_NS_string.h"
5 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
7 namespace PortableServer
9 PortableServer::ObjectId *
10 wstring_to_ObjectId (const CORBA::WChar *string)
12 // Size of Id
14 // We DO NOT include the zero terminator, as this is simply an
15 // artifact of the way strings are stored in C.
17 u_int string_length = ACE_OS::wslen (string);
19 CORBA::ULong buffer_size = string_length * sizeof (CORBA::WChar);
21 // Create the buffer for the Id
22 CORBA::Octet *buffer = PortableServer::ObjectId::allocbuf (buffer_size);
24 // Copy contents
25 ACE_OS::memcpy (buffer, string, buffer_size);
27 // Create a new ID
28 PortableServer::ObjectId *id = 0;
29 ACE_NEW_RETURN (id,
30 PortableServer::ObjectId (buffer_size,
31 buffer_size,
32 buffer,
33 1),
34 0);
36 return id;
39 CORBA::WChar *
40 ObjectId_to_wstring (const PortableServer::ObjectId &id)
42 // Compute resulting wide string's length.
43 CORBA::ULong string_length =
44 id.length () / sizeof (CORBA::WChar);
46 // Allocate an extra slot if the id's length is not "aligned" on a
47 // CORBA::WChar.
48 if (id.length () % sizeof (CORBA::WChar))
49 string_length++;
51 // Create space - note that this method adds + 1 for the '\0'.
52 CORBA::WChar* string = CORBA::wstring_alloc (string_length);
54 // Copy the data
55 ACE_OS::memcpy (string,
56 id.get_buffer (),
57 id.length ());
59 // Null terminate the string
60 string[string_length] = '\0';
62 // Return string.
63 return string;
67 TAO_END_VERSIONED_NAMESPACE_DECL