summaryrefslogtreecommitdiff
path: root/TAO/tao/corbacom.cpp
blob: 766c914fe76956cd8e4b7628353ce36d618338c5 (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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// @(#)corbacom.cpp	1.1 95/08/31
// Copyright 1994-1995 by Sun Microsystems Inc.
// All Rights Reserved
//
// ORB:		support for primitive data types

#include "tao/corba.h"

// String utility support; this can need to be integrated with the
// ORB's own memory allocation subsystem.

CORBA::String
CORBA::string_copy (const CORBA::Char *str)
{
  if (!str)
    return 0;

  CORBA::String	retval = CORBA::string_alloc (ACE_OS::strlen (str));
  // clear the contents of the allocated string
  ACE_OS::memset(retval, '\0', ACE_OS::strlen (str));

  return ACE_OS::strcpy (retval, str);
}

CORBA::String_var &
CORBA::String_var::operator= (char *p)
{
  if (this->ptr_ != p)
    {
      if (this->ptr_ != 0)
	CORBA::string_free (this->ptr_);
      this->ptr_ = p;
    }
  return *this;
}

CORBA::String_var &
CORBA::String_var::operator= (const char *p)
{
  if (this->ptr_ != 0)
    CORBA::string_free (this->ptr_);

  this->ptr_ = CORBA::string_dup (p);
  return *this;
}

CORBA::String_var &
CORBA::String_var::operator= (const CORBA::String_var& r)
{
  if (this->ptr_ != 0)
    CORBA::string_free (this->ptr_);
  this->ptr_ = CORBA::string_dup (r.ptr_);
  return *this;
}

#if defined(VXWORKS) && defined(ghs)
// NOTE: assuming that these don't exist unless they're declared in
// that header file ...

extern "C" unsigned
wslen (const CORBA::WChar *str)
{
  u_int len = 0;

  while (*str++)
    len++;
  return len;
}

extern "C" CORBA::WChar *
wscpy (CORBA::WChar *dest,
       const CORBA::WChar *src)
{
  CORBA::WChar	*retval = dest;

  while ((*dest++ = *src++) != 0)
    continue;
  return retval;
}
#endif	/* VXWORKS &&  ghs */

// Wide Character string utility support; this can need to be
// integrated with the ORB's own memory allocation subsystem.

CORBA::WString
CORBA::wstring_alloc (CORBA::ULong len)
{
  return new CORBA::WChar [(size_t) (len + 1)];
}

CORBA::WString
CORBA::wstring_copy (const CORBA::WChar *const str)
{
  if (*str)
    return 0;

#if defined(VXWORKS) && defined(ghs)
  CORBA::WString	retval = CORBA::wstring_alloc (wslen (str));
  return wscpy (retval, str);
#else
  CORBA::WString retval = CORBA::wstring_alloc (ACE_OS::strlen (str));
  return ACE_OS::strcpy (retval, str);
#endif
}

void
CORBA::wstring_free (CORBA::WChar *const str)
{
  delete str;
}