Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 931


Ignore:
Timestamp:
Mar 27, 2008, 3:56:13 AM (16 years ago)
Author:
landauf
Message:

expanded Executor

Location:
code/branches/core2/src
Files:
9 edited

Legend:

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

    r871 r931  
    3939        this->bAddedDescription_ = false;
    4040        this->bAddedDescriptionReturnvalue_ = false;
     41
    4142        this->bAddedDescriptionParam_[0] = false;
    4243        this->bAddedDescriptionParam_[1] = false;
     
    4445        this->bAddedDescriptionParam_[3] = false;
    4546        this->bAddedDescriptionParam_[4] = false;
     47
     48        this->bAddedDefaultValue_[0] = false;
     49        this->bAddedDefaultValue_[1] = false;
     50        this->bAddedDefaultValue_[2] = false;
     51        this->bAddedDefaultValue_[3] = false;
     52        this->bAddedDefaultValue_[4] = false;
    4653    }
    4754
    4855    Executor::~Executor()
    4956    {
     57        delete this->functor_;
     58    }
     59
     60    bool Executor::parse(const std::string& params, const std::string& delimiter) const
     61    {
     62        unsigned int paramCount = this->functor_->getParamCount();
     63
     64        if (paramCount == 0)
     65        {
     66            (*this->functor_)();
     67        }
     68        else if (paramCount == 1)
     69        {
     70            (*this->functor_)(MultiTypeMath(params));
     71        }
     72        else
     73        {
     74            SubString tokens(params, delimiter, SubString::WhiteSpaces, false, '\\', '"', '(', ')', '\0');
     75
     76            for (unsigned int i = tokens.size(); i < this->functor_->getParamCount(); i++)
     77                if (!this->bAddedDefaultValue_[i])
     78                    return false;
     79
     80            MultiTypeMath param[paramCount];
     81            for (unsigned int i = 0; i < tokens.size(); i++)
     82                param[i] = tokens[i];
     83            for (unsigned int i = tokens.size(); i < paramCount; i++)
     84                param[i] = this->defaultValue_[i];
     85
     86            switch(paramCount)
     87            {
     88                case 2:
     89                    (*this->functor_)(param[0], param[1]);
     90                    break;
     91                case 3:
     92                    (*this->functor_)(param[0], param[1], param[2]);
     93                    break;
     94                case 4:
     95                    (*this->functor_)(param[0], param[1], param[2], param[3]);
     96                    break;
     97                case 5:
     98                    (*this->functor_)(param[0], param[1], param[2], param[3], param[4]);
     99                    break;
     100            }
     101        }
     102
     103        return true;
    50104    }
    51105
     
    77131    void Executor::descriptionParam(int param, const std::string& description)
    78132    {
    79         if (param > 0 && param <= 5)
     133        if (param >= 0 && param < MAX_FUNCTOR_ARGUMENTS)
    80134        {
    81135            if (!this->bAddedDescriptionParam_[param])
     
    94148    const std::string& Executor::getDescriptionParam(int param) const
    95149    {
    96         if (param > 0 && param <= 5)
    97         {
     150        if (param >= 0 && param < MAX_FUNCTOR_ARGUMENTS)
    98151            return GetLocalisation(this->descriptionParam_[param]);
    99         }
    100152
    101153        return this->descriptionParam_[0];
     
    116168        return GetLocalisation(this->descriptionReturnvalue_);
    117169    }
     170
     171    void Executor::setDefaultValues(const MultiTypeMath& param1)
     172    {
     173        this->defaultValue_[0] = param1;
     174        this->bAddedDefaultValue_[0] = true;
     175    }
     176
     177    void Executor::setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2)
     178    {
     179        this->defaultValue_[0] = param1;
     180        this->bAddedDefaultValue_[0] = true;
     181        this->defaultValue_[1] = param2;
     182        this->bAddedDefaultValue_[1] = true;
     183    }
     184
     185    void Executor::setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3)
     186    {
     187        this->defaultValue_[0] = param1;
     188        this->bAddedDefaultValue_[0] = true;
     189        this->defaultValue_[1] = param2;
     190        this->bAddedDefaultValue_[1] = true;
     191        this->defaultValue_[2] = param3;
     192        this->bAddedDefaultValue_[2] = true;
     193    }
     194
     195    void Executor::setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3, const MultiTypeMath& param4)
     196    {
     197        this->defaultValue_[0] = param1;
     198        this->bAddedDefaultValue_[0] = true;
     199        this->defaultValue_[1] = param2;
     200        this->bAddedDefaultValue_[1] = true;
     201        this->defaultValue_[2] = param3;
     202        this->bAddedDefaultValue_[2] = true;
     203        this->defaultValue_[3] = param4;
     204        this->bAddedDefaultValue_[3] = true;
     205    }
     206
     207    void Executor::setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3, const MultiTypeMath& param4, const MultiTypeMath& param5)
     208    {
     209        this->defaultValue_[0] = param1;
     210        this->bAddedDefaultValue_[0] = true;
     211        this->defaultValue_[1] = param2;
     212        this->bAddedDefaultValue_[1] = true;
     213        this->defaultValue_[2] = param3;
     214        this->bAddedDefaultValue_[2] = true;
     215        this->defaultValue_[3] = param4;
     216        this->bAddedDefaultValue_[3] = true;
     217        this->defaultValue_[4] = param5;
     218        this->bAddedDefaultValue_[4] = true;
     219    }
     220
     221    void Executor::setDefaultValue(int index, const MultiTypeMath& param)
     222    {
     223        if (index >= 0 && index < MAX_FUNCTOR_ARGUMENTS)
     224        {
     225            this->defaultValue_[index] = param;
     226            this->bAddedDefaultValue_[index] = true;
     227        }
     228    }
    118229}
  • code/branches/core2/src/orxonox/core/Executor.h

    r871 r931  
    3232#include "CorePrereqs.h"
    3333#include "Functor.h"
     34#include "util/SubString.h"
     35
    3436
    3537namespace orxonox
     
    4143            virtual ~Executor();
    4244
    43             inline virtual void operator()(const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null)
     45            inline void operator()() const
     46                { (*this->functor_)(this->defaultValue_[0], this->defaultValue_[1], this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); }
     47            inline void operator()(const MultiTypeMath& param1) const
     48                { (*this->functor_)(param1, this->defaultValue_[1], this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); }
     49            inline void operator()(const MultiTypeMath& param1, const MultiTypeMath& param2) const
     50                { (*this->functor_)(param1, param2, this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); }
     51            inline void operator()(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3) const
     52                { (*this->functor_)(param1, param2, param3, this->defaultValue_[3], this->defaultValue_[4]); }
     53            inline void operator()(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3, const MultiTypeMath& param4) const
     54                { (*this->functor_)(param1, param2, param3, param4, this->defaultValue_[4]); }
     55            inline void operator()(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3, const MultiTypeMath& param4, const MultiTypeMath& param5) const
    4456                { (*this->functor_)(param1, param2, param3, param4, param5); }
     57
     58            bool parse(const std::string& params, const std::string& delimiter = " ") const;
    4559
    4660            void setName(const std::string name);
     
    6983                { return this->functor_->getTypenameReturnvalue(); }
    7084
     85            void setDefaultValues(const MultiTypeMath& param1);
     86            void setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2);
     87            void setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3);
     88            void setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3, const MultiTypeMath& param4);
     89            void setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3, const MultiTypeMath& param4, const MultiTypeMath& param5);
     90            void setDefaultValue(int index, const MultiTypeMath& param);
     91
    7192        protected:
    7293            Functor* functor_;
     
    7798            LanguageEntryLabel description_;
    7899            LanguageEntryLabel descriptionReturnvalue_;
    79             LanguageEntryLabel descriptionParam_[5];
     100            LanguageEntryLabel descriptionParam_[MAX_FUNCTOR_ARGUMENTS];
    80101
    81102            bool bAddedDescription_;
    82103            bool bAddedDescriptionReturnvalue_;
    83             bool bAddedDescriptionParam_[5];
     104            bool bAddedDescriptionParam_[MAX_FUNCTOR_ARGUMENTS];
     105
     106            MultiTypeMath defaultValue_[MAX_FUNCTOR_ARGUMENTS];
     107            bool bAddedDefaultValue_[MAX_FUNCTOR_ARGUMENTS];
    84108    };
    85109
     
    89113            ExecutorStatic(FunctorStatic* functor, const std::string& name = "") : Executor(functor, name) {}
    90114            virtual ~ExecutorStatic() {}
    91 
    92             inline virtual void operator()(const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null)
    93                 { (*this->functor_)(param1, param2, param3, param4, param5); }
    94115    };
    95116
     
    101122            virtual ~ExecutorMember() {}
    102123
    103             inline virtual void operator()(T* object, const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null)
    104                 { (*this->functor_)(object, param1, param2, param3, param4, param5); }
    105             inline virtual void operator()(const T* object, const MultiTypeMath param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null)
    106                 { (*this->functor_)(object, param1, param2, param3, param4, param5); }
    107             inline virtual void operator()(const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null)
    108                 { (*this->functor_)(param1, param2, param3, param4, param5); }
    109 
    110             inline void setObject(T* object)
    111                 { this->functor_->setObject(object); }
    112             inline void setObject(const T* object)
    113                 { this->functor_->setObject(object); }
     124            inline void operator()(T* object) const
     125                { (*((FunctorMember<T>*)this->functor_))(object, this->defaultValue_[0], this->defaultValue_[1], this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); }
     126            inline void operator()(T* object, const MultiTypeMath& param1) const
     127                { (*((FunctorMember<T>*)this->functor_))(object, param1, this->defaultValue_[1], this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); }
     128            inline void operator()(T* object, const MultiTypeMath& param1, const MultiTypeMath& param2) const
     129                { (*((FunctorMember<T>*)this->functor_))(object, param1, param2, this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); }
     130            inline void operator()(T* object, const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3) const
     131                { (*((FunctorMember<T>*)this->functor_))(object, param1, param2, param3, this->defaultValue_[3], this->defaultValue_[4]); }
     132            inline void operator()(T* object, const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3, const MultiTypeMath& param4) const
     133                { (*((FunctorMember<T>*)this->functor_))(object, param1, param2, param3, param4, this->defaultValue_[4]); }
     134            inline void operator()(T* object, const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3, const MultiTypeMath& param4, const MultiTypeMath& param5) const
     135                { (*((FunctorMember<T>*)this->functor_))(object, param1, param2, param3, param4, param5); }
     136
     137
     138            inline void operator()(const T* object) const
     139                { (*((FunctorMember<T>*)this->functor_))(object, this->defaultValue_[0], this->defaultValue_[1], this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); }
     140            inline void operator()(const T* object, const MultiTypeMath& param1) const
     141                { (*((FunctorMember<T>*)this->functor_))(object, param1, this->defaultValue_[1], this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); }
     142            inline void operator()(const T* object, const MultiTypeMath& param1, const MultiTypeMath& param2) const
     143                { (*((FunctorMember<T>*)this->functor_))(object, param1, param2, this->defaultValue_[2], this->defaultValue_[3], this->defaultValue_[4]); }
     144            inline void operator()(const T* object, const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3) const
     145                { (*((FunctorMember<T>*)this->functor_))(object, param1, param2, param3, this->defaultValue_[3], this->defaultValue_[4]); }
     146            inline void operator()(const T* object, const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3, const MultiTypeMath& param4) const
     147                { (*((FunctorMember<T>*)this->functor_))(object, param1, param2, param3, param4, this->defaultValue_[4]); }
     148            inline void operator()(const T* object, const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3, const MultiTypeMath& param4, const MultiTypeMath& param5) const
     149                { (*((FunctorMember<T>*)this->functor_))(object, param1, param2, param3, param4, param5); }
     150
     151            inline void setObject(T* object) const
     152                { ((FunctorMember<T>*)this->functor_)->setObject(object); }
     153            inline void setObject(const T* object) const
     154                { ((FunctorMember<T>*)this->functor_)->setObject(object); }
     155
     156            bool parse(T* object, const std::string& params, const std::string& delimiter) const
     157            {
     158                unsigned int paramCount = this->functor_->getParamCount();
     159
     160                if (paramCount == 0)
     161                {
     162                    (*((FunctorMember<T>*)this->functor_))(object);
     163                }
     164                else if (paramCount == 1)
     165                {
     166                    (*((FunctorMember<T>*)this->functor_))(object, MultiTypeMath(params));
     167                }
     168                else
     169                {
     170                    SubString tokens(params, delimiter, SubString::WhiteSpaces, false, '\\', '"', '(', ')', '\0');
     171
     172                    for (unsigned int i = tokens.size(); i < this->functor_->getParamCount(); i++)
     173                        if (!this->bAddedDefaultValue_[i])
     174                            return false;
     175
     176                    MultiTypeMath param[paramCount];
     177                    for (unsigned int i = 0; i < tokens.size(); i++)
     178                        param[i] = tokens[i];
     179                    for (unsigned int i = tokens.size(); i < paramCount; i++)
     180                        param[i] = this->defaultValue_[i];
     181
     182                    switch(paramCount)
     183                    {
     184                        case 2:
     185                            (*((FunctorMember<T>*)this->functor_))(object, param[0], param[1]);
     186                            break;
     187                        case 3:
     188                            (*((FunctorMember<T>*)this->functor_))(object, param[0], param[1], param[2]);
     189                            break;
     190                        case 4:
     191                            (*((FunctorMember<T>*)this->functor_))(object, param[0], param[1], param[2], param[3]);
     192                            break;
     193                        case 5:
     194                            (*((FunctorMember<T>*)this->functor_))(object, param[0], param[1], param[2], param[3], param[4]);
     195                            break;
     196                    }
     197                }
     198
     199                return true;
     200            }
     201
     202            bool parse(const T* object, const std::string& params, const std::string& delimiter) const
     203            {
     204                unsigned int paramCount = this->functor_->getParamCount();
     205
     206                if (paramCount == 0)
     207                {
     208                    (*((FunctorMember<T>*)this->functor_))(object);
     209                }
     210                else if (paramCount == 1)
     211                {
     212                    (*((FunctorMember<T>*)this->functor_))(object, MultiTypeMath(params));
     213                }
     214                else
     215                {
     216                    SubString tokens(params, delimiter, SubString::WhiteSpaces, false, '\\', '"', '(', ')', '\0');
     217
     218                    for (unsigned int i = tokens.size(); i < this->functor_->getParamCount(); i++)
     219                        if (!this->bAddedDefaultValue_[i])
     220                            return false;
     221
     222                    MultiTypeMath param[paramCount];
     223                    for (unsigned int i = 0; i < tokens.size(); i++)
     224                        param[i] = tokens[i];
     225                    for (unsigned int i = tokens.size(); i < paramCount; i++)
     226                        param[i] = this->defaultValue_[i];
     227
     228                    switch(paramCount)
     229                    {
     230                        case 2:
     231                            (*((FunctorMember<T>*)this->functor_))(object, param[0], param[1]);
     232                            break;
     233                        case 3:
     234                            (*((FunctorMember<T>*)this->functor_))(object, param[0], param[1], param[2]);
     235                            break;
     236                        case 4:
     237                            (*((FunctorMember<T>*)this->functor_))(object, param[0], param[1], param[2], param[3]);
     238                            break;
     239                        case 5:
     240                            (*((FunctorMember<T>*)this->functor_))(object, param[0], param[1], param[2], param[3], param[4]);
     241                            break;
     242                    }
     243                }
     244
     245                return true;
     246            }
    114247    };
    115248}
  • code/branches/core2/src/orxonox/core/Functor.h

    r925 r931  
    3535#include "CorePrereqs.h"
    3636
     37#define MAX_FUNCTOR_ARGUMENTS 5
    3738
    3839enum FunctionType
     
    8081        virtual void operator()(const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) = 0;
    8182
    82         inline int getParamCount() const { return this->numParams_; }
     83        inline unsigned int getParamCount() const { return this->numParams_; }
    8384        inline bool hasReturnvalue() const { return this->hasReturnValue_; }
    8485        inline FunctionType getType() const { return this->type_; }
     
    8990
    9091    protected:
    91         int numParams_;
     92        unsigned int numParams_;
    9293        bool hasReturnValue_;
    9394        FunctionType type_;
     
    9596
    9697        std::string typeReturnvalue_;
    97         std::string typeParam_[5];
     98        std::string typeParam_[MAX_FUNCTOR_ARGUMENTS];
    9899};
    99100
  • code/branches/core2/src/orxonox/core/Language.cc

    r871 r931  
    6161    {
    6262        // Check if the translation is more than just an empty string
    63         if (localisation.compare("") != 0)
     63        if ((localisation != "") && (localisation.size() > 0))
    6464        {
    6565            this->localisedEntry_ = localisation;
     
    244244
    245245            // Check if the line is empty
    246             if (lineString.compare("") != 0)
     246            if ((lineString != "") && (lineString.size() > 0))
    247247            {
    248248                unsigned int pos = lineString.find('=');
     
    288288
    289289            // Check if the line is empty
    290             if (lineString.compare("") != 0)
     290            if ((lineString != "") && (lineString.size() > 0))
    291291            {
    292292                unsigned int pos = lineString.find('=');
  • code/branches/core2/src/orxonox/core/XMLPort.h

    r902 r931  
    102102            const std::string& getDescription();
    103103
    104             XMLPortParamContainer& defaultValues(const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null)
    105             {
    106                 this->defaultValues_[0] = param1;
    107                 this->defaultValues_[1] = param2;
    108                 this->defaultValues_[2] = param3;
    109                 this->defaultValues_[3] = param4;
    110                 this->defaultValues_[4] = param5;
    111 
    112                 return (*this);
    113             }
    114 
    115104        protected:
    116105            std::string classname_;
    117106            std::string paramname_;
    118             MultiTypeMath defaultValues_[5];
    119107
    120108        private:
     
    247235                    {
    248236                        Element* xmlsubelement;
    249                         if (this->sectionname_ != "")
     237                        if ((this->sectionname_ != "") && (this->sectionname_.size() > 0))
    250238                            xmlsubelement = xmlelement.FirstChildElement(this->sectionname_, false);
    251239                        else
  • code/branches/core2/src/orxonox/objects/Model.cc

    r902 r931  
    8181    }
    8282
    83     bool Model::create(){
    84       if(meshSrc_.compare("")!=0){
    85         this->mesh_.setMesh(meshSrc_);
    86         this->attachObject(this->mesh_.getEntity());
    87         COUT(4) << "Loader: Created model" << std::endl;
    88       }
    89       registerAllVariables();
    90       return true;
     83    bool Model::create()
     84    {
     85        if ((this->meshSrc_ != "") && (this->meshSrc_.size() > 0))
     86        {
     87            this->mesh_.setMesh(meshSrc_);
     88            this->attachObject(this->mesh_.getEntity());
     89            COUT(4) << "Loader: Created model" << std::endl;
     90        }
     91        registerAllVariables();
     92        return true;
    9193    }
    9294
  • code/branches/core2/src/util/Convert.h

    r925 r931  
    541541};
    542542
    543 
    544 ////////////////
    545 // XMLElement //
    546 ////////////////
    547 
    548 // orxonox::Element to std::string
    549 template <>
    550 class Converter<orxonox::Element, std::string>
    551 {
    552   public:
    553     bool operator()(std::string* output, const orxonox::Element& input) const
    554     {
    555       std::ostringstream ostream;
    556       if (ostream << input)
    557       {
    558         (*output) = ostream.str();
    559         return true;
    560       }
    561 
    562       return false;
    563     }
    564 };
    565 
    566 // std::string to orxonox::Element
    567 template <>
    568 class Converter<std::string, orxonox::Element>
    569 {
    570   public:
    571     bool operator()(orxonox::Element* output, const std::string& input) const
    572     {
    573       std::istringstream istream(input);
    574       if (istream >> (*output))
    575         return true;
    576 
    577       return false;
    578     }
    579 };
    580 
    581 
    582543#endif /* _Convert_H__ */
  • code/branches/core2/src/util/MultiTypeString.cc

    r925 r931  
    3232MultiTypeString::MultiTypeString(MultiType type) : MultiTypePrimitive(type)
    3333{
    34     if (type == MT_constchar)
    35         this->string_ = std::string("");
    36     else if (type == MT_string)
    37         this->string_ = std::string("");
     34    // Nothing to do for string and xml-element
    3835}
    3936
  • code/branches/core2/src/util/String.cc

    r871 r931  
    8383bool isEmpty(const std::string& str)
    8484{
    85     return getStripped(str) == "";
     85    std::string temp = getStripped(str);
     86    return ((temp == "") || (temp.size() == 0));
    8687}
    8788
Note: See TracChangeset for help on using the changeset viewer.