blob: d37374d5062263226200d105ed59a2f227c0a053 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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;
}
}
|