PTLib  Version 2.18.8
 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  */
27 
28 #ifndef PTLIB_WXSTRING_H
29 #define PTLIB_WXSTRING_H
30 
31 
34 class PwxString : public wxString
35 {
36  public:
37  PwxString() { }
38  PwxString(const wxString & str) : wxString(str) { }
39  PwxString(const char * str) : wxString( str, wxConvUTF8) { }
40  PwxString(const PString & str) : wxString((const char *)str, wxConvUTF8) { }
41  PwxString(const PFilePath & fn) : wxString((const char *)fn, wxConvUTF8) { }
42 #ifdef OPAL_OPAL_MEDIAFMT_H
43  PwxString(const OpalMediaFormat & fmt) : wxString((const char *)fmt.GetName(), wxConvUTF8) { }
44 #endif
45 #if wxUSE_UNICODE
46  PwxString(const wchar_t * wstr) : wxString(wstr) { }
47 #endif
48 
49  inline PwxString & operator=(const char * str) { *this = wxString(str, wxConvUTF8); return *this; }
50 #if wxUSE_UNICODE
51  inline PwxString & operator=(const wchar_t * wstr) { wxString::operator=(wstr); return *this; }
52 #endif
53  inline PwxString & operator=(const wxString & str) { wxString::operator=(str); return *this; }
54  inline PwxString & operator=(const PString & str) { *this = wxString((const char *)str, wxConvUTF8); return *this; }
55 
56  inline bool operator==(const char * other) const { return IsSameAs(wxString(other, wxConvUTF8)); }
57 #if wxUSE_UNICODE
58  inline bool operator==(const wchar_t * other) const { return IsSameAs(other); }
59 #endif
60  inline bool operator==(const wxString & other) const { return IsSameAs(other); }
61  inline bool operator==(const PString & other) const { return IsSameAs(wxString((const char *)other, wxConvUTF8)); }
62  inline bool operator==(const PwxString & other) const { return IsSameAs(other); }
63 #ifdef OPAL_OPAL_MEDIAFMT_H
64  inline bool operator==(const OpalMediaFormat & other) const { return IsSameAs(wxString((const char *)other.GetName(), wxConvUTF8)); }
65 #endif
66 
67  inline bool operator!=(const char * other) const { return !IsSameAs(wxString(other, wxConvUTF8)); }
68 #if wxUSE_UNICODE
69  inline bool operator!=(const wchar_t * other) const { return !IsSameAs(other); }
70 #endif
71  inline bool operator!=(const wxString & other) const { return !IsSameAs(other); }
72  inline bool operator!=(const PString & other) const { return !IsSameAs(wxString((const char *)other, wxConvUTF8)); }
73  inline bool operator!=(const PwxString & other) const { return !IsSameAs(other); }
74 #ifdef OPAL_OPAL_MEDIAFMT_H
75  inline bool operator!=(const OpalMediaFormat & other) const { return !IsSameAs(wxString((const char *)other.GetName(), wxConvUTF8)); }
76 #endif
77 
78 #if wxUSE_UNICODE
79  inline PString p_str() const { return ToUTF8().data(); }
80  inline operator PString() const { return ToUTF8().data(); }
81  inline operator PCaselessString() const { return ToUTF8().data(); }
82  inline operator PFilePath() const { return ToUTF8().data(); }
83 #if defined(PTLIB_PURL_H) && defined(P_URL)
84  inline operator PURL() const { return ToUTF8().data(); }
85 #endif
86 #if defined(PTLIB_IPSOCKET_H)
87  inline operator PIPSocket::Address() const { return PIPSocket::Address(PString(ToUTF8().data())); }
88 #endif
89  inline friend ostream & operator<<(ostream & stream, const PwxString & string) { return stream << string.ToUTF8(); }
90  inline friend wostream & operator<<(wostream & stream, const PwxString & string) { return stream << string.c_str(); }
91 #else
92  inline PString p_str() const { return c_str(); }
93  inline operator PString() const { return c_str(); }
94  inline operator PCaselessString() const { return c_str(); }
95  inline operator PFilePath() const { return c_str(); }
96 #if defined(PTLIB_PURL_H) && defined(P_URL)
97  inline operator PURL() const { return c_str(); }
98 #endif
99 #if defined(PTLIB_IPSOCKET_H)
100  inline operator PIPSocket::Address() const { return c_str(); }
101 #endif
102  inline friend ostream & operator<<(ostream & stream, const PwxString & string) { return stream << string.c_str(); }
103  inline friend wostream & operator<<(wostream & stream, const PwxString & string) { return stream << string.c_str(); }
104 #endif
105 
106 #if !wxCHECK_VERSION(2,9,2)
107  PwxString & operator<<(const char * str) { *this += wxString( str, wxConvUTF8); return *this; }
108  PwxString & operator<<(const PString & str) { *this += wxString((const char *)str, wxConvUTF8); return *this; }
109 #endif
110 };
111 
112 __inline bool wxFromString(wxString & s1, PwxString * & s2) { *s2 = s1; return true; }
113 __inline wxString wxToString(const PwxString & str) { return str; }
114 
115 #endif // PTLIB_WXSTRING_H
116 
117 
118 // End Of File ///////////////////////////////////////////////////////////////
This class defines a class to bridge WX Widgets strings to PTLib strings.
Definition: wxstring.h:34
PwxString & operator<<(const char *str)
Definition: wxstring.h:107
__inline char * data()
Definition: pstring.h:1888
PString p_str() const
Definition: wxstring.h:92
PwxString(const PFilePath &fn)
Definition: wxstring.h:41
PwxString & operator=(const wxString &str)
Definition: wxstring.h:53
PwxString(const wxString &str)
Definition: wxstring.h:38
bool operator==(const PwxString &other) const
Definition: wxstring.h:62
This class describes a full description for a file on the particular platform.
Definition: filepath.h:61
PwxString & operator<<(const PString &str)
Definition: wxstring.h:108
bool operator!=(const PString &other) const
Definition: wxstring.h:72
PwxString & operator=(const char *str)
Definition: wxstring.h:49
This class is a variation of a string that ignores case.
Definition: pstring.h:2012
bool operator!=(const wxString &other) const
Definition: wxstring.h:71
bool operator==(const wxString &other) const
Definition: wxstring.h:60
bool operator!=(const char *other) const
Definition: wxstring.h:67
PwxString(const char *str)
Definition: wxstring.h:39
bool operator!=(const PwxString &other) const
Definition: wxstring.h:73
friend ostream & operator<<(ostream &stream, const PwxString &string)
Definition: wxstring.h:102
__inline wxString wxToString(const PwxString &str)
Definition: wxstring.h:113
PwxString & operator=(const PString &str)
Definition: wxstring.h:54
__inline bool wxFromString(wxString &s1, PwxString *&s2)
Definition: wxstring.h:112
PwxString(const PString &str)
Definition: wxstring.h:40
The character string class.
Definition: pstring.h:108
friend wostream & operator<<(wostream &stream, const PwxString &string)
Definition: wxstring.h:103
bool operator==(const PString &other) const
Definition: wxstring.h:61
A class describing an IP address.
Definition: ipsock.h:59
PwxString()
Definition: wxstring.h:37
This class describes a Universal Resource Locator.
Definition: url.h:56
bool operator==(const char *other) const
Definition: wxstring.h:56