Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 967 for code


Ignore:
Timestamp:
Mar 31, 2008, 12:25:09 AM (17 years ago)
Author:
landauf
Message:

hum, i forgot what i was doing there… oh wait, i remember… it had something to do with executor evaluation. strange thing, no wonder my brain has a leak or something… what's that SVN thing all around my cursor? what's a cursor anyway? oh, and what am i doing here? i feel like having breakfast and it's all dark… stupid clock change…

Location:
code/branches/core2/src/orxonox/core
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core2/src/orxonox/core/CommandExecutor.cc

    r965 r967  
    6363        this->errorMessage_ = "";
    6464        this->state_ = CS_Uninitialized;
     65
     66        this->bEvaluatedParams_ = false;
     67        this->evaluatedExecutor_ = 0;
    6568    }
    6669
     
    113116            return false;
    114117        }
     118    }
     119
     120    void CommandEvaluation::evaluateParams()
     121    {
     122        this->bEvaluatedParams_ = false;
     123        this->evaluatedExecutor_ = 0;
     124
     125        for (unsigned int i = 0; i < MAX_FUNCTOR_ARGUMENTS; i++)
     126            this->param_[i] = MT_null;
     127
     128        if (this->state_ == CS_Shortcut_Params || this->state_ == CS_Shortcut_Finished)
     129        {
     130            if (this->shortcut_ != 0)
     131            {
     132                if (this->shortcut_->evaluate(this->processedCommand_ + this->getAdditionalParameter(), this->param_, " "))
     133                {
     134                    this->bEvaluatedParams_ = true;
     135                    this->evaluatedExecutor_ = this->shortcut_;
     136                }
     137            }
     138        }
     139        else if (this->state_ == CS_Function_Params || this->state_ == CS_Function_Finished)
     140        {
     141            if (this->function_ != 0)
     142            {
     143                if (this->function_->evaluate(this->processedCommand_ + this->getAdditionalParameter(), this->param_, " "))
     144                {
     145                    this->bEvaluatedParams_ = true;
     146                    this->evaluatedExecutor_ = this->function_;
     147                }
     148            }
     149        }
     150    }
     151
     152    void CommandEvaluation::setEvaluatedParameter(unsigned int index, MultiTypeMath param)
     153    {
     154        if (index >= 0 && index < MAX_FUNCTOR_ARGUMENTS)
     155            this->param_[index] = param;
     156    }
     157
     158    MultiTypeMath CommandEvaluation::getEvaluatedParameter(unsigned int index) const
     159    {
     160        if (index >= 0 && index < MAX_FUNCTOR_ARGUMENTS)
     161            return this->param_[index];
     162
     163        return MT_null;
    115164    }
    116165
     
    178227        SubString tokens(evaluation.processedCommand_, " ", SubString::WhiteSpaces, false, '\\', '"', '(', ')', '\0');
    179228
     229        if (evaluation.bEvaluatedParams_ && evaluation.evaluatedExecutor_ != 0)
     230        {
     231            (*evaluation.evaluatedExecutor_)(evaluation.param_[0], evaluation.param_[1], evaluation.param_[2], evaluation.param_[3], evaluation.param_[4]);
     232        }
     233
    180234        switch (evaluation.state_)
    181235        {
     
    404458    {
    405459        CommandExecutor::parse(command, true);
     460        CommandExecutor::getEvaluation().evaluateParams();
    406461        return CommandExecutor::getEvaluation();
    407462    }
  • code/branches/core2/src/orxonox/core/CommandExecutor.h

    r965 r967  
    7777
    7878            inline void setAdditionalParameter(const std::string& param)
    79                 { this->additionalParameter_ = param; }
     79                { this->additionalParameter_ = param; this->bEvaluatedParams_ = false; }
    8080            inline std::string getAdditionalParameter() const
    8181                { return (this->additionalParameter_ != "") ? (" " + this->additionalParameter_) : ""; }
     82
     83            void setEvaluatedParameter(unsigned int index, MultiTypeMath param);
     84            MultiTypeMath getEvaluatedParameter(unsigned int index) const;
     85
     86            void evaluateParams();
    8287
    8388        private:
     
    102107            std::string errorMessage_;
    103108            CommandState state_;
     109
     110            bool bEvaluatedParams_;
     111            MultiTypeMath param_[5];
     112            ExecutorStatic* evaluatedExecutor_;
    104113    };
    105114
  • code/branches/core2/src/orxonox/core/Executor.cc

    r957 r967  
    2929#include "Executor.h"
    3030#include "Language.h"
     31#include "util/Math.h"
    3132
    3233namespace orxonox
     
    6263    {
    6364        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, '\\', '"', '(', ')', '\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        }
    64113    }
    65114
  • code/branches/core2/src/orxonox/core/Executor.h

    r957 r967  
    8989        MultiTypeMath param[paramCount]; \
    9090        COUT(5) << "Calling Executor " << this->name_ << " through parser with " << paramCount << " parameters, using " << tokens.size() << " tokens ("; \
    91         for (unsigned int i = 0; i < tokens.size(); i++) \
     91        for (unsigned int i = 0; i < tokens.size() && i < MAX_FUNCTOR_ARGUMENTS; i++) \
    9292        { \
    9393            param[i] = tokens[i]; \
     
    165165            bool parse(const std::string& params, const std::string& delimiter = " ") const;
    166166
     167            bool evaluate(const std::string& params, MultiTypeMath param[5], const std::string& delimiter = " ") const;
     168
    167169            Executor& setDescription(const std::string& description);
    168170            const std::string& getDescription() const;
  • code/branches/core2/src/orxonox/core/Functor.h

    r955 r967  
    103103            std::string getTypenameParam(unsigned int param) const { return (param >= 0 && param < 5) ? this->typeParam_[param] : ""; }
    104104            std::string getTypenameReturnvalue() const { return this->typeReturnvalue_; }
     105
     106            virtual void evaluateParam(unsigned int index, MultiTypeMath& param) const = 0;
    105107
    106108        protected:
     
    278280
    279281
     282#define FUNCTOR_EVALUATE_PARAM(numparams) FUNCTOR_EVALUATE_PARAM##numparams
     283#define FUNCTOR_EVALUATE_PARAM0
     284#define FUNCTOR_EVALUATE_PARAM1 \
     285    if (index == 0) param = (P1)param
     286#define FUNCTOR_EVALUATE_PARAM2 \
     287    if (index == 0) param = (P1)param; \
     288    else if (index == 1) param = (P2)param
     289#define FUNCTOR_EVALUATE_PARAM3 \
     290    if (index == 0) param = (P1)param; \
     291    else if (index == 1) param = (P2)param; \
     292    else if (index == 2) param = (P3)param
     293#define FUNCTOR_EVALUATE_PARAM4 \
     294    if (index == 0) param = (P1)param; \
     295    else if (index == 1) param = (P2)param; \
     296    else if (index == 2) param = (P3)param; \
     297    else if (index == 3) param = (P4)param
     298#define FUNCTOR_EVALUATE_PARAM5 \
     299    if (index == 0) param = (P1)param; \
     300    else if (index == 1) param = (P2)param; \
     301    else if (index == 2) param = (P3)param; \
     302    else if (index == 3) param = (P4)param; \
     303    else if (index == 4) param = (P5)param
     304
     305
     306
    280307
    281308
     
    301328            } \
    302329    \
     330            virtual void evaluateParam(unsigned int index, MultiTypeMath& param) const \
     331            { \
     332                FUNCTOR_EVALUATE_PARAM(numparams); \
     333            } \
     334    \
    303335        private: \
    304336            FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (*functionPointer_)(FUNCTOR_FUNCTION_PARAMS(numparams)); \
     
    340372            } \
    341373    \
     374            virtual void evaluateParam(unsigned int index, MultiTypeMath& param) const \
     375            { \
     376                FUNCTOR_EVALUATE_PARAM(numparams); \
     377            } \
     378    \
    342379        private: \
    343380            FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer_)(FUNCTOR_FUNCTION_PARAMS(numparams)); \
     
    365402            { \
    366403                FUNCTOR_STORE_RETURNVALUE(returnvalue, (*object.*this->functionPointer_)(FUNCTOR_FUNCTION_CALL(numparams))); \
     404            } \
     405    \
     406            virtual void evaluateParam(unsigned int index, MultiTypeMath& param) const \
     407            { \
     408                FUNCTOR_EVALUATE_PARAM(numparams); \
    367409            } \
    368410    \
Note: See TracChangeset for help on using the changeset viewer.