PortableServer_WFunctions.cpp

Go to the documentation of this file.
00001 #include "tao/PortableServer/PortableServer_WFunctions.h"
00002 
00003 ACE_RCSID (PortableServer,
00004            PortableServer_WFunctions,
00005            "$Id: PortableServer_WFunctions.cpp 71473 2006-03-10 07:19:20Z jtc $")
00006 
00007 #include "ace/OS_NS_string.h"
00008 
00009 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00010 
00011 namespace PortableServer
00012 {
00013   PortableServer::ObjectId *
00014   wstring_to_ObjectId (const CORBA::WChar *string)
00015   {
00016     // Size of Id
00017     //
00018     // We DO NOT include the zero terminator, as this is simply an
00019     // artifact of the way strings are stored in C.
00020     //
00021     u_int string_length = ACE_OS::wslen (string);
00022 
00023     CORBA::ULong buffer_size = string_length * sizeof (CORBA::WChar);
00024 
00025     // Create the buffer for the Id
00026     CORBA::Octet *buffer = PortableServer::ObjectId::allocbuf (buffer_size);
00027 
00028     // Copy contents
00029     ACE_OS::memcpy (buffer, string, buffer_size);
00030 
00031     // Create a new ID
00032     PortableServer::ObjectId *id = 0;
00033     ACE_NEW_RETURN (id,
00034                     PortableServer::ObjectId (buffer_size,
00035                                               buffer_size,
00036                                               buffer,
00037                                               1),
00038                     0);
00039 
00040     return id;
00041   }
00042 
00043   CORBA::WChar *
00044   ObjectId_to_wstring (const PortableServer::ObjectId &id)
00045   {
00046     // Compute resulting wide string's length.
00047     CORBA::ULong string_length =
00048       id.length () / sizeof (CORBA::WChar);
00049 
00050     // Allocate an extra slot if the id's length is not "aligned" on a
00051     // CORBA::WChar.
00052     if (id.length () % sizeof (CORBA::WChar))
00053       string_length++;
00054 
00055     // Create space - note that this method adds + 1 for the '\0'.
00056     CORBA::WChar* string = CORBA::wstring_alloc (string_length);
00057 
00058     // Copy the data
00059     ACE_OS::memcpy (string,
00060                     id.get_buffer (),
00061                     id.length ());
00062 
00063     // Null terminate the string
00064     string[string_length] = '\0';
00065 
00066     // Return string.
00067     return string;
00068   }
00069 }
00070 
00071 TAO_END_VERSIONED_NAMESPACE_DECL

Generated on Tue Feb 2 17:40:54 2010 for TAO_PortableServer by  doxygen 1.4.7