Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 953 was 947, checked in by landauf, 16 years ago
  • added CommandExecutor
  • added ConsoleCommand macros
  • added getTypename to all MultiTypes
  • added 2 static maps to Identifier that contain all existing Identifiers with their names and lowercase names respectively.
  • added 2 maps to each Identifier that contain all console commands of the Identifier with their names and lowercase names respectively
  • using tolower(.) and toupper(.) instead of selfmade hacks in String.h
  • added AccessLevel enum
  • added some test-console-commands to OutputHandler, Ambient and SpaceShip
File size: 6.4 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, AccessLevel::Level level)
35    {
36        this->functor_ = functor;
37        this->name_ = name;
38        this->accessLevel_ = level;
39
40        this->bAddedDescription_ = false;
41        this->bAddedDescriptionReturnvalue_ = false;
42
43        this->bAddedDescriptionParam_[0] = false;
44        this->bAddedDescriptionParam_[1] = false;
45        this->bAddedDescriptionParam_[2] = false;
46        this->bAddedDescriptionParam_[3] = false;
47        this->bAddedDescriptionParam_[4] = false;
48
49        this->bAddedDefaultValue_[0] = false;
50        this->bAddedDefaultValue_[1] = false;
51        this->bAddedDefaultValue_[2] = false;
52        this->bAddedDefaultValue_[3] = false;
53        this->bAddedDefaultValue_[4] = false;
54    }
55
56    Executor::~Executor()
57    {
58        delete this->functor_;
59    }
60
61    bool Executor::parse(const std::string& params, const std::string& delimiter) const
62    {
63        EXECUTOR_PARSE(normal);
64    }
65
66    void Executor::setDescription(const std::string& description)
67    {
68        if (!this->bAddedDescription_)
69        {
70            this->description_ = std::string("ExecutorDescription::" + this->name_ + "::function");
71            AddLanguageEntry(this->description_, description);
72            this->bAddedDescription_ = true;
73        }
74    }
75
76    const std::string& Executor::getDescription() const
77    {
78        return GetLocalisation(this->description_);
79    }
80
81    void Executor::setDescriptionParam(int param, const std::string& description)
82    {
83        if (param >= 0 && param < MAX_FUNCTOR_ARGUMENTS)
84        {
85            if (!this->bAddedDescriptionParam_[param])
86            {
87                std::string paramnumber;
88                if (!Convert::ToString(&paramnumber, param))
89                    return;
90
91                this->descriptionParam_[param] = std::string("ExecutorDescription::" + this->name_ + "::param" + paramnumber);
92                AddLanguageEntry(this->descriptionParam_[param], description);
93                this->bAddedDescriptionParam_[param] = true;
94            }
95        }
96    }
97
98    const std::string& Executor::getDescriptionParam(int param) const
99    {
100        if (param >= 0 && param < MAX_FUNCTOR_ARGUMENTS)
101            return GetLocalisation(this->descriptionParam_[param]);
102
103        return this->descriptionParam_[0];
104    }
105
106    void Executor::setDescriptionReturnvalue(const std::string& description)
107    {
108        if (!this->bAddedDescriptionReturnvalue_)
109        {
110            this->descriptionReturnvalue_ = std::string("ExecutorDescription::" + this->name_ + "::returnvalue");
111            AddLanguageEntry(this->descriptionReturnvalue_, description);
112            this->bAddedDescriptionReturnvalue_ = true;
113        }
114    }
115
116    const std::string& Executor::getDescriptionReturnvalue(int param) const
117    {
118        return GetLocalisation(this->descriptionReturnvalue_);
119    }
120
121    void Executor::setDefaultValues(const MultiTypeMath& param1)
122    {
123        this->defaultValue_[0] = param1;
124        this->bAddedDefaultValue_[0] = true;
125    }
126
127    void Executor::setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2)
128    {
129        this->defaultValue_[0] = param1;
130        this->bAddedDefaultValue_[0] = true;
131        this->defaultValue_[1] = param2;
132        this->bAddedDefaultValue_[1] = true;
133    }
134
135    void Executor::setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3)
136    {
137        this->defaultValue_[0] = param1;
138        this->bAddedDefaultValue_[0] = true;
139        this->defaultValue_[1] = param2;
140        this->bAddedDefaultValue_[1] = true;
141        this->defaultValue_[2] = param3;
142        this->bAddedDefaultValue_[2] = true;
143    }
144
145    void Executor::setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3, const MultiTypeMath& param4)
146    {
147        this->defaultValue_[0] = param1;
148        this->bAddedDefaultValue_[0] = true;
149        this->defaultValue_[1] = param2;
150        this->bAddedDefaultValue_[1] = true;
151        this->defaultValue_[2] = param3;
152        this->bAddedDefaultValue_[2] = true;
153        this->defaultValue_[3] = param4;
154        this->bAddedDefaultValue_[3] = true;
155    }
156
157    void Executor::setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3, const MultiTypeMath& param4, const MultiTypeMath& param5)
158    {
159        this->defaultValue_[0] = param1;
160        this->bAddedDefaultValue_[0] = true;
161        this->defaultValue_[1] = param2;
162        this->bAddedDefaultValue_[1] = true;
163        this->defaultValue_[2] = param3;
164        this->bAddedDefaultValue_[2] = true;
165        this->defaultValue_[3] = param4;
166        this->bAddedDefaultValue_[3] = true;
167        this->defaultValue_[4] = param5;
168        this->bAddedDefaultValue_[4] = true;
169    }
170
171    void Executor::setDefaultValue(unsigned int index, const MultiTypeMath& param)
172    {
173        if (index >= 0 && index < MAX_FUNCTOR_ARGUMENTS)
174        {
175            this->defaultValue_[index] = param;
176            this->bAddedDefaultValue_[index] = true;
177        }
178    }
179
180    bool Executor::allDefaultValuesSet() const
181    {
182        for (unsigned int i = 0; i < this->functor_->getParamCount(); i++)
183            if (!this->bAddedDefaultValue_[i])
184                return false;
185
186        return true;
187    }
188}
Note: See TracBrowser for help on using the repository browser.