first check-in of feisty meow codebase. many things broken still due to recent
[feisty_meow.git] / core / 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     #ifndef __MINGW32__
24       #define _WINSOCKAPI_  // the dance of the windows headers.
25       #include <windows.h>
26       #include <comdef.h>
27     #endif
28   #endif
29 #endif
30
31 // forward.
32 class _bstr_t;  // ATL (Active Template Library) string type.
33
34 //! A collection of conversions between popular string types.
35
36 namespace string_convert
37 {
38
39 #ifdef _AFXDLL
40   //! conversion from MFC CString to astring.
41   inline astring to_astring(const CString &original)
42   { return astring(from_unicode_temp(original)); }
43
44   //! conversion from astring to MFC CString.
45   inline CString to_CString(const astring &original)
46   { return CString(to_unicode_temp(original)); }
47 #endif
48
49 #ifdef WIN32
50  #ifndef _MANAGED
51    #ifndef __MINGW32__
52     //! conversion from ATL's _bstr_t object to astring.
53     inline basis::astring to_astring(const _bstr_t &original) {
54        return basis::astring(basis::astring::UNTERMINATED, (const char *)original,
55           original.length());
56     }
57
58     //! conversion from astring to the ATL _bstr_t object.
59     inline _bstr_t to_bstr_t(const basis::astring &original)
60     { return _bstr_t(original.s()); }
61    #endif
62  #endif
63 #endif
64
65 //other conversions.
66
67 } //namespace
68
69 #endif
70