1 /*
2 * wxstring.h
3 *
4 * Adapter class for WX Widgets strings.
5 *
6 * Portable Tools Library
7 *
8 * Copyright (c) 2009 Vox Lucida
9 *
10 * The contents of this file are subject to the Mozilla Public License
11 * Version 1.0 (the "License"); you may not use this file except in
12 * compliance with the License. You may obtain a copy of the License at
13 * http://www.mozilla.org/MPL/
14 *
15 * Software distributed under the License is distributed on an "AS IS"
16 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17 * the License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * The Original Code is Portable Windows Library.
21 *
22 * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
23 *
24 * Contributor(s): ______________________________________.
25 *
26 * $Revision: 25648 $
27 * $Author: rjongbloed $
28 * $Date: 2011-05-01 20:19:23 -0500 (Sun, 01 May 2011) $
29 */
30
31 #ifndef PTLIB_WXSTRING_H
32 #define PTLIB_WXSTRING_H
33
34 #ifdef P_USE_PRAGMA
35 #pragma interface
36 #endif
37
38 /**This class defines a class to bridge WX Widgets strings to PTLib strings.
39 */
40 class PwxString : public wxString
41 {
42 public:
PwxString()43 PwxString() { }
PwxString(const wxString & str)44 PwxString(const wxString & str) : wxString(str) { }
PwxString(const PString & str)45 PwxString(const PString & str) : wxString((const char *)str, wxConvUTF8 ) { }
PwxString(const PFilePath & fn)46 PwxString(const PFilePath & fn) : wxString((const char *)fn, wxConvUTF8 ) { }
PwxString(const char * str)47 PwxString(const char * str) : wxString(str, wxConvUTF8) { }
48 #ifdef OPAL_OPAL_MEDIAFMT_H
PwxString(const OpalMediaFormat & fmt)49 PwxString(const OpalMediaFormat & fmt) : wxString((const char *)fmt.GetName(), wxConvUTF8) { }
50 #endif
51 #if wxUSE_UNICODE
PwxString(const wchar_t * wstr)52 PwxString(const wchar_t * wstr) : wxString(wstr) { }
53 #endif
54
55 inline PwxString & operator=(const char * str) { *this = wxString(str, wxConvUTF8); return *this; }
56 #if wxUSE_UNICODE
57 inline PwxString & operator=(const wchar_t * wstr) { wxString::operator=(wstr); return *this; }
58 #endif
59 inline PwxString & operator=(const wxString & str) { wxString::operator=(str); return *this; }
60 inline PwxString & operator=(const PString & str) { *this = wxString((const char *)str, wxConvUTF8); return *this; }
61
62 inline bool operator==(const char * other) const { return IsSameAs(wxString(other, wxConvUTF8)); }
63 #if wxUSE_UNICODE
64 inline bool operator==(const wchar_t * other) const { return IsSameAs(other); }
65 #endif
66 inline bool operator==(const wxString & other) const { return IsSameAs(other); }
67 inline bool operator==(const PString & other) const { return IsSameAs(wxString((const char *)other, wxConvUTF8)); }
68 inline bool operator==(const PwxString & other) const { return IsSameAs(other); }
69 #ifdef OPAL_OPAL_MEDIAFMT_H
70 inline bool operator==(const OpalMediaFormat & other) const { return IsSameAs(wxString((const char *)other.GetName(), wxConvUTF8)); }
71 #endif
72
73 inline bool operator!=(const char * other) const { return !IsSameAs(wxString(other, wxConvUTF8)); }
74 #if wxUSE_UNICODE
75 inline bool operator!=(const wchar_t * other) const { return !IsSameAs(other); }
76 #endif
77 inline bool operator!=(const wxString & other) const { return !IsSameAs(other); }
78 inline bool operator!=(const PString & other) const { return !IsSameAs(wxString((const char *)other, wxConvUTF8)); }
79 inline bool operator!=(const PwxString & other) const { return !IsSameAs(other); }
80 #ifdef OPAL_OPAL_MEDIAFMT_H
81 inline bool operator!=(const OpalMediaFormat & other) const { return !IsSameAs(wxString((const char *)other.GetName(), wxConvUTF8)); }
82 #endif
83
84 #if wxUSE_UNICODE
p_str()85 inline PString p_str() const { return ToUTF8().data(); }
PString()86 inline operator PString() const { return ToUTF8().data(); }
PFilePath()87 inline operator PFilePath() const { return ToUTF8().data(); }
88 #if defined(PTLIB_PURL_H) && defined(P_URL)
PURL()89 inline operator PURL() const { return ToUTF8().data(); }
90 #endif
91 #if defined(PTLIB_IPSOCKET_H)
Address()92 inline operator PIPSocket::Address() const { return PString(ToUTF8().data()); }
93 #endif
94 inline friend ostream & operator<<(ostream & stream, const PwxString & string) { return stream << string.ToUTF8(); }
95 inline friend wostream & operator<<(wostream & stream, const PwxString & string) { return stream << string.c_str(); }
96 #else
p_str()97 inline PString p_str() const { return c_str(); }
PString()98 inline operator PString() const { return c_str(); }
PFilePath()99 inline operator PFilePath() const { return c_str(); }
100 #if defined(PTLIB_PURL_H) && defined(P_URL)
PURL()101 inline operator PURL() const { return c_str(); }
102 #endif
103 #if defined(PTLIB_IPSOCKET_H)
Address()104 inline operator PIPSocket::Address() const { return c_str(); }
105 #endif
106 inline friend ostream & operator<<(ostream & stream, const PwxString & string) { return stream << string.c_str(); }
107 inline friend wostream & operator<<(wostream & stream, const PwxString & string) { return stream << string.c_str(); }
108 #endif
109 };
110
wxFromString(wxString & s1,PwxString * & s2)111 __inline bool wxFromString(wxString & s1, PwxString * & s2) { *s2 = s1; return true; }
wxToString(const PwxString & str)112 __inline wxString wxToString(const PwxString & str) { return str; }
113
114 #endif // PTLIB_WXSTRING_H
115
116
117 // End Of File ///////////////////////////////////////////////////////////////
118