Shellp

shellcmdchoicearg.h

00001 /*
00002     
00003   This file is a part of Shellp, a 'shell helper' library.
00004   
00005   Copyright (C) 2011-2012 Jori Liesenborgs
00006   
00007   Contact: jori.liesenborgs@gmail.com
00008 
00009   This library is free software; you can redistribute it and/or
00010   modify it under the terms of the GNU Lesser General Public
00011   License as published by the Free Software Foundation; either
00012   version 2.1 of the License, or (at your option) any later version.
00013 
00014   This library is distributed in the hope that it will be useful,
00015   but WITHOUT ANY WARRANTY; without even the implied warranty of
00016   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017   Lesser General Public License for more details.
00018 
00019   You should have received a copy of the GNU Lesser General Public
00020   License along with this library; if not, write to the Free Software
00021   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  
00022   USA
00023 
00024 */
00025 
00026 #ifndef SHELLP_SHELLCMDCHOICEARG_H
00027 
00028 #define SHELLP_SHELLCMDCHOICEARG_H
00029 
00030 #include "shellconfig.h"
00031 #include "shellcmdarg.h"
00032 #include <vector>
00033 
00034 namespace shellp
00035 {
00036 
00037 class SHELLP_IMPORTEXPORT ShellCmdChoiceArg : public ShellCmdArg
00038 {
00039 public:
00040         ShellCmdChoiceArg(const std::string &argName);
00041         ShellCmdChoiceArg(const std::string &argName, const std::string &defaultValue);
00042         ~ShellCmdChoiceArg();
00043 
00044         // 'value' should be positive
00045         bool registerChoice(const std::string &choiceName, const std::string &choiceDescription, int value);
00046 
00047         bool parse(const std::string &arg);
00048         int getValue() const                                                    { return m_val; }
00049 
00050         int getNumberOfChoices() const                                          { return m_choices.size(); }
00051         bool getChoiceInfo(int i, std::string &name, std::string &description, int &value) const;
00052 private:
00053         int m_val;
00054 
00055         class ChoiceInfo
00056         {
00057         public:
00058                 ChoiceInfo(const std::string &choiceName, const std::string &choiceDescription, int value)
00059                 {
00060                         m_choiceName = choiceName;
00061                         m_choiceDescription = choiceDescription;
00062                         m_value = value;
00063                 }
00064 
00065                 std::string getName() const                                     { return m_choiceName; }
00066                 std::string getDescription() const                              { return m_choiceDescription; }
00067                 int getValue() const                                            { return m_value; }
00068         private:
00069                 std::string m_choiceName, m_choiceDescription;
00070                 int m_value;
00071         };
00072 
00073         std::vector<ChoiceInfo> m_choices;
00074 };
00075 
00076 } // end namespace
00077 
00078 #endif // SHELLP_SHELLCMDCHOICEARG_H
00079