X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/541ea80f0ec8a1250981bfaa3452f370e5c42c3b..f54e5c1a4f6952c62ed4480f7d26feddc20f98ba:/include/wx/cmdargs.h?ds=sidebyside diff --git a/include/wx/cmdargs.h b/include/wx/cmdargs.h index 57b22b42e5..a120c45870 100644 --- a/include/wx/cmdargs.h +++ b/include/wx/cmdargs.h @@ -26,7 +26,7 @@ // as it's used for compatibility, it tries to look as much as traditional // (char **) argv as possible, in particular it provides implicit conversions // to "char **" and also array-like operator[] -class wxCmdLineArgsArray +class WXDLLIMPEXP_BASE wxCmdLineArgsArray { public: wxCmdLineArgsArray() { m_argsA = NULL; m_argsW = NULL; } @@ -80,14 +80,31 @@ public: return !m_args.empty(); } + // and the same for "if ( !argv )" checks + bool operator!() const + { + return m_args.empty(); + } + wxString operator[](size_t n) const { 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 - // convenient array of wxStrings + // we must provide this overload for g++ 3.4 which can't choose between + // our operator[](size_t) and ::operator[](char**, int) otherwise + wxString operator[](int n) const + { + return m_args[n]; + } + + + // convenience methods, i.e. not existing only for backwards compatibility + + // 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; } ~wxCmdLineArgsArray() @@ -122,6 +139,13 @@ private: DECLARE_NO_COPY_CLASS(wxCmdLineArgsArray) }; +// provide global operator overload for compatibility with the existing code +// doing things like "if ( condition && argv )" +inline bool operator&&(bool cond, const wxCmdLineArgsArray& array) +{ + return cond && !array.IsEmpty(); +} + #endif // wxUSE_UNICODE #endif // _WX_CMDARGS_H_