Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jul 20, 2008, 7:49:26 PM (16 years ago)
Author:
rgrieder
Message:

merged input branch into gui test branch (was about time)
svn save (it's still a mess and CMLs haven't been updated)
I'll have to create a special project to create the tolua_bind files for tolua itself anyway..

Location:
code/branches/gui
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/gui

  • code/branches/gui/src/util/ArgReader.h

    r1535 r1638  
    2222 *   Author:
    2323 *      Reto Grieder
     24 *      Benjamin Knecht <beni_at_orxonox.net>
    2425 *   Co-authors:
    25  *      Benjamin Knecht <beni_at_orxonox.net>
     26 *      ...
    2627 *
    2728 */
     
    4243#include "Convert.h"
    4344
    44 struct _UtilExport CmdLineArg
    45 {
    46   std::string name_;
    47   std::string value_;
    48   bool bChecked_;
    49 };
    5045
    5146class _UtilExport ArgReader
    5247{
    53   public:
    54     ArgReader(int argc, char **argv);
    55     template <class T>
    56     void checkArgument(std::string option, T* value, bool must = false);
    57     bool errorHandling();
    58     const std::string& getErrorString();
     48public:
     49    ArgReader() { }
     50    std::string parse(int argc, char **argv);
     51    const std::string& getArgument(const std::string& option);
     52    bool allChecked();
    5953
    60   private:
     54private:
     55    struct CmdLineArg
     56    {
     57        std::string name_;
     58        std::string value_;
     59        bool bChecked_;
     60    };
     61
    6162    std::vector<CmdLineArg> arguments_;
    62     bool failure_;
    63     std::string errorString_;
    6463};
    6564
    66 template <class T>
    67 void ArgReader::checkArgument(std::string option, T* value, bool must)
    68 {
    69   unsigned int iArg = 0;
    70   while (iArg < arguments_.size())
    71   {
    72     if (arguments_[iArg].name_ == option)
    73       break;
    74     ++iArg;
    75   }
    76   if (iArg == arguments_.size())
    77   {
    78     if (must)
    79     {
    80       failure_ = true;
    81       errorString_ += "Cannot find mandatory argument \"" + option + "\"\n";
    82       return;
    83     }
    84     else
    85       return;
    86   }
    87 
    88   arguments_[iArg].bChecked_ = true;
    89 
    90   if (!convertValue(value, arguments_[iArg].value_))
    91   {
    92     failure_ = true;
    93     errorString_ += "Cannot convert argument value for option \"" + option + "\"\n";
    94   }
    95 }
    96 
    97 template <>
    98 void ArgReader::checkArgument(std::string option, bool* value, bool must)
    99 {
    100   // for type bool, only check whether the option was set or not
    101   unsigned int iArg = 0;
    102   while (iArg < arguments_.size())
    103   {
    104     if (arguments_[iArg].name_ == option)
    105     {
    106       arguments_[iArg].bChecked_ = true;
    107       *value = true;
    108       break;
    109     }
    110     ++iArg;
    111   }
    112   if (iArg == arguments_.size())
    113     *value = false;
    114 }
    115 
    11665#endif /* _ArgReader_H__ */
Note: See TracChangeset for help on using the changeset viewer.