lmi
[Top][All Lists]
Advanced

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

Re[2]: [lmi] trivial patch: don't use deprecated GetPrintableName()


From: Vadim Zeitlin
Subject: Re[2]: [lmi] trivial patch: don't use deprecated GetPrintableName()
Date: Sun, 11 May 2008 05:34:45 +0200

On Sun, 11 May 2008 02:38:12 +0000 Greg Chicares <address@hidden> wrote:

GC> Shouldn't we add 'c_str()', e.g.:
GC>   std::string S(some_document.GetUserReadableName().c_str());
GC> ?

 No, this is not necessary.

GC> Paraphrasing an off-list email you sent me 2008-01-29T14:24Z,
GC> this is always okay:
GC>   std::string S("STD");
GC>   wxString W(S);
GC> but c_str() is preferred here:
GC>   wxString W("WX");
GC>   std::string S(W.c_str());
GC> or else we're restricted to a wxUSE_STL build--and, IIRC, that
GC> was an issue for you because you maintain so many builds.

 Sorry for the confusion, AFAIR in this mail I spoke about the problem with
the code like this:

        std::string S = W;

or maybe with code like this:

        extern void foo(const std::string& s);

        foo(W);

Neither of these snippets compiles without wxUSE_STL or, at least,
wxUSE_STD_STRING (which became default in the current wx svn trunk BTW).
But the code here:

        std::string S(W);

is different and does compile because wxString is implicitly convertible to
"const char *" and std::string has a ctor from it. The first version above
is very similar to the last one but not quite the same: it would require 2
user-defined conversions to compile and this is, of course, forbidden in
C++.

GC> but doesn't the revised documentation:
GC> 
GC>   
http://www.lpthe.jussieu.fr/~zeitlin/wxWidgets/docs/wxwin_wxdocument.html#wxdocumentgetuserreadablentablename
GC> | The default implementation uses the document title, if any,
GC> | of the name part of the document filename if it was set or,
GC> | otherwise, the string unnamed.
GC> 
GC> guarantee that a nonempty string will be returned, so that we
GC> can eliminate that clause?

 Indeed, we can, sorry for not thinking about this.

GC> >  And I also should have probably mentioned in my previous email that I'm
GC> > going to submit a slightly less trivial patch fixing a similar problem 
with
GC> > MakeDefaultName() very soon so if you prefer to apply both of them at once
GC> > you should wait for it.
GC> 
GC> I was about to ask whether you had a replacement for that
GC> function, too.

 Unfortunately this patch was delayed but hopefully I should have it
tomorrow...

GC> Aside from that, the only other place where lmi
GC> seems to default-construct a local wxString in order to pass it
GC> by non-const reference to a library function is with
GC>   wxFileType::GetOpenCommand()
GC>   wxFileType::GetPrintCommand()
GC> where I guess there really is a reason for returning bool and
GC> passing the string by reference, so that doesn't trouble me.

 Yes, these functions can (and indeed actually do) fail.
VZ





reply via email to

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