Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jul 20, 2008, 7:49:26 PM (17 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:
5 edited

Legend:

Unmodified
Added
Removed
  • code/branches/gui

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

    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 */
     
    3536#include "SubString.h"
    3637
    37 ArgReader::ArgReader(int argc, char **argv)
     38std::string ArgReader::parse(int argc, char **argv)
    3839{
    39   failure_ = false;
    40   errorString_ = "";
    41   CmdLineArg arg;
     40    std::string errorString;
     41    CmdLineArg arg;
     42    int i = 1;
     43    while (i < argc)
     44    {
     45        if (argv[i][0] == '-' && argv[i][1] == '-') // name
     46        {
     47            if (argv[i][2] == '\0')
     48            {
     49                errorString += "Expected word after \"--\".\n";
     50            }
     51            arg.bChecked_ = false;
     52            arg.name_ = argv[i] + 2;
     53            arg.value_ = " ";
     54            arguments_.push_back(arg);
     55        }
     56        else // value
     57        {
     58            if (arguments_.size() == 0)
     59            {
     60                errorString += "Expected \"--\" in command line arguments.\n";
     61                arg.bChecked_ = false;
     62                arg.name_ = "";
     63                arg.value_ = " ";
     64                arguments_.push_back(arg);
     65            }
    4266
    43   int i = 1;
    44   while (i < argc)
    45   {
    46     if (argv[i][0] == '-' && argv[i][1] == '-') // name
    47     {
    48       if (argv[i][2] == '\0')
    49       {
    50         failure_ = true;
    51         errorString_ += "Expected word after \"--\".\n";
    52       }
    53       arg.bChecked_ = false;
    54       arg.name_ = argv[i] + 2;
    55       arg.value_ = "";
    56       arguments_.push_back(arg);
     67            if (arguments_.back().value_ != " ")
     68                arguments_.back().value_ += " " + std::string(argv[i]);
     69            else
     70                arguments_.back().value_ = argv[i];
     71        }
     72        ++i;
    5773    }
    58     else // value
    59     {
    60       if (arguments_.size() == 0)
    61       {
    62         failure_ = true;
    63         errorString_ += "Expected \"--\" in command line arguments.\n";
    64         arg.bChecked_ = false;
    65         arg.name_ = "";
    66         arg.value_ = "";
    67         arguments_.push_back(arg);
    68       }
    69 
    70       if (arguments_.back().value_ != "")
    71         arguments_.back().value_ += " " + std::string(argv[i]);
    72       else
    73         arguments_.back().value_ = argv[i];
    74     }
    75     ++i;
    76   }
     74    return errorString;
    7775}
    7876
    79 bool ArgReader::errorHandling()
     77const std::string& ArgReader::getArgument(const std::string& option)
    8078{
    81   bool argumentsChecked = true;
    82   for (unsigned int i = 1; i < arguments_.size(); ++i)
    83     argumentsChecked &= arguments_[i].bChecked_;
    84 
    85   if (!argumentsChecked)
    86     errorString_ += "Not all arguments could be matched.\n";
    87 
    88   return !argumentsChecked || failure_;
     79    unsigned int iArg = 0;
     80    while (iArg < arguments_.size())
     81    {
     82        if (arguments_[iArg].name_ == option)
     83        {
     84            arguments_[iArg].bChecked_ = true;
     85            return arguments_[iArg].value_;
     86        }
     87        ++iArg;
     88    }
     89    return blankString;
    8990}
    9091
    91 const std::string& ArgReader::getErrorString()
     92bool ArgReader::allChecked()
    9293{
    93   return errorString_;
     94    bool argumentsChecked = true;
     95    for (unsigned int i = 1; i < arguments_.size(); ++i)
     96        argumentsChecked &= arguments_[i].bChecked_;
     97
     98    return argumentsChecked;
    9499}
  • 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__ */
  • code/branches/gui/src/util/OrxonoxPlatform.h

    r1505 r1638  
    103103#else
    104104#  define ORXONOX_ARCH_TYPE ORXONOX_ARCHITECTURE_32
     105#endif
     106
     107// try to define function information
     108#ifndef __FUNCTIONNAME__
     109#  if ORXONOX_COMPILER == ORXONOX_COMPILER_BORL
     110#    define __FUNCTIONNAME__ __FUNC__
     111#  elif ORXONOX_COMPILER == ORXONOX_COMPILER_GNUC
     112#    define __FUNCTIONNAME__ __PRETTY_FUNCTION__
     113#  elif ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC
     114#    define __FUNCTIONNAME__ __FUNCTION__
     115#  else
     116#    define __FUNCTIONNAME__
     117#  endif
    105118#endif
    106119
     
    265278// generated code from nvparse etc). I doubt very much that these calls
    266279// will ever be actually removed from VC anyway, it would break too much code.
    267 //#     pragma warning( disable: 4996)
     280//# pragma warning( disable: 4996)
    268281
    269282// disable: "conditional expression constant", always occurs on
  • code/branches/gui/src/util/Sleep.h

    r1505 r1638  
    2929/**
    3030 @file  Sleep.h
    31  @brief Macros for using sleep() and usleep() under windows
     31 @brief Functions for using sleep() and usleep() under windows
    3232 */
    3333
Note: See TracChangeset for help on using the changeset viewer.