Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core2/src/orxonox/core/Executor.cc @ 939

Last change on this file since 939 was 939, checked in by landauf, 16 years ago
  • 3 times the (almost) same implementation + macro
File size: 6.6 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *
4 *
5 *   License notice:
6 *
7 *   This program is free software; you can redistribute it and/or
8 *   modify it under the terms of the GNU General Public License
9 *   as published by the Free Software Foundation; either version 2
10 *   of the License, or (at your option) any later version.
11 *
12 *   This program is distributed in the hope that it will be useful,
13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 *   GNU General Public License for more details.
16 *
17 *   You should have received a copy of the GNU General Public License
18 *   along with this program; if not, write to the Free Software
19 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 *
21 *   Author:
22 *      Fabian 'x3n' Landau
23 *   Co-authors:
24 *      ...
25 *
26 *   Inspiration: Executor by Benjamin Grauer
27 */
28
29#include "Executor.h"
30#include "Language.h"
31
32namespace orxonox
33{
34    Executor::Executor(Functor* functor, const std::string& name)
35    {
36        this->functor_ = functor;
37        this->name_ = name;
38        this->bAddedDescription_ = false;
39        this->bAddedDescriptionReturnvalue_ = false;
40
41        this->bAddedDescriptionParam_[0] = false;
42        this->bAddedDescriptionParam_[1] = false;
43        this->bAddedDescriptionParam_[2] = false;
44        this->bAddedDescriptionParam_[3] = false;
45        this->bAddedDescriptionParam_[4] = false;
46
47        this->bAddedDefaultValue_[0] = false;
48        this->bAddedDefaultValue_[1] = false;
49        this->bAddedDefaultValue_[2] = false;
50        this->bAddedDefaultValue_[3] = false;
51        this->bAddedDefaultValue_[4] = false;
52    }
53
54    Executor::~Executor()
55    {
56        delete this->functor_;
57    }
58
59    bool Executor::parse(const std::string& params, const std::string& delimiter) const
60    {
61        EXECUTOR_PARSE(normal);
62    }
63
64    void Executor::setName(const std::string name)
65    {
66        this->name_ = name;
67    }
68
69    const std::string& Executor::getName() const
70    {
71        return this->name_;
72    }
73
74    void Executor::setDescription(const std::string& description)
75    {
76        if (!this->bAddedDescription_)
77        {
78            this->description_ = std::string("ExecutorDescription::" + this->name_ + "::function");
79            AddLanguageEntry(this->description_, description);
80            this->bAddedDescription_ = true;
81        }
82    }
83
84    const std::string& Executor::getDescription() const
85    {
86        return GetLocalisation(this->description_);
87    }
88
89    void Executor::setDescriptionParam(int param, const std::string& description)
90    {
91        if (param >= 0 && param < MAX_FUNCTOR_ARGUMENTS)
92        {
93            if (!this->bAddedDescriptionParam_[param])
94            {
95                std::string paramnumber;
96                if (!Convert::ToString(&paramnumber, param))
97                    return;
98
99                this->descriptionParam_[param] = std::string("ExecutorDescription::" + this->name_ + "::param" + paramnumber);
100                AddLanguageEntry(this->descriptionParam_[param], description);
101                this->bAddedDescriptionParam_[param] = true;
102            }
103        }
104    }
105
106    const std::string& Executor::getDescriptionParam(int param) const
107    {
108        if (param >= 0 && param < MAX_FUNCTOR_ARGUMENTS)
109            return GetLocalisation(this->descriptionParam_[param]);
110
111        return this->descriptionParam_[0];
112    }
113
114    void Executor::setDescriptionReturnvalue(const std::string& description)
115    {
116        if (!this->bAddedDescriptionReturnvalue_)
117        {
118            this->descriptionReturnvalue_ = std::string("ExecutorDescription::" + this->name_ + "::returnvalue");
119            AddLanguageEntry(this->descriptionReturnvalue_, description);
120            this->bAddedDescriptionReturnvalue_ = true;
121        }
122    }
123
124    const std::string& Executor::getDescriptionReturnvalue(int param) const
125    {
126        return GetLocalisation(this->descriptionReturnvalue_);
127    }
128
129    void Executor::setDefaultValues(const MultiTypeMath& param1)
130    {
131        this->defaultValue_[0] = param1;
132        this->bAddedDefaultValue_[0] = true;
133    }
134
135    void Executor::setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2)
136    {
137        this->defaultValue_[0] = param1;
138        this->bAddedDefaultValue_[0] = true;
139        this->defaultValue_[1] = param2;
140        this->bAddedDefaultValue_[1] = true;
141    }
142
143    void Executor::setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3)
144    {
145        this->defaultValue_[0] = param1;
146        this->bAddedDefaultValue_[0] = true;
147        this->defaultValue_[1] = param2;
148        this->bAddedDefaultValue_[1] = true;
149        this->defaultValue_[2] = param3;
150        this->bAddedDefaultValue_[2] = true;
151    }
152
153    void Executor::setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3, const MultiTypeMath& param4)
154    {
155        this->defaultValue_[0] = param1;
156        this->bAddedDefaultValue_[0] = true;
157        this->defaultValue_[1] = param2;
158        this->bAddedDefaultValue_[1] = true;
159        this->defaultValue_[2] = param3;
160        this->bAddedDefaultValue_[2] = true;
161        this->defaultValue_[3] = param4;
162        this->bAddedDefaultValue_[3] = true;
163    }
164
165    void Executor::setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3, const MultiTypeMath& param4, const MultiTypeMath& param5)
166    {
167        this->defaultValue_[0] = param1;
168        this->bAddedDefaultValue_[0] = true;
169        this->defaultValue_[1] = param2;
170        this->bAddedDefaultValue_[1] = true;
171        this->defaultValue_[2] = param3;
172        this->bAddedDefaultValue_[2] = true;
173        this->defaultValue_[3] = param4;
174        this->bAddedDefaultValue_[3] = true;
175        this->defaultValue_[4] = param5;
176        this->bAddedDefaultValue_[4] = true;
177    }
178
179    void Executor::setDefaultValue(unsigned int index, const MultiTypeMath& param)
180    {
181        if (index >= 0 && index < MAX_FUNCTOR_ARGUMENTS)
182        {
183            this->defaultValue_[index] = param;
184            this->bAddedDefaultValue_[index] = true;
185        }
186    }
187
188    bool Executor::allDefaultValuesSet() const
189    {
190        for (unsigned int i = 0; i < this->functor_->getParamCount(); i++)
191            if (!this->bAddedDefaultValue_[i])
192                return false;
193
194        return true;
195    }
196}
Note: See TracBrowser for help on using the repository browser.