replace changes of r49890 by defining more compatibility operators in wxCmdLineArgsArray as we're interested in preserving as much compatibility with the existing code outside of the library as possible; also DLL-export the class to avoid VC6 DLL build warnings

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@49902 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2007-11-13 13:27:30 +00:00
parent c8ddadff84
commit d154ab3d29
3 changed files with 23 additions and 6 deletions

View File

@@ -26,7 +26,7 @@
// as it's used for compatibility, it tries to look as much as traditional // as it's used for compatibility, it tries to look as much as traditional
// (char **) argv as possible, in particular it provides implicit conversions // (char **) argv as possible, in particular it provides implicit conversions
// to "char **" and also array-like operator[] // to "char **" and also array-like operator[]
class wxCmdLineArgsArray class WXDLLIMPEXP_BASE wxCmdLineArgsArray
{ {
public: public:
wxCmdLineArgsArray() { m_argsA = NULL; m_argsW = NULL; } wxCmdLineArgsArray() { m_argsA = NULL; m_argsW = NULL; }
@@ -80,6 +80,12 @@ public:
return !m_args.empty(); return !m_args.empty();
} }
// and the same for "if ( !argv )" checks
bool operator!() const
{
return m_args.empty();
}
wxString operator[](size_t n) const wxString operator[](size_t n) const
{ {
return m_args[n]; return m_args[n];
@@ -92,9 +98,13 @@ public:
return m_args[n]; return m_args[n];
} }
// this is the only method of this class which doesn't exist solely for
// compatibility purposes: it allows to access the arguments as a // convenience methods, i.e. not existing only for backwards compatibility
// convenient array of wxStrings
// do we have any arguments at all?
bool IsEmpty() const { return m_args.empty(); }
// access the arguments as a convenient array of wxStrings
const wxArrayString& GetArguments() const { return m_args; } const wxArrayString& GetArguments() const { return m_args; }
~wxCmdLineArgsArray() ~wxCmdLineArgsArray()
@@ -129,6 +139,13 @@ private:
DECLARE_NO_COPY_CLASS(wxCmdLineArgsArray) DECLARE_NO_COPY_CLASS(wxCmdLineArgsArray)
}; };
// provide global operator overload for compatibility with the existing code
// doing things like "if ( condition && argv )"
inline operator&&(bool cond, const wxCmdLineArgsArray& array)
{
return cond && !array.IsEmpty();
}
#endif // wxUSE_UNICODE #endif // wxUSE_UNICODE
#endif // _WX_CMDARGS_H_ #endif // _WX_CMDARGS_H_

View File

@@ -177,7 +177,7 @@ bool wxAppConsoleBase::Initialize(int& argcOrig, wxChar **argvOrig)
#endif #endif
#ifndef __WXPALMOS__ #ifndef __WXPALMOS__
if ( m_appName.empty() && (bool) argv ) if ( m_appName.empty() && argv )
{ {
// the application name is, by default, the name of its executable file // the application name is, by default, the name of its executable file
wxFileName::SplitPath(argv[0], NULL, &m_appName, NULL); wxFileName::SplitPath(argv[0], NULL, &m_appName, NULL);

View File

@@ -53,7 +53,7 @@ wxStandardPathsBase& wxStandardPathsBase::Get()
wxString wxStandardPathsBase::GetExecutablePath() const wxString wxStandardPathsBase::GetExecutablePath() const
{ {
if ( !wxTheApp || ! (bool) wxTheApp->argv ) if ( !wxTheApp || !wxTheApp->argv )
return wxEmptyString; return wxEmptyString;
wxString argv0 = wxTheApp->argv[0]; wxString argv0 = wxTheApp->argv[0];