Merge branch 'release-2.140.101'
[feisty_meow.git] / nucleus / library / textual / string_convert.h
1 #ifndef STRING_CONVERSION_GROUP
2 #define STRING_CONVERSION_GROUP
3
4 /*****************************************************************************\
5 *                                                                             *
6 *  Name   : string_convert                                                    *
7 *  Author : Chris Koeritz                                                     *
8 *                                                                             *
9 *******************************************************************************
10 * Copyright (c) 2007-$now By Author.  This program is free software; you can  *
11 * redistribute it and/or modify it under the terms of the GNU General Public  *
12 * License as published by the Free Software Foundation; either version 2 of   *
13 * the License or (at your option) any later version.  This is online at:      *
14 *     http://www.fsf.org/copyleft/gpl.html                                    *
15 * Please send any updates to: fred@gruntose.com                               *
16 \*****************************************************************************/
17
18 #include <basis/astring.h>
19 #include <basis/utf_conversion.h>
20
21 #ifdef __WIN32__
22   #ifndef _MANAGED
23       #define _WINSOCKAPI_  // the dance of the windows headers.
24   // winsock support...
25 //  #undef FD_SETSIZE
26 //  #define FD_SETSIZE 1000
27     // if you don't set this, you can only select on a default of 64 sockets.
28   #include <winsock2.h>
29   #include <windows.h>
30   #ifndef __GNU_WINDOWS__
31     #include <comdef.h>
32   #endif
33   #endif
34 #endif
35
36 // forward.
37 class _bstr_t;  // ATL (Active Template Library) string type.
38
39 //! A collection of conversions between popular string types.
40
41 namespace string_convert
42 {
43
44 #ifdef _AFXDLL
45   //! conversion from MFC CString to astring.
46   inline astring to_astring(const CString &original)
47   { return astring(from_unicode_temp(original)); }
48
49   //! conversion from astring to MFC CString.
50   inline CString to_CString(const astring &original)
51   { return CString(to_unicode_temp(original)); }
52 #endif
53
54 #ifdef WIN32
55  #ifndef _MANAGED
56   #ifndef __GNU_WINDOWS__
57     //! conversion from ATL's _bstr_t object to astring.
58     inline basis::astring to_astring(const _bstr_t &original) {
59        return basis::astring(basis::astring::UNTERMINATED, (const char *)original,
60           original.length());
61     }
62
63     //! conversion from astring to the ATL _bstr_t object.
64     inline _bstr_t to_bstr_t(const basis::astring &original)
65     { return _bstr_t(original.s()); }
66   #endif
67  #endif
68 #endif
69
70 //other conversions.
71
72 } //namespace
73
74 #endif
75