Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 14, 2008, 3:42:49 AM (16 years ago)
Author:
landauf
Message:

merged core2 back to trunk
there might be some errors, wasn't able to test it yet due to some strange g++ and linker behaviour.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/orxonox/core/Executor.cc

    r871 r1052  
    2929#include "Executor.h"
    3030#include "Language.h"
    31 #include "util/String.h"
     31#include "util/Math.h"
    3232
    3333namespace orxonox
    3434{
    35     Executor::Executor(Functor* functor, const std::string& name)
     35    Executor::Executor(Functor* functor, const std::string& name, AccessLevel::Level level)
    3636    {
    3737        this->functor_ = functor;
    3838        this->name_ = name;
     39        this->accessLevel_ = level;
     40
    3941        this->bAddedDescription_ = false;
    4042        this->bAddedDescriptionReturnvalue_ = false;
     43
    4144        this->bAddedDescriptionParam_[0] = false;
    4245        this->bAddedDescriptionParam_[1] = false;
     
    4447        this->bAddedDescriptionParam_[3] = false;
    4548        this->bAddedDescriptionParam_[4] = false;
     49
     50        this->bAddedDefaultValue_[0] = false;
     51        this->bAddedDefaultValue_[1] = false;
     52        this->bAddedDefaultValue_[2] = false;
     53        this->bAddedDefaultValue_[3] = false;
     54        this->bAddedDefaultValue_[4] = false;
    4655    }
    4756
    4857    Executor::~Executor()
    4958    {
    50     }
    51 
    52     void Executor::setName(const std::string name)
    53     {
    54         this->name_ = name;
    55     }
    56 
    57     const std::string& Executor::getName() const
    58     {
    59         return this->name_;
    60     }
    61 
    62     void Executor::description(const std::string& description)
     59        delete this->functor_;
     60    }
     61
     62    bool Executor::parse(const std::string& params, const std::string& delimiter) const
     63    {
     64        EXECUTOR_PARSE(normal);
     65    }
     66
     67    bool Executor::evaluate(const std::string& params, MultiTypeMath param[5], const std::string& delimiter) const
     68    {
     69        unsigned int paramCount = this->functor_->getParamCount();
     70
     71        if (paramCount == 1)
     72        {
     73            // only one param: check if there are params given, otherwise try to use default values
     74            std::string temp = getStripped(params);
     75            if ((temp != "") && (temp.size() != 0))
     76            {
     77                param[0] = params;
     78                this->functor_->evaluateParam(0, param[0]);
     79                return true;
     80            }
     81            else if (this->bAddedDefaultValue_[0])
     82            {
     83                param[0] = this->defaultValue_[0];
     84                this->functor_->evaluateParam(0, param[0]);
     85                return true;
     86            }
     87            return false;
     88        }
     89        else
     90        {
     91            // more than one param
     92            SubString tokens(params, delimiter, SubString::WhiteSpaces, false, '\\', true, '"', true, '(', ')', true, '\0');
     93
     94            // if there are not enough params given, check if there are default values
     95            for (unsigned int i = tokens.size(); i < this->functor_->getParamCount(); i++)
     96                if (!this->bAddedDefaultValue_[i])
     97                    return false;
     98
     99            // assign all given arguments to the multitypes
     100            for (unsigned int i = 0; i < min(tokens.size(), (unsigned int)MAX_FUNCTOR_ARGUMENTS); i++)
     101                param[i] = tokens[i];
     102
     103            // fill the remaining multitypes with default values
     104            for (unsigned int i = tokens.size(); i < min(paramCount, (unsigned int)MAX_FUNCTOR_ARGUMENTS); i++)
     105                param[i] = this->defaultValue_[i];
     106
     107            // evaluate the param types through the functor
     108            for (unsigned int i = 0; i < min(paramCount, (unsigned int)MAX_FUNCTOR_ARGUMENTS); i++)
     109                this->functor_->evaluateParam(i, param[i]);
     110
     111            return true;
     112        }
     113    }
     114
     115    Executor& Executor::setDescription(const std::string& description)
    63116    {
    64117        if (!this->bAddedDescription_)
     
    68121            this->bAddedDescription_ = true;
    69122        }
     123        return (*this);
    70124    }
    71125
     
    75129    }
    76130
    77     void Executor::descriptionParam(int param, const std::string& description)
    78     {
    79         if (param > 0 && param <= 5)
     131    Executor& Executor::setDescriptionParam(int param, const std::string& description)
     132    {
     133        if (param >= 0 && param < MAX_FUNCTOR_ARGUMENTS)
    80134        {
    81135            if (!this->bAddedDescriptionParam_[param])
     
    83137                std::string paramnumber;
    84138                if (!Convert::ToString(&paramnumber, param))
    85                     return;
     139                    return (*this);
    86140
    87141                this->descriptionParam_[param] = std::string("ExecutorDescription::" + this->name_ + "::param" + paramnumber);
     
    90144            }
    91145        }
     146        return (*this);
    92147    }
    93148
    94149    const std::string& Executor::getDescriptionParam(int param) const
    95150    {
    96         if (param > 0 && param <= 5)
    97         {
     151        if (param >= 0 && param < MAX_FUNCTOR_ARGUMENTS)
    98152            return GetLocalisation(this->descriptionParam_[param]);
    99         }
    100153
    101154        return this->descriptionParam_[0];
    102155    }
    103156
    104     void Executor::descriptionReturnvalue(const std::string& description)
     157    Executor& Executor::setDescriptionReturnvalue(const std::string& description)
    105158    {
    106159        if (!this->bAddedDescriptionReturnvalue_)
     
    110163            this->bAddedDescriptionReturnvalue_ = true;
    111164        }
     165        return (*this);
    112166    }
    113167
     
    116170        return GetLocalisation(this->descriptionReturnvalue_);
    117171    }
     172
     173    Executor& Executor::setDefaultValues(const MultiTypeMath& param1)
     174    {
     175        this->defaultValue_[0] = param1;
     176        this->bAddedDefaultValue_[0] = true;
     177
     178        return (*this);
     179    }
     180
     181    Executor& Executor::setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2)
     182    {
     183        this->defaultValue_[0] = param1;
     184        this->bAddedDefaultValue_[0] = true;
     185        this->defaultValue_[1] = param2;
     186        this->bAddedDefaultValue_[1] = true;
     187
     188        return (*this);
     189    }
     190
     191    Executor& Executor::setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3)
     192    {
     193        this->defaultValue_[0] = param1;
     194        this->bAddedDefaultValue_[0] = true;
     195        this->defaultValue_[1] = param2;
     196        this->bAddedDefaultValue_[1] = true;
     197        this->defaultValue_[2] = param3;
     198        this->bAddedDefaultValue_[2] = true;
     199
     200        return (*this);
     201    }
     202
     203    Executor& Executor::setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3, const MultiTypeMath& param4)
     204    {
     205        this->defaultValue_[0] = param1;
     206        this->bAddedDefaultValue_[0] = true;
     207        this->defaultValue_[1] = param2;
     208        this->bAddedDefaultValue_[1] = true;
     209        this->defaultValue_[2] = param3;
     210        this->bAddedDefaultValue_[2] = true;
     211        this->defaultValue_[3] = param4;
     212        this->bAddedDefaultValue_[3] = true;
     213
     214        return (*this);
     215    }
     216
     217    Executor& Executor::setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3, const MultiTypeMath& param4, const MultiTypeMath& param5)
     218    {
     219        this->defaultValue_[0] = param1;
     220        this->bAddedDefaultValue_[0] = true;
     221        this->defaultValue_[1] = param2;
     222        this->bAddedDefaultValue_[1] = true;
     223        this->defaultValue_[2] = param3;
     224        this->bAddedDefaultValue_[2] = true;
     225        this->defaultValue_[3] = param4;
     226        this->bAddedDefaultValue_[3] = true;
     227        this->defaultValue_[4] = param5;
     228        this->bAddedDefaultValue_[4] = true;
     229
     230        return (*this);
     231    }
     232
     233    Executor& Executor::setDefaultValue(unsigned int index, const MultiTypeMath& param)
     234    {
     235        if (index >= 0 && index < MAX_FUNCTOR_ARGUMENTS)
     236        {
     237            this->defaultValue_[index] = param;
     238            this->bAddedDefaultValue_[index] = true;
     239        }
     240        return (*this);
     241    }
     242
     243    bool Executor::allDefaultValuesSet() const
     244    {
     245        for (unsigned int i = 0; i < this->functor_->getParamCount(); i++)
     246            if (!this->bAddedDefaultValue_[i])
     247                return false;
     248
     249        return true;
     250    }
    118251}
Note: See TracChangeset for help on using the changeset viewer.