summaryrefslogtreecommitdiff
path: root/ace/ace_wchar.h
blob: 329f3f8607daa0f9c5e6c3d2f422c2a6494485d5 (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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
/* -*- C++ -*- */

//=============================================================================
/**
 *  @file    ace_wchar.h
 *
 *  $Id$
 *
 *  @author Darrell Brunsch
 */
//=============================================================================


#ifndef ACE_WCHAR_H
#define ACE_WCHAR_H

#if !defined (ACE_LACKS_PRAGMA_ONCE)
# pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */

// These macros have been deprecated and should be replaced by their
// ACE_TEXT_* equivalents.  These macros are just hacks and may not
// completely provide the old functionality.
#if defined (ACE_LEGACY_MODE)
// Convert the old unicode indicators
# if defined (ACE_HAS_MOSTLY_UNICODE_APIS)
#   define ACE_USES_WCHAR
# endif /* ACE_HAS_MOSTLY_UNICODE_APIS */
# if defined (ACE_HAS_UNICODE)
#   define ACE_HAS_WCHAR
# endif /* ACE_HAS_UNICODE */

// These are defined to get older stuff to compile
// FUZZ: disable check_for_tchar
# define ASYS_TCHAR ACE_TCHAR
# define ASYS_TEXT ACE_TEXT
# define ASYS_ONLY_MULTIBYTE_STRING ACE_TEXT_ALWAYS_CHAR
# define ASYS_MULTIBYTE_STRING ACE_TEXT_CHAR_TO_TCHAR
# define ASYS_WIDE_STRING ACE_TEXT_CHAR_TO_TCHAR
# define ACE_WIDE_STRING ACE_TEXT_CHAR_TO_TCHAR

# if defined (ACE_USES_WCHAR)
#   define ASYS_ONLY_WIDE_STRING(STRING) STRING
# else /* ACE_USES_WCHAR */
#   define ASYS_ONLY_WIDE_STRING(STRING) \
           ACE_Ascii_To_Wide (STRING).wchar_rep ()
# endif /* ACE_USES_WCHAR */

# define ACE_TEXT_STRING ACE_TString

#endif /* ACE_LEGACY_MODE */

#if defined (ACE_HAS_WCHAR)
# if defined (VXWORKS)
#   include /**/ <types/vxTypes.h>  /* For wchar_t */
#   include /**/ <stdlib.h>         /* For mbstowcs, etc. */
#   include /**/ <string.h>         /* For strlen */
#   define wint_t unsigned int      /* VxWorks has wchar_t but not wint_t */
# elif defined (ACE_HAS_STANDARD_CPP_LIBRARY) && \
    (ACE_HAS_STANDARD_CPP_LIBRARY != 0)
#   include /**/ <cwchar>
#   include /**/ <cwctype>
# elif !defined (__BORLANDC__) && !defined (ACE_HAS_WINCE)
#   include /**/ <wchar.h>
# endif /* ACE_HAS_STANDARD_CPP_LIBRARY */
#elif defined (ACE_HAS_XPG4_MULTIBYTE_CHAR)
# include /**/ <wchar.h>
#endif

#if defined (ACE_USES_STD_NAMESPACE_FOR_STDC_LIB) && \
            (ACE_USES_STD_NAMESPACE_FOR_STDC_LIB != 0)
using std::size_t;
#endif /* ACE_USES_STD_NAMESPACE_FOR_STDC_LIB */

// Since MSVC uses ushort16 = wchar_t, it is the only one
// that does not need this defined

#if defined (ACE_HAS_WCHAR) && !defined (_MSC_VER)
# if !defined (ACE_WSTRING_HAS_USHORT_SUPPORT)
#  define ACE_WSTRING_HAS_USHORT_SUPPORT
# endif /* ACE_WSTRING_HAS_USHORT_SUPPORT */
#endif /* ACE_HAS_WCHAR && !_MSC_VER */

// Define the unicode/wchar related macros correctly

# if !defined (ACE_TEXT_WIDE)
#  define ACE_TEXT_WIDE_I(STRING) L##STRING
#  define ACE_TEXT_WIDE(STRING) ACE_TEXT_WIDE_I (STRING)
# endif /* ACE_TEXT_WIDE */

#if defined (ACE_USES_WCHAR)
typedef wchar_t ACE_TCHAR;
typedef char ACE_ANTI_TCHAR;
# define ACE_LIB_TEXT(STRING) ACE_TEXT_WIDE (STRING)
# define ACE_TEXT_ALWAYS_CHAR(STRING) ACE_Wide_To_Ascii (STRING).char_rep ()
# define ACE_TEXT_CHAR_TO_TCHAR(STRING) ACE_Ascii_To_Wide (STRING).wchar_rep ()
# define ACE_TEXT_WCHAR_TO_TCHAR(STRING) STRING
# define ACE_TEXT_ANTI_TO_TCHAR(STRING) ACE_Ascii_To_Wide (STRING).wchar_rep ()
#else /* ACE_USES_WCHAR */
typedef char ACE_TCHAR;
typedef wchar_t ACE_ANTI_TCHAR;
# define ACE_LIB_TEXT(STRING) STRING
# define ACE_TEXT_ALWAYS_CHAR(STRING) STRING
# define ACE_TEXT_CHAR_TO_TCHAR(STRING) STRING
# define ACE_TEXT_WCHAR_TO_TCHAR(STRING) ACE_Wide_To_Ascii (STRING).char_rep ()
# define ACE_TEXT_ANTI_TO_TCHAR(STRING) ACE_Wide_To_Ascii (STRING).char_rep ()
#endif /* ACE_USES_WCHAR */

#if defined (ACE_LEGACY_MODE)
# define ACE_TEXT TEXT
#else /* ACE_LEGACY_MODE */
# define ACE_TEXT ACE_LIB_TEXT
#endif /* ACE_LEGACY_MODE */

#if defined ACE_HAS_WCHAR
/**
 * @class ACE_Wide_To_Ascii
 *
 * @brief A lightweight wchar* to char* string conversion class.
 *
 * The purpose of this class is to perform conversion from
 * wchar* to char* strings.  It is not intended for general
 * purpose use.
 */
class ACE_Wide_To_Ascii
{
public:
  /// Ctor must take a wchar string.
  ACE_Wide_To_Ascii (const wchar_t *s);

  /// Dtor will free up the memory.
  ~ACE_Wide_To_Ascii (void);

  /// Return the internal char* representation.
  char *char_rep (void);

  /// Converts an wchar_t string to ascii and returns a new string.
  static char *convert (const wchar_t *wstr);

private:
  /// Internal pointer to the converted string.
  char *s_;

  /// Disallow these operation.
  ACE_Wide_To_Ascii (void);
  ACE_Wide_To_Ascii (ACE_Wide_To_Ascii &);
  ACE_Wide_To_Ascii& operator= (ACE_Wide_To_Ascii &);
};

/**
 * @class ACE_Ascii_To_Wide
 *
 * @brief A lightweight char* to wchar* string conversion class.
 *
 * The purpose of this class is to perform conversion from
 * char* to wchar* strings.  It is not intended for general
 * purpose use.
 */
class ACE_Ascii_To_Wide
{
public:
  /// Ctor must take a wchar string.
  ACE_Ascii_To_Wide (const char *s);

  /// Dtor will free up the memory.
  ~ACE_Ascii_To_Wide (void);

  /// Return the internal wchar* representation.
  wchar_t *wchar_rep (void);

  /// Converts an char string to unicode/wide and returns a new string.
  static wchar_t *convert (const char *str);

private:
  /// Internal pointer to the converted string.
  wchar_t *s_;

  /// Disallow these operation.
  ACE_Ascii_To_Wide (void);
  ACE_Ascii_To_Wide (ACE_Ascii_To_Wide &);
  ACE_Ascii_To_Wide operator= (ACE_Ascii_To_Wide &);
};

#if defined (ACE_LEGACY_MODE)
typedef ACE_Ascii_To_Wide ACE_OS_CString;
typedef ACE_Wide_To_Ascii ACE_OS_WString;
#endif /* ACE_LEGACY_MODE */

#endif /* ACE_HAS_WCHAR */

#if defined (ACE_WIN32)
#if defined (ACE_USES_WCHAR)
#define ACE_TEXT_STARTUPINFO              STARTUPINFOW
#define ACE_TEXT_WIN32_FIND_DATA          WIN32_FIND_DATAW

#define ACE_TEXT_CreateEvent              ::CreateEventW
#define ACE_TEXT_CreateFile               ::CreateFileW
#define ACE_TEXT_CreateFileMapping        ::CreateFileMappingW
#define ACE_TEXT_CreateMutex              ::CreateMutexW
#define ACE_TEXT_CreateProcess            ::CreateProcessW
#define ACE_TEXT_CreateSemaphore          ::CreateSemaphoreW
#define ACE_TEXT_CreateService            ::CreateServiceW
#define ACE_TEXT_ExpandEnvironmentStrings ::ExpandEnvironmentStringsW
#define ACE_TEXT_FindFirstFile            ::FindFirstFileW
#define ACE_TEXT_FindNextFile             ::FindNextFileW
#define ACE_TEXT_FormatMessage            ::FormatMessageW
#define ACE_TEXT_FreeEnvironmentStrings   ::FreeEnvironmentStringsW
#define ACE_TEXT_GetComputerName          ::GetComputerNameW
#define ACE_TEXT_GetModuleFileName        ::GetModuleFileNameW
#define ACE_TEXT_GetTempPath              ::GetTempPathW
#define ACE_TEXT_GetUserName              ::GetUserNameW
#define ACE_TEXT_LoadLibrary              ::LoadLibraryW
#define ACE_TEXT_MoveFileEx               ::MoveFileExW
#define ACE_TEXT_OpenSCManager            ::OpenSCManagerW
#define ACE_TEXT_OpenService              ::OpenServiceW
#define ACE_TEXT_RegConnectRegistry       ::RegConnectRegistryW
#define ACE_TEXT_RegCreateKeyEx           ::RegCreateKeyExW
#define ACE_TEXT_RegDeleteKey             ::RegDeleteKeyW
#define ACE_TEXT_RegDeleteValue           ::RegDeleteValueW
#define ACE_TEXT_RegEnumKeyEx             ::RegEnumKeyExW
#define ACE_TEXT_RegEnumValue             ::RegEnumValueW
#define ACE_TEXT_RegOpenKey               ::RegOpenKeyW
#define ACE_TEXT_RegOpenKeyEx             ::RegOpenKeyExW
#define ACE_TEXT_RegQueryValueEx          ::RegQueryValueExW
#define ACE_TEXT_RegSetValueEx            ::RegSetValueExW
#define ACE_TEXT_StartService             ::StartServiceW

#else /* ACE_USES_WCHAR */
#define ACE_TEXT_STARTUPINFO              STARTUPINFOA
#define ACE_TEXT_WIN32_FIND_DATA          WIN32_FIND_DATAA

#define ACE_TEXT_CreateEvent              ::CreateEventA
#define ACE_TEXT_CreateFile               ::CreateFileA
#define ACE_TEXT_CreateFileMapping        ::CreateFileMappingA
#define ACE_TEXT_CreateMutex              ::CreateMutexA
#define ACE_TEXT_CreateProcess            ::CreateProcessA
#define ACE_TEXT_CreateSemaphore          ::CreateSemaphoreA
#define ACE_TEXT_CreateService            ::CreateServiceA
#define ACE_TEXT_ExpandEnvironmentStrings ::ExpandEnvironmentStringsA
#define ACE_TEXT_FindFirstFile            ::FindFirstFileA
#define ACE_TEXT_FindNextFile             ::FindNextFileA
#define ACE_TEXT_FormatMessage            ::FormatMessageA
#define ACE_TEXT_FreeEnvironmentStrings   ::FreeEnvironmentStringsA
#define ACE_TEXT_GetComputerName          ::GetComputerNameA
#define ACE_TEXT_GetModuleFileName        ::GetModuleFileNameA
#define ACE_TEXT_GetTempPath              ::GetTempPathA
#define ACE_TEXT_GetUserName              ::GetUserNameA
#define ACE_TEXT_LoadLibrary              ::LoadLibraryA
#define ACE_TEXT_MoveFileEx               ::MoveFileExA
#define ACE_TEXT_OpenSCManager            ::OpenSCManagerA
#define ACE_TEXT_OpenService              ::OpenServiceA
#define ACE_TEXT_RegConnectRegistry       ::RegConnectRegistryA
#define ACE_TEXT_RegCreateKeyEx           ::RegCreateKeyExA
#define ACE_TEXT_RegDeleteKey             ::RegDeleteKeyA
#define ACE_TEXT_RegDeleteValue           ::RegDeleteValueA
#define ACE_TEXT_RegEnumKeyEx             ::RegEnumKeyExA
#define ACE_TEXT_RegEnumValue             ::RegEnumValueA
#define ACE_TEXT_RegOpenKey               ::RegOpenKeyA
#define ACE_TEXT_RegOpenKeyEx             ::RegOpenKeyExA
#define ACE_TEXT_RegQueryValueEx          ::RegQueryValueExA
#define ACE_TEXT_RegSetValueEx            ::RegSetValueExA
#define ACE_TEXT_StartService             ::StartServiceA
#endif /* ACE_USES_WCHAR */
#endif /* ACE_WIN32 */

#include "ace/ace_wchar.inl"

#endif /* ACE_WCHAR_H */