summaryrefslogtreecommitdiff
path: root/tao/PortableServer/PortableServer_Functions.cpp
blob: 4c0eb61834554caa90931284e610d9250eb51610 (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
69
70
71
72
73
74
#include "tao/PortableServer/PortableServer_Functions.h"

ACE_RCSID (PortableServer,
           PortableServer_Functions,
           "$Id$")

#include "ace/OS_NS_string.h"

TAO_BEGIN_VERSIONED_NAMESPACE_DECL

namespace PortableServer
{
  PortableServer::ObjectId
  string_to_ObjectId (const char *string)
  {
    // Size of string
    //
    // We DO NOT include the zero terminator, as this is simply an
    // artifact of the way strings are stored in C.
    //
    CORBA::ULong buffer_size = static_cast <CORBA::ULong>
                                           (ACE_OS::strlen (string));
                                           
    PortableServer::ObjectId id;
    id.resize (buffer_size);
                                           
    for (CORBA::ULong i = 0; i < buffer_size; ++i)
      {
        id[i] = string[i];
      }
/*
    // Create the buffer for the Id
    CORBA::Octet *buffer = PortableServer::ObjectId::allocbuf (buffer_size);

    // Copy the contents
    ACE_OS::memcpy (buffer, string, buffer_size);

    // Create and return a new ID
    PortableServer::ObjectId *id = 0;
    ACE_NEW_RETURN (id,
                    PortableServer::ObjectId (buffer_size,
                                              buffer_size,
                                              buffer,
                                              1),
                    0);
*/
    return id;
  }

  char *
  ObjectId_to_string (const PortableServer::ObjectId &id)
  {
    CORBA::ULong length = id.size ();
    // Create space
    char * string = CORBA::string_alloc (length);

    // Copy the data
//    ACE_OS::memcpy (string, id.get_buffer (), id.length ());

    for (CORBA::ULong i = 0; i < length; ++i)
      {
        string[i] = id[i];
      }

    // Null terminate the string
    string[length] = '\0';

    // Return string
    return string;
  }
}


TAO_END_VERSIONED_NAMESPACE_DECL