Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7714 in orxonox.OLD


Ignore:
Timestamp:
May 19, 2006, 1:29:27 AM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: Reimplementation of the Executor started in orxonox.cc

Location:
trunk/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/util/executor/executor.cc

    r7300 r7714  
    1818#include "executor.h"
    1919
    20 #include "debug.h"
    21 #include "class_list.h"
    22 
    23 #include "key_names.h"
    24 #include <stdarg.h>
    25 #include <stdio.h>
    26 #include <string.h>
    27 
    28 using namespace std;
    29 
    3020////////////////////////
    3121// SHELL COMMAND BASE //
    3222////////////////////////
    3323/**
    34  * constructs and registers a new Command
     24 * @brief constructs and registers a new Command
    3525 * @param commandName the name of the Command
    3626 * @param className the name of the class to apply this command to
     
    4333                   const MultiType& param4)
    4434{
    45   this->setClassID(CL_EXECUTOR, "Executor");
     35//  this->setClassID(CL_EXECUTOR, "Executor");
    4636
    4737  // What Parameters have we got
  • trunk/src/lib/util/executor/executor.h

    r7474 r7714  
    3636 *  Functions with many types (@see functor_list.h)
    3737 */
    38 class Executor: public BaseObject
     38class Executor : public BaseObject
    3939{
    40   public:
    41     virtual ~Executor();
    42 
    43     virtual Executor* clone () const = 0;
    44 
    45     // SETTING up the EXECUTOR
    46     Executor* defaultValues(const MultiType& value0 = MT_NULL, const MultiType& value1 = MT_NULL,
    47                             const MultiType& value2 = MT_NULL, const MultiType& value3 = MT_NULL,
    48                             const MultiType& value4 = MT_NULL);
    49     /** @param i the i'th defaultValue, @returns reference to the MultiType */
    50     inline MultiType& getDefaultValue(unsigned int i) { return defaultValue[i]; };
    51 
    52     // EXECUTE
    53     /** executes a Command @param object the object to apply this to @param parameters the parameters the command takes */
    54     virtual void operator()(BaseObject* object, const SubString& sub = SubString()) const = 0;
    55     /** executes a Command @param object the object to apply this to @param parameters the parameters the command takes @brief here for your convenience*/
    56     void execute (BaseObject* object, const std::string& parameters = "") const { (*this)(object, parameters); };
    57 
    58     // RETRIEVE INFORMATION
    59     /** @returns the Type of this Function (either static or objective) */
    60     inline long getType() const { return this->functorType; };
    61     /** @returns the Count of Parameters this Executor takes */
    62     inline unsigned int getParamCount() const { return this->paramCount; };
    63 
    64     static void debug();
    65 
    66   protected:
    67     Executor(const MultiType& param0 = MT_NULL, const MultiType& param1 = MT_NULL,
    68              const MultiType& param2 = MT_NULL, const MultiType& param3 = MT_NULL,
    69              const MultiType& param4 = MT_NULL);
    70 
    71     void cloning(Executor* executor) const;
    72 
    73   protected:
    74     short                       functorType;      //!< The type of Function we've got (either static or objective).
    75     unsigned int                paramCount;       //!< the count of parameters.
    76     MultiType                   defaultValue[5];  //!< Default Values.
     40public:
     41  virtual ~Executor();
     42
     43  virtual Executor* clone () const = 0;
     44
     45  // SETTING up the EXECUTOR
     46  Executor* defaultValues(const MultiType& value0 = MT_NULL, const MultiType& value1 = MT_NULL,
     47                          const MultiType& value2 = MT_NULL, const MultiType& value3 = MT_NULL,
     48                          const MultiType& value4 = MT_NULL);
     49  /** @param i the i'th defaultValue, @returns reference to the MultiType */
     50  inline MultiType& getDefaultValue(unsigned int i) { return defaultValue[i]; };
     51
     52  // EXECUTE
     53  /** executes a Command @param object the object to apply this to @param parameters the parameters the command takes */
     54  virtual void operator()(BaseObject* object, const SubString& sub = SubString()) const = 0;
     55  /** executes a Command @param object the object to apply this to @param parameters the parameters the command takes @brief here for your convenience*/
     56  void execute (BaseObject* object, const std::string& parameters = "") const { (*this)(object, parameters); };
     57
     58  // RETRIEVE INFORMATION
     59  /** @returns the Type of this Function (either static or objective) */
     60  inline long getType() const { return this->functorType; };
     61  /** @returns the Count of Parameters this Executor takes */
     62  inline unsigned int getParamCount() const { return this->paramCount; };
     63
     64  static void debug();
     65
     66protected:
     67  Executor(const MultiType& param0 = MT_NULL, const MultiType& param1 = MT_NULL,
     68           const MultiType& param2 = MT_NULL, const MultiType& param3 = MT_NULL,
     69           const MultiType& param4 = MT_NULL);
     70
     71  void cloning(Executor* executor) const;
     72
     73protected:
     74  short                       functorType;      //!< The type of Function we've got (either static or objective).
     75  unsigned int                paramCount;       //!< the count of parameters.
     76  MultiType                   defaultValue[5];  //!< Default Values.
    7777};
    7878
     
    8989
    9090
     91
    9192///////////////////////
    9293// FUNCTION POINTERS //
     
    232233template<class T> class EXECUTOR : public Executor
    233234{
    234   public:
    235     EXECUTOR() : Executor() { };
    236     // COPY constuctor (virtual version)
    237     virtual Executor* clone () const
    238     {
    239       EXECUTOR<T>* executor = new EXECUTOR<T>();
    240       this->cloning(executor);
    241       executor->fp = this->fp;
    242       return executor;
    243     }
    244 
    245 //! FUNCTOR_LIST is the List of CommandConstructors
     235public:
     236  EXECUTOR() : Executor() { };
     237  // COPY constuctor (virtual version)
     238  virtual Executor* clone () const
     239  {
     240    EXECUTOR<T>* executor = new EXECUTOR<T>();
     241    this->cloning(executor);
     242    executor->fp = this->fp;
     243    return executor;
     244  }
     245
     246  //! FUNCTOR_LIST is the List of CommandConstructors
    246247#define FUNCTOR_LIST(x) ExecutorConstructor ## x
    247248#include "functor_list.h"
    248249#undef FUNCTOR_LIST
    249250
    250   private:
    251 //! FUNCTOR_LIST is the List of FunctionPointers
    252     union FunctionPointers {
     251private:
     252  //! FUNCTOR_LIST is the List of FunctionPointers
     253  union FunctionPointers {
    253254#define FUNCTOR_LIST(x) ExecutorFunctionPoiter ## x
    254255#include "functor_list.h"
    255256#undef FUNCTOR_LIST
    256     } fp;
    257 
    258     virtual void operator()(BaseObject* object, const SubString& sub = SubString()) const
    259     {
    260 //! FUNCTOR_LIST is the List of Executive Functions
     257  } fp;
     258
     259  virtual void operator()(BaseObject* object, const SubString& sub = SubString()) const
     260  {
     261    //! FUNCTOR_LIST is the List of Executive Functions
    261262#define FUNCTOR_LIST(x) ExecutorExecute ## x
    262263#include "functor_list.h"
    263264#undef FUNCTOR_LIST
    264     }
     265
     266  }
    265267};
    266268
     
    292294template<class T> class ExecutorStatic : public Executor
    293295{
    294   public:
    295     EXECUTOR() : Executor() { };
    296     // COPY constuctor
    297     virtual Executor* clone () const
    298     {
    299       EXECUTOR<T>* executor = new EXECUTOR<T>();
    300       this->cloning(executor);
    301       executor->fp = this->fp;
    302       return executor;
    303     }
    304 
    305 //! FUNCTOR_LIST is the List of CommandConstructors
     296public:
     297  EXECUTOR() : Executor() { };
     298  // COPY constuctor
     299  virtual Executor* clone () const
     300  {
     301    EXECUTOR<T>* executor = new EXECUTOR<T>();
     302    this->cloning(executor);
     303    executor->fp = this->fp;
     304    return executor;
     305  }
     306
     307  //! FUNCTOR_LIST is the List of CommandConstructors
    306308#define FUNCTOR_LIST(x) ExecutorConstructor ## x
    307309#include "functor_list.h"
    308310#undef FUNCTOR_LIST
    309311
    310   private:
    311 //! FUNCTOR_LIST is the List of FunctionPointers
    312     union FunctionPointers {
     312private:
     313  //! FUNCTOR_LIST is the List of FunctionPointers
     314  union FunctionPointers {
    313315#define FUNCTOR_LIST(x) ExecutorFunctionPoiter ## x
    314316#include "functor_list.h"
    315317#undef FUNCTOR_LIST
    316     } fp;
    317 
    318 
    319     virtual void operator()(BaseObject* object, const SubString& sub = SubString()) const
    320     {
    321 //! FUNCTOR_LIST is the List of Executive Functions
     318  } fp;
     319
     320
     321  virtual void operator()(BaseObject* object, const SubString& sub = SubString()) const
     322  {
     323    //! FUNCTOR_LIST is the List of Executive Functions
    322324#define FUNCTOR_LIST(x) ExecutorExecute ## x
    323325#include "functor_list.h"
    324326#undef FUNCTOR_LIST
    325     }
     327
     328  }
    326329};
    327330
  • trunk/src/lib/util/helper_functions.cc

    r7412 r7714  
    101101 * @return returns the contained string (char-array), if STRING was correct otherwise defaultValue
    102102 */
    103 std::string isString(const std::string& STRING, const std::string& defaultValue)
     103const std::string& isString(const std::string& STRING, const std::string& defaultValue)
    104104{
    105105  if (STRING.size() > 0)
     
    124124  {
    125125    if(::toupper(*it1) != ::toupper(*it2)) //letters differ?
    126      // return -1 to indicate smaller than, 1 otherwise
     126      // return -1 to indicate smaller than, 1 otherwise
    127127      return (::toupper(*it1)  < ::toupper(*it2)) ? -1 : 1;
    128128    //proceed to the next character in each string
     
    131131  }
    132132  size_t size1=s1.size(), size2=s2.size();// cache lengths
    133    //return -1,0 or 1 according to strings' lengths
     133  //return -1,0 or 1 according to strings' lengths
    134134  if (size1==size2)
    135135    return 0;
     
    155155  {
    156156    if(::toupper(*it1) != ::toupper(*it2)) //letters differ?
    157      // return -1 to indicate smaller than, 1 otherwise
     157      // return -1 to indicate smaller than, 1 otherwise
    158158      return (::toupper(*it1)  < ::toupper(*it2)) ? -1 : 1;
    159159    //proceed to the next character in each string
  • trunk/src/lib/util/helper_functions.h

    r7371 r7714  
    1818float         isFloat(const std::string& FLOAT, float defaultValue);
    1919const char*   isCString(const std::string& STRING, const char* defaultValue);
    20 std::string  isString(const std::string& STRING, const std::string& defaultValue);
     20const std::string& isString(const std::string& STRING, const std::string& defaultValue);
    2121
    2222
  • trunk/src/orxonox.cc

    r7711 r7714  
    302302    NetworkManager::getInstance()->establishConnection(this->serverName, port);
    303303  }
    304   else if( this->port > 0) {    // we are a server
     304  else if( this->port > 0)
     305  {    // we are a server
    305306    State::setOnline(true);
    306307    NetworkManager::getInstance()->createServer(port);
     
    335336    PRINTF(1)("The DataDirectory %s could not be verified\n\nh" \
    336337              "!!!  Please Change in File %s Section %s Entry %s to a suitable value !!!\n",
    337     ResourceManager::getInstance()->getDataDir().c_str(),
    338     this->configFileName.c_str(),
     338              ResourceManager::getInstance()->getDataDir().c_str(),
     339              this->configFileName.c_str(),
    339340              CONFIG_SECTION_GENERAL,
    340341              CONFIG_NAME_DATADIR );
     
    413414bool showGui = false;
    414415
    415 
     416/// HACK HACK TEST
     417
     418
     419template<typename type> MT_Type ExecutorParamType() { return MT_EXT1; };
     420template<> MT_Type ExecutorParamType<bool>() { return MT_EXT1; };
     421template<> MT_Type ExecutorParamType<int>() { return MT_INT; };
     422template<> MT_Type ExecutorParamType<unsigned int>() { return MT_UINT; };
     423template<> MT_Type ExecutorParamType<float>() { return MT_FLOAT; };
     424template<> MT_Type ExecutorParamType<char>() { return MT_CHAR; };
     425template<> MT_Type ExecutorParamType<const std::string&>() { return MT_STRING; };
     426
     427template<typename type> type fromString(const std::string& input, type defaultValue) {return defaultValue; };
     428template<> bool fromString<bool>(const std::string& input, bool defaultValue) { return isBool(input, defaultValue); };
     429template<> int fromString<int>(const std::string& input, int defaultValue) { return isInt(input, defaultValue); };
     430template<> unsigned int fromString<unsigned int>(const std::string& input, unsigned int defaultValue) { return isInt(input, defaultValue); };
     431template<> float fromString<float>(const std::string& input, float defaultValue) { return isFloat(input, defaultValue); };
     432template<> char fromString<char>(const std::string& input, char defaultValue) { return isInt(input, defaultValue); };
     433template<> const std::string& fromString<const std::string&>(const std::string& input, const std::string& defaultValue) { return isString(input, defaultValue); };
     434
     435template<typename type> type getDefault(const MultiType* const defaultValues, unsigned int i) { return (type)0; };
     436template<> bool getDefault<bool>(const MultiType* const defaultValues, unsigned int i) { return defaultValues[i].getBool(); };
     437template<> int getDefault<int>(const MultiType* const defaultValues, unsigned int i) { return defaultValues[i].getInt(); };
     438template<> unsigned int getDefault<unsigned int>(const MultiType* const defaultValues, unsigned int i) { return defaultValues[i].getInt(); };
     439template<> float getDefault<float>(const MultiType* const defaultValues, unsigned int i) { return defaultValues[i].getFloat(); };
     440template<> char getDefault<char>(const MultiType* const defaultValues, unsigned int i) { return defaultValues[i].getChar(); };
     441template<> std::string getDefault<std::string>(const MultiType* const defaultValues, unsigned int i) { return defaultValues[i].getString(); };
     442
     443
     444template<class T> class Executor0Params : public Executor
     445{
     446  private:
     447    void (T::*functionPointer)();
     448
     449  public:
     450    Executor0Params (void (T::*functionPointer)())
     451  : Executor()
     452    {
     453      this->functorType = Executor_Objective;
     454      this->functionPointer = functionPointer;
     455    }
     456    virtual void operator()(BaseObject* object, const SubString& sub = SubString()) const
     457    {
     458      (dynamic_cast<T*>(object)->*functionPointer)();
     459    };
     460
     461    Executor* clone() const {};
     462};
     463
     464
     465template<class T, typename type0> class Executor1Params : public Executor
     466{
     467private:
     468  void (T::*functionPointer)(type0);
     469
     470public:
     471  Executor1Params (void (T::*functionPointer)(type0))
     472      : Executor(ExecutorParamType<type0>())
     473  {
     474    this->functorType = Executor_Objective;
     475    this->functionPointer = functionPointer;
     476  }
     477  virtual void operator()(BaseObject* object, const SubString& sub = SubString()) const
     478  {
     479
     480    /* // THE VERY COOL DEBUG
     481    printf("SUB[0] : %s\n", sub[0].c_str());
     482    printf("getDefault<type0>(this->defaultValue, 0):::: %d\n", getDefault<type0>(this->defaultValue, 0));
     483    printf("VALUE: %d\n", fromString<type0>(sub[0], getDefault<type0>(this->defaultValue, 0)));
     484    */
     485    (dynamic_cast<T*>(object)->*functionPointer)( fromString<type0>(sub[0], getDefault<type0>(this->defaultValue, 0)) );
     486  };
     487
     488  virtual Executor* clone() const {};
     489};
     490
     491/// DOUBLE PENETRATION
     492template<class T, typename type0, typename type1> class Executor2Params : public Executor
     493{
     494private:
     495  void (T::*functionPointer)(type0, type1);
     496
     497public:
     498  Executor2Params (void (T::*functionPointer)(type0, type1))
     499      : Executor(ExecutorParamType<type0>(), ExecutorParamType<type1>())
     500  {
     501    this->functorType = Executor_Objective;
     502    this->functionPointer = functionPointer;
     503  }
     504  virtual void operator()(BaseObject* object, const SubString& sub = SubString()) const
     505  {
     506    (dynamic_cast<T*>(object)->*functionPointer)(
     507      fromString<type0>(sub[0], getDefault<type0>(this->defaultValue, 0)),
     508      fromString<type1>(sub[1], getDefault<type1>(this->defaultValue, 1)));
     509  };
     510
     511  virtual Executor* clone() const {};
     512};
     513
     514class TestClass : public BaseObject
     515{
     516public:
     517  TestClass() {};
     518
     519  void printTest() { printf ("TEST\n"); };
     520  void printTestInt(int i) { printf ("%d\n", i); };
     521  void printTestBool(bool b) { printf("%d\n", (int)b); };
     522  void printTwoVals(bool b, int i) { printf ("%d %d\n", b, i); };
     523};
     524
     525void TEST()
     526{
     527  TestClass test;
     528  SubString testStrings("1, 2, 3", ",", SubString::WhiteSpaces, false);
     529  (Executor0Params<TestClass>(&TestClass::printTest))(&test, testStrings);
     530  (Executor1Params<TestClass,int>(&TestClass::printTestInt))(&test, testStrings);
     531  (Executor1Params<TestClass,bool>(&TestClass::printTestBool))(&test, testStrings);
     532  (Executor2Params<TestClass,bool, int>(&TestClass::printTwoVals))(&test, testStrings);
     533
     534}
     535
     536//// HACK HACK
    416537
    417538/**********************************
     
    426547int main(int argc, char** argv)
    427548{
     549  TEST();
    428550  CmdLinePrefsReader prefs;
    429551
     
    444566  }
    445567  else if ( Preferences::getInstance()->getString("misc", "bt-to-file", "1") == "1" )
    446   {      SignalHandler::getInstance()->doCatch( argv[0], GDB_RUN_WRITE_TO_FILE );
     568  {
     569    SignalHandler::getInstance()->doCatch( argv[0], GDB_RUN_WRITE_TO_FILE );
    447570
    448571  }
     
    506629  // checking for existence of the configuration-files, or if the lock file is still used
    507630  if (showGui || (!File("./orxonox.conf").isFile() &&
    508       !File(DEFAULT_CONFIG_FILE).isFile())
     631                  !File(DEFAULT_CONFIG_FILE).isFile())
    509632#if DEBUG < 3 // developers do not need to see the GUI, when orxonox fails
    510633      || ResourceManager::isFile(DEFAULT_LOCK_FILE)
Note: See TracChangeset for help on using the changeset viewer.