]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/cmdargs.h
1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: declaration of wxCmdLineArgsArray helper class
4 // Author: Vadim Zeitlin
7 // Copyright: (c) 2007 Vadim Zeitlin <vadim@wxwindows.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_CMDARGS_H_
12 #define _WX_CMDARGS_H_
14 #include "wx/arrstr.h"
16 // ----------------------------------------------------------------------------
17 // wxCmdLineArgsArray: helper class used by wxApp::argv
18 // ----------------------------------------------------------------------------
22 // this class is used instead of either "char **" or "wchar_t **" (neither of
23 // which would be backwards compatible with all the existing code) for argv
26 // as it's used for compatibility, it tries to look as much as traditional
27 // (char **) argv as possible, in particular it provides implicit conversions
28 // to "char **" and also array-like operator[]
29 class wxCmdLineArgsArray
32 wxCmdLineArgsArray() { m_argsA
= NULL
; m_argsW
= NULL
; }
35 wxCmdLineArgsArray
& operator=(T
**argv
)
44 m_args
.push_back(*argv
++);
50 operator char**() const
54 const size_t count
= m_args
.size();
55 m_argsA
= new char *[count
];
56 for ( size_t n
= 0; n
< count
; n
++ )
57 m_argsA
[n
] = wxStrdup(m_args
[n
].ToAscii());
63 operator wchar_t**() const
67 const size_t count
= m_args
.size();
68 m_argsW
= new wchar_t *[count
];
69 for ( size_t n
= 0; n
< count
; n
++ )
70 m_argsW
[n
] = wxStrdup(m_args
[n
].wc_str());
76 // existing code does checks like "if ( argv )" and we want it to continue
77 // to compile, so provide this conversion even if it is pretty dangerous
80 return !m_args
.empty();
83 wxString
operator[](size_t n
) const
88 // we must provide this overload for g++ 3.4 which can't choose between
89 // our operator[](size_t) and ::operator[](char**, int) otherwise
90 wxString
operator[](int n
) const
95 // this is the only method of this class which doesn't exist solely for
96 // compatibility purposes: it allows to access the arguments as a
97 // convenient array of wxStrings
98 const wxArrayString
& GetArguments() const { return m_args
; }
100 ~wxCmdLineArgsArray()
106 template <typename T
>
112 const size_t count
= m_args
.size();
113 for ( size_t n
= 0; n
< count
; n
++ )
125 wxArrayString m_args
;
126 mutable char **m_argsA
;
127 mutable wchar_t **m_argsW
;
129 DECLARE_NO_COPY_CLASS(wxCmdLineArgsArray
)
132 #endif // wxUSE_UNICODE
134 #endif // _WX_CMDARGS_H_