summaryrefslogtreecommitdiff
path: root/TAO/tao/String_Traits_Base_T.h
blob: d750ddd1f7eae5223fb096f746cf6b2fb026b45f (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
#ifndef guard_string_traits_base_hpp
#define guard_string_traits_base_hpp
/**
 * @file
 *
 * @brief Isolate the string_traits from the accidental differences
 * between wstring and string.
 *
 * @author Carlos O'Ryan
 */

#include "tao/String_Alloc.h"
#include "ace/CDR_Stream.h"

TAO_BEGIN_VERSIONED_NAMESPACE_DECL

namespace TAO
{
template<typename charT>
class String_Manager_T;

template<typename charT>
class String_var;

template<typename charT>
class String_out;

namespace details
{
template<typename charT>
struct string_traits_base
{
};

template<>
struct string_traits_base<char>
{
  typedef char char_type;
  typedef TAO::String_var <char_type> string_var;
  typedef TAO::String_out <char_type> string_out;
  typedef TAO::String_Manager_T <char_type> string_mgr;
  typedef ACE_InputCDR::to_string to_type;
  typedef ACE_OutputCDR::from_string from_type;

  inline static char_type * default_initializer()
  {
    return CORBA::string_dup("");
  }

  inline static char_type * duplicate(char_type const * s)
  {
    return CORBA::string_dup(s);
  }

  inline static void release(char_type * s)
  {
    CORBA::string_free(s);
  }

  inline static char_type * allocate (CORBA::ULong len)
  {
    return CORBA::string_alloc (len);
  }
};

template<>
struct string_traits_base<CORBA::WChar>
{
  typedef CORBA::WChar char_type;
  typedef TAO::String_var <char_type> string_var;
  typedef TAO::String_out <char_type> string_out;
  typedef TAO::String_Manager_T <char_type> string_mgr;
  typedef ACE_InputCDR::to_wstring to_type;
  typedef ACE_OutputCDR::from_wstring from_type;

  inline static char_type * default_initializer()
  {
#if defined(ACE_HAS_WCHAR) || defined(ACE_HAS_XPG4_MULTIBYTE_CHAR)
    return CORBA::wstring_dup(L"");
#else
//#warning "platform not configured with native wchar_t support"
//    static CORBA::WChar empty[] = { 0 };
    CORBA::WChar empty[] = { 0 };
    return CORBA::wstring_dup(empty);
#endif /* 0 */
  }

  inline static char_type * duplicate(char_type const * s)
  {
    return CORBA::wstring_dup(s);
  }

  inline static void release(char_type * s)
  {
    CORBA::wstring_free(s);
  }

  inline static char_type * allocate (CORBA::ULong len)
  {
    return CORBA::wstring_alloc (len);
  }
};
} // namespace details
} // namespace TAO

TAO_END_VERSIONED_NAMESPACE_DECL

#endif // guard_string_traits_base_hpp