Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / tao / PortableServer / PortableServer_Functions.cpp
blob3bf950df3541dc3356bb5ae5e54f3c71bb2b5363
1 // -*- C++ -*-
2 #include "tao/PortableServer/PortableServer_Functions.h"
3 #include "ace/OS_NS_string.h"
4 #include <cstring>
6 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
8 namespace PortableServer
10 PortableServer::ObjectId *
11 string_to_ObjectId (const char *string)
13 // Passing in a nil pointer is illegal so throw an exception to
14 // indicate that
15 if (string == 0)
17 throw ::CORBA::BAD_PARAM ();
20 // Size of string
22 // We DO NOT include the zero terminator, as this is simply an
23 // artifact of the way strings are stored in C.
25 CORBA::ULong buffer_size = static_cast <CORBA::ULong>
26 (std::strlen (string));
28 // Create the buffer for the Id
29 CORBA::Octet *buffer = PortableServer::ObjectId::allocbuf (buffer_size);
31 // Copy the contents
32 ACE_OS::memcpy (buffer, string, buffer_size);
34 // Create and return a new ID
35 PortableServer::ObjectId *id = 0;
36 ACE_NEW_RETURN (id,
37 PortableServer::ObjectId (buffer_size,
38 buffer_size,
39 buffer,
40 1),
41 0);
43 return id;
46 char *
47 ObjectId_to_string (const PortableServer::ObjectId &id)
49 // Create space
50 char * string = CORBA::string_alloc (id.length ());
52 // Copy the data
53 ACE_OS::memcpy (string, id.get_buffer (), id.length ());
55 // Null terminate the string
56 string[id.length ()] = '\0';
58 // Return string
59 return string;
64 TAO_END_VERSIONED_NAMESPACE_DECL