lmi
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi] patch: compilation fix for wx 2.9


From: Vadim Zeitlin
Subject: [lmi] patch: compilation fix for wx 2.9
Date: Wed, 30 Dec 2009 00:43:33 +0100

 Hello,

 I'd like to discuss the following simple patch:

--- a/mec_document.cpp
+++ b/mec_document.cpp
@@ -69,7 +69,7 @@ bool mec_document::OnCreate(wxString const& filename, long 
int flags)
         }
     else
         {
-        std::ifstream ifs(filename.c_str());
+        std::ifstream ifs(filename.wc_str());
         if(!ifs)
             {
             warning()
@@ -118,7 +118,7 @@ bool mec_document::DoOpenDocument(wxString const& filename)

 bool mec_document::DoSaveDocument(wxString const& filename)
 {
-    std::ofstream ofs(filename.c_str(), ios_out_trunc_binary());
+    std::ofstream ofs(filename.wc_str(), ios_out_trunc_binary());
     doc_.write(ofs);
     if(!ofs)
         {

It fixes compilation of this code with wxWidgets 2.9 as without it an
ambiguity arises when passing wxCStrData, which is the proxy object
convertible to both "const char*" and "const wchar_t*" returned by
wxString::c_str(), to std::ifstream ctor which is overloaded for both
narrow and wide string types.

 Because of this we need to explicitly choose the version to use. I
selected the wide character one because even if LMI deals with ASCII only
internally the file name might come from outside and a user might use a
non-ASCII character in a file name and if we chose to use
wxString::mb_str() instead of wc_str() here the conversion would fail and
opening the stream would fail as well without any obvious reason (the error
message would complain about the real file name but the name passed to
ifstream would be empty). Using wc_str() is safe and ensures that we never
lose any data so hopefully an exception could be made from general LMI
ANSI-only mindset.

 Please let me know what do you think about this, thanks,
VZ

reply via email to

[Prev in Thread] Current Thread [Next in Thread]