PTLib  Version 2.14.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
wxstring.h
Go to the documentation of this file.
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: 31310 $
27  * $Author: rjongbloed $
28  * $Date: 2014-01-29 21:27:09 +1100 (Wed, 29 Jan 2014) $
29  */
30 
31 #ifndef PTLIB_WXSTRING_H
32 #define PTLIB_WXSTRING_H
33 
34 
37 class PwxString : public wxString
38 {
39  public:
40  PwxString() { }
41  PwxString(const wxString & str) : wxString(str) { }
42  PwxString(const char * str) : wxString( str, wxConvUTF8) { }
43  PwxString(const PString & str) : wxString((const char *)str, wxConvUTF8) { }
44  PwxString(const PFilePath & fn) : wxString((const char *)fn, wxConvUTF8) { }
45 #ifdef OPAL_OPAL_MEDIAFMT_H
46  PwxString(const OpalMediaFormat & fmt) : wxString((const char *)fmt.GetName(), wxConvUTF8) { }
47 #endif
48 #if wxUSE_UNICODE
49  PwxString(const wchar_t * wstr) : wxString(wstr) { }
50 #endif
51 
52  inline PwxString & operator=(const char * str) { *this = wxString(str, wxConvUTF8); return *this; }
53 #if wxUSE_UNICODE
54  inline PwxString & operator=(const wchar_t * wstr) { wxString::operator=(wstr); return *this; }
55 #endif
56  inline PwxString & operator=(const wxString & str) { wxString::operator=(str); return *this; }
57  inline PwxString & operator=(const PString & str) { *this = wxString((const char *)str, wxConvUTF8); return *this; }
58 
59  inline bool operator==(const char * other) const { return IsSameAs(wxString(other, wxConvUTF8)); }
60 #if wxUSE_UNICODE
61  inline bool operator==(const wchar_t * other) const { return IsSameAs(other); }
62 #endif
63  inline bool operator==(const wxString & other) const { return IsSameAs(other); }
64  inline bool operator==(const PString & other) const { return IsSameAs(wxString((const char *)other, wxConvUTF8)); }
65  inline bool operator==(const PwxString & other) const { return IsSameAs(other); }
66 #ifdef OPAL_OPAL_MEDIAFMT_H
67  inline bool operator==(const OpalMediaFormat & other) const { return IsSameAs(wxString((const char *)other.GetName(), wxConvUTF8)); }
68 #endif
69 
70  inline bool operator!=(const char * other) const { return !IsSameAs(wxString(other, wxConvUTF8)); }
71 #if wxUSE_UNICODE
72  inline bool operator!=(const wchar_t * other) const { return !IsSameAs(other); }
73 #endif
74  inline bool operator!=(const wxString & other) const { return !IsSameAs(other); }
75  inline bool operator!=(const PString & other) const { return !IsSameAs(wxString((const char *)other, wxConvUTF8)); }
76  inline bool operator!=(const PwxString & other) const { return !IsSameAs(other); }
77 #ifdef OPAL_OPAL_MEDIAFMT_H
78  inline bool operator!=(const OpalMediaFormat & other) const { return !IsSameAs(wxString((const char *)other.GetName(), wxConvUTF8)); }
79 #endif
80 
81 #if wxUSE_UNICODE
82  inline PString p_str() const { return ToUTF8().data(); }
83  inline operator PString() const { return ToUTF8().data(); }
84  inline operator PCaselessString() const { return ToUTF8().data(); }
85  inline operator PFilePath() const { return ToUTF8().data(); }
86 #if defined(PTLIB_PURL_H) && defined(P_URL)
87  inline operator PURL() const { return ToUTF8().data(); }
88 #endif
89 #if defined(PTLIB_IPSOCKET_H)
90  inline operator PIPSocket::Address() const { return PIPSocket::Address(PString(ToUTF8().data())); }
91 #endif
92  inline friend ostream & operator<<(ostream & stream, const PwxString & string) { return stream << string.ToUTF8(); }
93  inline friend wostream & operator<<(wostream & stream, const PwxString & string) { return stream << string.c_str(); }
94 #else
95  inline PString p_str() const { return c_str(); }
96  inline operator PString() const { return c_str(); }
97  inline operator PCaselessString() const { return c_str(); }
98  inline operator PFilePath() const { return c_str(); }
99 #if defined(PTLIB_PURL_H) && defined(P_URL)
100  inline operator PURL() const { return c_str(); }
101 #endif
102 #if defined(PTLIB_IPSOCKET_H)
103  inline operator PIPSocket::Address() const { return c_str(); }
104 #endif
105  inline friend ostream & operator<<(ostream & stream, const PwxString & string) { return stream << string.c_str(); }
106  inline friend wostream & operator<<(wostream & stream, const PwxString & string) { return stream << string.c_str(); }
107 #endif
108 
109 #if !wxCHECK_VERSION(2,9,2)
110  PwxString & operator<<(const char * str) { *this += wxString( str, wxConvUTF8); return *this; }
111  PwxString & operator<<(const PString & str) { *this += wxString((const char *)str, wxConvUTF8); return *this; }
112 #endif
113 };
114 
115 __inline bool wxFromString(wxString & s1, PwxString * & s2) { *s2 = s1; return true; }
116 __inline wxString wxToString(const PwxString & str) { return str; }
117 
118 #endif // PTLIB_WXSTRING_H
119 
120 
121 // End Of File ///////////////////////////////////////////////////////////////