ace_wchar.h

Go to the documentation of this file.
00001 /* -*- C++ -*- */
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    ace_wchar.h
00006  *
00007  *  $Id: ace_wchar.h 81503 2008-04-28 18:28:15Z johnnyw $
00008  *
00009  *  @author Darrell Brunsch <brunsch@uci.edu>
00010  */
00011 //=============================================================================
00012 
00013 #ifndef ACE_WCHAR_H
00014 #define ACE_WCHAR_H
00015 
00016 #include "ace/config-macros.h"
00017 
00018 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00019 # pragma once
00020 #endif /* ACE_LACKS_PRAGMA_ONCE */
00021 
00022 // These macros have been deprecated and should be replaced by their
00023 // ACE_TEXT_* equivalents.  These macros are just hacks and may not
00024 // completely provide the old functionality.
00025 #if defined (ACE_LEGACY_MODE)
00026 // Convert the old unicode indicators
00027 # if defined (ACE_HAS_MOSTLY_UNICODE_APIS)
00028 #   define ACE_USES_WCHAR
00029 # endif /* ACE_HAS_MOSTLY_UNICODE_APIS */
00030 # if defined (ACE_HAS_UNICODE)
00031 #   define ACE_HAS_WCHAR
00032 # endif /* ACE_HAS_UNICODE */
00033 
00034 // These are defined to get older stuff to compile
00035 // FUZZ: disable check_for_tchar
00036 # define ASYS_TCHAR ACE_TCHAR
00037 # define ASYS_TEXT ACE_TEXT
00038 # define ASYS_ONLY_MULTIBYTE_STRING ACE_TEXT_ALWAYS_CHAR
00039 # define ASYS_MULTIBYTE_STRING ACE_TEXT_CHAR_TO_TCHAR
00040 # define ASYS_WIDE_STRING ACE_TEXT_CHAR_TO_TCHAR
00041 # define ACE_WIDE_STRING ACE_TEXT_CHAR_TO_TCHAR
00042 
00043 # if defined (ACE_USES_WCHAR)
00044 #   define ASYS_ONLY_WIDE_STRING(STRING) STRING
00045 # else /* ACE_USES_WCHAR */
00046 #   define ASYS_ONLY_WIDE_STRING(STRING) \
00047            ACE_Ascii_To_Wide (STRING).wchar_rep ()
00048 # endif /* ACE_USES_WCHAR */
00049 
00050 # define ACE_TEXT_STRING ACE_TString
00051 
00052 #endif /* ACE_LEGACY_MODE */
00053 
00054 #if defined (ACE_HAS_XPG4_MULTIBYTE_CHAR)
00055 #  if !defined (ACE_HAS_WCHAR)
00056 #    define ACE_HAS_WCHAR
00057 #  endif
00058 #  include /**/ <wchar.h>
00059 #endif /* ACE_HAS_XPG4_MULTIBYTE_CHAR */
00060 
00061 #if defined (ACE_HAS_WCHAR)
00062 # if defined (ACE_VXWORKS)
00063 #   include /**/ <types/vxTypes.h>  /* For wchar_t */
00064 #   include /**/ <stdlib.h>         /* For mbstowcs, etc. */
00065 #   include /**/ <string.h>         /* For strlen */
00066 #   if !defined (__RTP__)
00067 #     define wint_t unsigned int    /* VxWorks has wchar_t but not wint_t */
00068 #   else
00069 #     include /**/ <wchar.h>
00070 #     include /**/ <wctype.h>
00071 #   endif
00072 # elif defined (ACE_OPENVMS)
00073 #   include /**/ <wchar.h>
00074 #   include /**/ <wctype.h>
00075 # elif defined (ACE_HAS_STANDARD_CPP_LIBRARY) && \
00076     (ACE_HAS_STANDARD_CPP_LIBRARY != 0)
00077 #   include /**/ <cwchar>
00078 #   include /**/ <cwctype>
00079 # elif defined (ACE_HAS_WINCE)
00080 #   include /**/ <wtypes.h>
00081 # elif !defined (__BORLANDC__)
00082 #   include /**/ <wchar.h>
00083 # endif /* ACE_HAS_STANDARD_CPP_LIBRARY */
00084 #endif /* ACE_HAS_WCHAR */
00085 
00086 #if defined (ACE_HAS_ICONV)
00087 #  include /**/ <iconv.h>
00088 #  if !defined (ACE_MAX_ICONV_BUFFER)
00089 #    define ACE_MAX_ICONV_BUFFER   16*1024
00090 #  endif
00091 #endif /* ACE_HAS_ICONV */
00092 
00093 #if defined (ACE_USES_STD_NAMESPACE_FOR_STDC_LIB) && \
00094             (ACE_USES_STD_NAMESPACE_FOR_STDC_LIB != 0)
00095 using std::size_t;
00096 #endif /* ACE_USES_STD_NAMESPACE_FOR_STDC_LIB */
00097 
00098 // This makes the somewhat dubious assumption that if a platform lacks
00099 // a native wchar_t type, then it will typedef it as unsigned short.
00100 #if defined (ACE_HAS_WCHAR) && !defined (ACE_LACKS_NATIVE_WCHAR_T)
00101 # if !defined (ACE_WSTRING_HAS_USHORT_SUPPORT)
00102 #  define ACE_WSTRING_HAS_USHORT_SUPPORT
00103 # endif /* ACE_WSTRING_HAS_USHORT_SUPPORT */
00104 #endif /* ACE_HAS_WCHAR && !ACE_LACKS_NATIVE_WCHAR_T */
00105 
00106 // Set the default behaviour for ACE_TEXT_WIDE to use the L-prefix
00107 #if !defined (ACE_USES_L_PREFIX)
00108 # define ACE_USES_L_PREFIX 1
00109 #endif /* ACE_USES_L_PREFIX */
00110 
00111 // Define the unicode/wchar related macros correctly
00112 
00113 # if !defined (ACE_TEXT_WIDE)
00114 #  if (ACE_USES_L_PREFIX == 1)
00115 #    define ACE_TEXT_WIDE_I(STRING) L##STRING
00116 #  else /* ACE_USES_L_PREFIX */
00117 #    define ACE_TEXT_WIDE_I(STRING) STRING
00118 #  endif /* ACE_USES_L_PREFIX */
00119 #  define ACE_TEXT_WIDE(STRING) ACE_TEXT_WIDE_I (STRING)
00120 # endif /* ACE_TEXT_WIDE */
00121 
00122 #if defined (ACE_USES_WCHAR)
00123 typedef wchar_t ACE_TCHAR;
00124 typedef char ACE_ANTI_TCHAR;
00125 # define ACE_TEXT(STRING) ACE_TEXT_WIDE (STRING)
00126 # if !defined (ACE_LACKS_DEPRECATED_MACROS)
00127 #  define ACE_LIB_TEXT(STRING) ACE_TEXT_WIDE (STRING)
00128 # endif
00129 # define ACE_TEXT_ALWAYS_CHAR(STRING) ACE_Wide_To_Ascii (STRING).char_rep ()
00130 # define ACE_TEXT_ALWAYS_WCHAR(STRING) STRING
00131 # define ACE_TEXT_CHAR_TO_TCHAR(STRING) ACE_Ascii_To_Wide (STRING).wchar_rep ()
00132 # define ACE_TEXT_WCHAR_TO_TCHAR(STRING) STRING
00133 # define ACE_TEXT_ANTI_TO_TCHAR(STRING) ACE_Ascii_To_Wide (STRING).wchar_rep ()
00134 #else /* ACE_USES_WCHAR */
00135 typedef char ACE_TCHAR;
00136 typedef wchar_t ACE_ANTI_TCHAR;
00137 # define ACE_TEXT(STRING) STRING
00138 # if !defined (ACE_LACKS_DEPRECATED_MACROS)
00139 #  define ACE_LIB_TEXT(STRING) STRING
00140 # endif
00141 # define ACE_TEXT_ALWAYS_CHAR(STRING) STRING
00142 # define ACE_TEXT_ALWAYS_WCHAR(STRING) ACE_Ascii_To_Wide (STRING).wchar_rep ()
00143 # define ACE_TEXT_CHAR_TO_TCHAR(STRING) STRING
00144 # define ACE_TEXT_WCHAR_TO_TCHAR(STRING) ACE_Wide_To_Ascii (STRING).char_rep ()
00145 # define ACE_TEXT_ANTI_TO_TCHAR(STRING) ACE_Wide_To_Ascii (STRING).char_rep ()
00146 #endif /* ACE_USES_WCHAR */
00147 
00148 // The OS_String module defines some wide-char functions that are not
00149 // universally available. In particular, they're not part of the
00150 // XPG4 Worldwide Portability Interface wide-character string handling
00151 // functions. So, if ACE_HAS_XPG4_MULTIBYTE_CHAR is defined, note that
00152 // these functions are missing.
00153 #if defined (ACE_HAS_XPG4_MULTIBYTE_CHAR)
00154 
00155 #  if !defined (ACE_LACKS_ITOW)
00156 #    define ACE_LACKS_ITOW
00157 #  endif
00158 
00159 #  if !defined (ACE_LACKS_WCSICMP)
00160 #    define ACE_LACKS_WCSICMP
00161 #  endif
00162 
00163 #  if !defined (ACE_LACKS_WCSNICMP)
00164 #    define ACE_LACKS_WCSNICMP
00165 #  endif
00166 
00167 #  if !defined (ACE_LACKS_WCSDUP)
00168 #    define ACE_LACKS_WCSDUP
00169 #  endif
00170 
00171 #endif /* ACE_HAS_XPG4_MULTIBYTE_CHAR */
00172 
00173 #if defined ACE_HAS_WCHAR
00174 
00175 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00176 
00177 /**
00178  * @class ACE_Wide_To_Ascii
00179  *
00180  * @brief A lightweight wchar* to char* string conversion class.
00181  *
00182  * The purpose of this class is to perform conversion from
00183  * wchar* to char* strings.  It is not intended for general
00184  * purpose use.
00185  */
00186 class ACE_Wide_To_Ascii
00187 {
00188 public:
00189   /// Ctor must take a wchar string.
00190   ACE_Wide_To_Ascii (const wchar_t *s);
00191 
00192   /// Dtor will free up the memory.
00193   ~ACE_Wide_To_Ascii (void);
00194 
00195   /// Return the internal char* representation.
00196   char *char_rep (void);
00197 
00198   /// Converts an wchar_t string to ascii and returns a new string.
00199   static char *convert (const wchar_t *wstr);
00200 
00201 private:
00202   /// Internal pointer to the converted string.
00203   char *s_;
00204 
00205 #if defined (ACE_HAS_ICONV)
00206   static iconv_t ACE_Wide_To_Ascii_iconv_env;
00207 #endif /* ACE_HAS_ICONV */
00208 
00209   /// Disallow these operation.
00210   ACE_Wide_To_Ascii (void);
00211   ACE_Wide_To_Ascii (ACE_Wide_To_Ascii &);
00212   ACE_Wide_To_Ascii& operator= (ACE_Wide_To_Ascii &);
00213 };
00214 
00215 /**
00216  * @class ACE_Ascii_To_Wide
00217  *
00218  * @brief A lightweight char* to wchar* string conversion class.
00219  *
00220  * The purpose of this class is to perform conversion from
00221  * char* to wchar* strings.  It is not intended for general
00222  * purpose use.
00223  */
00224 class ACE_Ascii_To_Wide
00225 {
00226 public:
00227   /// Ctor must take a wchar string.
00228   ACE_Ascii_To_Wide (const char *s);
00229 
00230   /// Dtor will free up the memory.
00231   ~ACE_Ascii_To_Wide (void);
00232 
00233   /// Return the internal wchar* representation.
00234   wchar_t *wchar_rep (void);
00235 
00236   /// Converts an char string to unicode/wide and returns a new string.
00237   static wchar_t *convert (const char *str);
00238 
00239 private:
00240   /// Internal pointer to the converted string.
00241   wchar_t *s_;
00242 
00243 #if defined (ACE_HAS_ICONV)
00244   static iconv_t ACE_Ascii_To_Wide_iconv_env;
00245 #endif /* ACE_HAS_ICONV */
00246 
00247   /// Disallow these operation.
00248   ACE_Ascii_To_Wide (void);
00249   ACE_Ascii_To_Wide (ACE_Ascii_To_Wide &);
00250   ACE_Ascii_To_Wide operator= (ACE_Ascii_To_Wide &);
00251 };
00252 
00253 #if defined (ACE_LEGACY_MODE)
00254 typedef ACE_Ascii_To_Wide ACE_OS_CString;
00255 typedef ACE_Wide_To_Ascii ACE_OS_WString;
00256 #endif /* ACE_LEGACY_MODE */
00257 
00258 ACE_END_VERSIONED_NAMESPACE_DECL
00259 
00260 #endif /* ACE_HAS_WCHAR */
00261 
00262 #if defined (ACE_WIN32)
00263 #if defined (ACE_USES_WCHAR)
00264 #define ACE_LPSTR                                LPWSTR
00265 #define ACE_TEXT_SERVICE_TABLE_ENTRY             SERVICE_TABLE_ENTRYW
00266 #define ACE_TEXT_STARTUPINFO                     STARTUPINFOW
00267 #define ACE_TEXT_WIN32_FIND_DATA                 WIN32_FIND_DATAW
00268 #define ACE_TEXT_OSVERSIONINFO                   OSVERSIONINFOW
00269 #define ACE_TEXT_EXPLICIT_ACCESS                 EXPLICIT_ACCESS_W
00270 
00271 #define ACE_TEXT_CreateEvent                     ::CreateEventW
00272 #define ACE_TEXT_CreateFile                      ::CreateFileW
00273 #define ACE_TEXT_CreateFileMapping               ::CreateFileMappingW
00274 #define ACE_TEXT_CreateMutex                     ::CreateMutexW
00275 #define ACE_TEXT_CreateProcess                   ::CreateProcessW
00276 #define ACE_TEXT_CreateSemaphore                 ::CreateSemaphoreW
00277 #define ACE_TEXT_CreateService                   ::CreateServiceW
00278 #define ACE_TEXT_ExpandEnvironmentStrings        ::ExpandEnvironmentStringsW
00279 #define ACE_TEXT_FindFirstChangeNotification     ::FindFirstChangeNotificationW
00280 #define ACE_TEXT_FindFirstFile                   ::FindFirstFileW
00281 #define ACE_TEXT_FindNextFile                    ::FindNextFileW
00282 #define ACE_TEXT_FormatMessage                   ::FormatMessageW
00283 #define ACE_TEXT_FreeEnvironmentStrings          ::FreeEnvironmentStringsW
00284 #define ACE_TEXT_GetComputerName                 ::GetComputerNameW
00285 #define ACE_TEXT_GetEnvironmentStrings           ::GetEnvironmentStringsW
00286 #define ACE_TEXT_GetFileAttributes               ::GetFileAttributesW
00287 #define ACE_TEXT_GetModuleFileName               ::GetModuleFileNameW
00288 #define ACE_TEXT_GetTempPath                     ::GetTempPathW
00289 #define ACE_TEXT_GetUserName                     ::GetUserNameW
00290 #define ACE_TEXT_GetUserNameEx                   ::GetUserNameExW
00291 #define ACE_TEXT_GetVersionEx                    ::GetVersionExW
00292 #define ACE_TEXT_LoadLibrary                     ::LoadLibraryW
00293 #define ACE_TEXT_MoveFileEx                      ::MoveFileExW
00294 #define ACE_TEXT_WaitNamedPipe                   ::WaitNamedPipeW
00295 #define ACE_TEXT_OpenFileMapping                 ::OpenFileMappingW
00296 #define ACE_TEXT_OpenSCManager                   ::OpenSCManagerW
00297 #define ACE_TEXT_OpenService                     ::OpenServiceW
00298 #define ACE_TEXT_OutputDebugString               ::OutputDebugStringW
00299 #define ACE_TEXT_RegisterEventSource             ::RegisterEventSourceW
00300 #define ACE_TEXT_RegisterServiceCtrlHandler      ::RegisterServiceCtrlHandlerW
00301 #define ACE_TEXT_RegConnectRegistry              ::RegConnectRegistryW
00302 #define ACE_TEXT_RegCreateKeyEx                  ::RegCreateKeyExW
00303 #define ACE_TEXT_RegDeleteKey                    ::RegDeleteKeyW
00304 #define ACE_TEXT_RegDeleteValue                  ::RegDeleteValueW
00305 #define ACE_TEXT_RegEnumKeyEx                    ::RegEnumKeyExW
00306 #define ACE_TEXT_RegEnumValue                    ::RegEnumValueW
00307 #define ACE_TEXT_RegCreateKey                    ::RegCreateKeyW
00308 #define ACE_TEXT_RegOpenKey                      ::RegOpenKeyW
00309 #define ACE_TEXT_RegOpenKeyEx                    ::RegOpenKeyExW
00310 #define ACE_TEXT_RegQueryValueEx                 ::RegQueryValueExW
00311 #define ACE_TEXT_RegSetValueEx                   ::RegSetValueExW
00312 #define ACE_TEXT_ReportEvent                     ::ReportEventW
00313 #define ACE_TEXT_SearchPath                      ::SearchPathW
00314 #define ACE_TEXT_StartService                    ::StartServiceW
00315 #define ACE_TEXT_StartServiceCtrlDispatcher      ::StartServiceCtrlDispatcherW
00316 #define ACE_TEXT_SetFileSecurity                 ::SetFileSecurityW
00317 #define ACE_TEXT_SetEntriesInAcl                 ::SetEntriesInAclW
00318 #define ACE_TEXT_PdhExpandCounterPath            ::PdhExpandCounterPathW
00319 #define ACE_TEXT_PdhOpenQuery                    ::PdhOpenQueryW
00320 #define ACE_TEXT_PdhAddCounter                   ::PdhAddCounterW
00321 
00322 #else /* ACE_USES_WCHAR */
00323 #define ACE_LPSTR                                LPSTR
00324 #define ACE_TEXT_SERVICE_TABLE_ENTRY             SERVICE_TABLE_ENTRYA
00325 #define ACE_TEXT_STARTUPINFO                     STARTUPINFOA
00326 #define ACE_TEXT_WIN32_FIND_DATA                 WIN32_FIND_DATAA
00327 #define ACE_TEXT_OSVERSIONINFO                   OSVERSIONINFOA
00328 #define ACE_TEXT_EXPLICIT_ACCESS                 EXPLICIT_ACCESS_A
00329 
00330 #define ACE_TEXT_CreateEvent                     ::CreateEventA
00331 #define ACE_TEXT_CreateFile                      ::CreateFileA
00332 #define ACE_TEXT_CreateFileMapping               ::CreateFileMappingA
00333 #define ACE_TEXT_CreateMutex                     ::CreateMutexA
00334 #define ACE_TEXT_CreateProcess                   ::CreateProcessA
00335 #define ACE_TEXT_CreateSemaphore                 ::CreateSemaphoreA
00336 #define ACE_TEXT_CreateService                   ::CreateServiceA
00337 #define ACE_TEXT_ExpandEnvironmentStrings        ::ExpandEnvironmentStringsA
00338 #define ACE_TEXT_FindFirstChangeNotification     ::FindFirstChangeNotificationA
00339 #define ACE_TEXT_FindFirstFile                   ::FindFirstFileA
00340 #define ACE_TEXT_FindNextFile                    ::FindNextFileA
00341 #define ACE_TEXT_FormatMessage                   ::FormatMessageA
00342 #define ACE_TEXT_FreeEnvironmentStrings          ::FreeEnvironmentStringsA
00343 #define ACE_TEXT_GetComputerName                 ::GetComputerNameA
00344 #define ACE_TEXT_GetEnvironmentStrings           ::GetEnvironmentStringsA
00345 #define ACE_TEXT_GetFileAttributes               ::GetFileAttributesA
00346 #define ACE_TEXT_GetModuleFileName               ::GetModuleFileNameA
00347 #define ACE_TEXT_GetTempPath                     ::GetTempPathA
00348 #define ACE_TEXT_GetUserName                     ::GetUserNameA
00349 #define ACE_TEXT_GetUserNameEx                   ::GetUserNameExA
00350 #define ACE_TEXT_GetVersionEx                    ::GetVersionExA
00351 #define ACE_TEXT_LoadLibrary                     ::LoadLibraryA
00352 #define ACE_TEXT_MoveFileEx                      ::MoveFileExA
00353 #define ACE_TEXT_WaitNamedPipe                   ::WaitNamedPipeA
00354 #define ACE_TEXT_OpenFileMapping                 ::OpenFileMappingA
00355 #define ACE_TEXT_OpenSCManager                   ::OpenSCManagerA
00356 #define ACE_TEXT_OpenService                     ::OpenServiceA
00357 #define ACE_TEXT_OutputDebugString               ::OutputDebugStringA
00358 #define ACE_TEXT_RegisterEventSource             ::RegisterEventSourceA
00359 #define ACE_TEXT_RegisterServiceCtrlHandler      ::RegisterServiceCtrlHandlerA
00360 #define ACE_TEXT_RegConnectRegistry              ::RegConnectRegistryA
00361 #define ACE_TEXT_RegCreateKeyEx                  ::RegCreateKeyExA
00362 #define ACE_TEXT_RegDeleteKey                    ::RegDeleteKeyA
00363 #define ACE_TEXT_RegDeleteValue                  ::RegDeleteValueA
00364 #define ACE_TEXT_RegEnumKeyEx                    ::RegEnumKeyExA
00365 #define ACE_TEXT_RegEnumValue                    ::RegEnumValueA
00366 #define ACE_TEXT_RegCreateKey                    ::RegCreateKeyA
00367 #define ACE_TEXT_RegOpenKey                      ::RegOpenKeyA
00368 #define ACE_TEXT_RegOpenKeyEx                    ::RegOpenKeyExA
00369 #define ACE_TEXT_RegQueryValueEx                 ::RegQueryValueExA
00370 #define ACE_TEXT_RegSetValueEx                   ::RegSetValueExA
00371 #define ACE_TEXT_ReportEvent                     ::ReportEventA
00372 #define ACE_TEXT_SearchPath                      ::SearchPathA
00373 #define ACE_TEXT_StartService                    ::StartServiceA
00374 #define ACE_TEXT_StartServiceCtrlDispatcher      ::StartServiceCtrlDispatcherA
00375 #define ACE_TEXT_SetFileSecurity                 ::SetFileSecurityA
00376 #define ACE_TEXT_SetEntriesInAcl                 ::SetEntriesInAclA
00377 #define ACE_TEXT_PdhExpandCounterPath            ::PdhExpandCounterPathA
00378 #define ACE_TEXT_PdhOpenQuery                    ::PdhOpenQueryA
00379 #define ACE_TEXT_PdhAddCounter                   ::PdhAddCounterA
00380 #endif /* ACE_USES_WCHAR */
00381 #endif /* ACE_WIN32 */
00382 
00383 #include "ace/ace_wchar.inl"
00384 
00385 #endif /* ACE_WCHAR_H */

Generated on Tue Feb 2 17:18:38 2010 for ACE by  doxygen 1.4.7