Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef ArgumentParserH
00033 #define ArgumentParserH
00034
00035 #include <zeusbase/System/ZObject.h>
00036 #include <zeusbase/System/StringMap.hpp>
00037 #include <zeusbase/System/StringList.h>
00038
00039 BEGIN_NAMESPACE_Zeus
00040
00041
00045
00046 zeusbase_class TArgumentParser : public TZObject
00047 {
00048 public:
00049 TArgumentParser();
00050 TArgumentParser(Int iArgC, char* apArgs[]);
00051 TArgumentParser(Int iArgC, wchar_t* awcArgs[]);
00052 TArgumentParser(const TString& rInParams, bool bNativeCommandLine = false);
00053 TArgumentParser(const IString& rInParams, bool bNativeCommandLine = false);
00054
00055 bool hasArgument(const IString& rArgName) const;
00056 bool hasArgument(const wchar_t* pArgName) const;
00057 bool hasArgumentWithValue(const IString& rArgName) const;
00058 bool hasArgumentWithValue(const wchar_t* pArgName) const;
00059 TString getArgumentValue(const IString& rArgName) const;
00060 TString getArgumentValue(const wchar_t* pArgName) const;
00061 TString getArgumentValueByIndex(Int iIndex) const;
00062 TString getFirstArgument() const;
00063 TString getLastArgument() const;
00064 Int getArgumentCount() const;
00065 TString getApplicationFile() const;
00066 TString getApplicationMainPath() const;
00067 void setApplicationFileName(const IString& rFileName);
00068
00069 void resetList();
00070 TString getNextItem() const;
00071 bool hasNextItem() const;
00072
00073 protected:
00074 virtual ~TArgumentParser();
00075
00077 TStringMap<TString> m_mapItems;
00079 TStringList m_lstItems;
00081 TString m_strFileName;
00082
00083 private:
00085 const IStringListIterator* m_pListIterator;
00086
00087 void addTokenToList(const TString& rArgument);
00088 void parseArguments(const IString& rArguments, bool bNativeCommandLine);
00089 };
00090
00091
00092
00093
00099
00100 inline bool TArgumentParser::hasArgument(const IString& rArgName) const
00101 {
00102 return m_mapItems.hasItem(rArgName);
00103 }
00104
00105
00111
00112 inline bool TArgumentParser::hasArgument(const wchar_t* pArgName) const
00113 {
00114 return m_mapItems.hasItem(pArgName);
00115 }
00116
00117
00123
00124 inline bool TArgumentParser::hasArgumentWithValue(const IString& rArgName) const
00125 {
00126 return (m_mapItems.hasItem(rArgName) && !m_mapItems.getItemConst(rArgName).isEmpty());
00127 }
00128
00129
00135
00136 inline bool TArgumentParser::hasArgumentWithValue(const wchar_t* pArgName) const
00137 {
00138 return (m_mapItems.hasItem(TString(pArgName)) && !m_mapItems.getItemConst(TString(pArgName)).isEmpty());
00139 }
00140
00141
00146
00147 inline TString TArgumentParser::getArgumentValue(const IString& rArgName) const
00148 {
00149 return m_mapItems.getItemConst(rArgName);
00150 }
00151
00152
00157
00158 inline TString TArgumentParser::getArgumentValue(const wchar_t* pArgName) const
00159 {
00160 return m_mapItems.getItemConst(TString(pArgName));
00161 }
00162
00163
00168
00169 inline TString TArgumentParser::getArgumentValueByIndex(Int iIndex) const
00170 {
00171 return m_lstItems.getItemConst(iIndex);
00172 }
00173
00174
00177
00178 inline TString TArgumentParser::getFirstArgument() const
00179 {
00180 return m_lstItems.getFirstItemConst();
00181 }
00182
00183
00186
00187 inline TString TArgumentParser::getLastArgument() const
00188 {
00189 return m_lstItems.getLastItemConst();
00190 }
00191
00192
00195
00196 inline Int TArgumentParser::getArgumentCount() const
00197 {
00198 return m_lstItems.getCount();
00199 }
00200
00201
00204
00205 inline void TArgumentParser::resetList()
00206 {
00207 m_pListIterator->reset();
00208 }
00209
00210
00213
00214 inline TString TArgumentParser::getNextItem() const
00215 {
00216 return m_pListIterator->getNextItemConst();
00217 }
00218
00219
00222
00223 inline bool TArgumentParser::hasNextItem() const
00224 {
00225 return m_pListIterator->hasNextItem();
00226 }
00227
00228
00231
00232 inline TString TArgumentParser::getApplicationFile() const
00233 {
00234 return m_strFileName;
00235 }
00236
00237
00241
00242 inline void TArgumentParser::setApplicationFileName(const IString& rFileName)
00243 {
00244 m_strFileName = rFileName;
00245 }
00246
00247
00248 END_NAMESPACE_Zeus
00249
00250 #endif