[Orxonox-commit 2480] r7187 - in code/branches/consolecommands3/src/libraries: core util
landauf at orxonox.net
landauf at orxonox.net
Thu Aug 19 02:42:40 CEST 2010
Author: landauf
Date: 2010-08-19 02:42:40 +0200 (Thu, 19 Aug 2010)
New Revision: 7187
Modified:
code/branches/consolecommands3/src/libraries/core/Executor.cc
code/branches/consolecommands3/src/libraries/core/Executor.h
code/branches/consolecommands3/src/libraries/util/MultiType.h
Log:
added new function to MultiType to check whether or not it contains a value. using this in executor to improve handling of default values.
Modified: code/branches/consolecommands3/src/libraries/core/Executor.cc
===================================================================
--- code/branches/consolecommands3/src/libraries/core/Executor.cc 2010-08-19 00:14:54 UTC (rev 7186)
+++ code/branches/consolecommands3/src/libraries/core/Executor.cc 2010-08-19 00:42:40 UTC (rev 7187)
@@ -42,12 +42,6 @@
{
this->functor_ = functor;
this->name_ = name;
-
- this->bAddedDefaultValue_[0] = false;
- this->bAddedDefaultValue_[1] = false;
- this->bAddedDefaultValue_[2] = false;
- this->bAddedDefaultValue_[3] = false;
- this->bAddedDefaultValue_[4] = false;
}
Executor::~Executor()
@@ -72,7 +66,7 @@
COUT(5) << "Calling Executor " << this->name_ << " through parser with one parameter, using whole string: " << params << std::endl;
(*this->functor_)(MultiType(params));
}
- else if (this->bAddedDefaultValue_[0])
+ else if (!this->defaultValue_[0].null())
{
COUT(5) << "Calling Executor " << this->name_ << " through parser with one parameter, using default value: " << this->defaultValue_[0] << std::endl;
(*this->functor_)(this->defaultValue_[0]);
@@ -89,7 +83,7 @@
for (unsigned int i = tokens.size(); i < this->functor_->getParamCount(); i++)
{
- if (!this->bAddedDefaultValue_[i])
+ if (this->defaultValue_[i].null())
{
COUT(2) << "Warning: Can't call executor " << this->name_ << " through parser: Not enough parameters or default values given (input:" << params << ")." << std::endl;
return false;
@@ -155,7 +149,7 @@
this->functor_->evaluateParam(0, param[0]);
return true;
}
- else if (this->bAddedDefaultValue_[0])
+ else if (!this->defaultValue_[0].null())
{
param[0] = this->defaultValue_[0];
this->functor_->evaluateParam(0, param[0]);
@@ -170,7 +164,7 @@
// if there are not enough params given, check if there are default values
for (unsigned int i = tokens.size(); i < this->functor_->getParamCount(); i++)
- if (!this->bAddedDefaultValue_[i])
+ if (this->defaultValue_[i].null())
return false;
// assign all given arguments to the multitypes
@@ -192,7 +186,6 @@
Executor& Executor::setDefaultValues(const MultiType& param1)
{
this->defaultValue_[0] = param1;
- this->bAddedDefaultValue_[0] = true;
return (*this);
}
@@ -200,9 +193,7 @@
Executor& Executor::setDefaultValues(const MultiType& param1, const MultiType& param2)
{
this->defaultValue_[0] = param1;
- this->bAddedDefaultValue_[0] = true;
this->defaultValue_[1] = param2;
- this->bAddedDefaultValue_[1] = true;
return (*this);
}
@@ -210,11 +201,8 @@
Executor& Executor::setDefaultValues(const MultiType& param1, const MultiType& param2, const MultiType& param3)
{
this->defaultValue_[0] = param1;
- this->bAddedDefaultValue_[0] = true;
this->defaultValue_[1] = param2;
- this->bAddedDefaultValue_[1] = true;
this->defaultValue_[2] = param3;
- this->bAddedDefaultValue_[2] = true;
return (*this);
}
@@ -222,13 +210,9 @@
Executor& Executor::setDefaultValues(const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4)
{
this->defaultValue_[0] = param1;
- this->bAddedDefaultValue_[0] = true;
this->defaultValue_[1] = param2;
- this->bAddedDefaultValue_[1] = true;
this->defaultValue_[2] = param3;
- this->bAddedDefaultValue_[2] = true;
this->defaultValue_[3] = param4;
- this->bAddedDefaultValue_[3] = true;
return (*this);
}
@@ -236,15 +220,10 @@
Executor& Executor::setDefaultValues(const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType& param5)
{
this->defaultValue_[0] = param1;
- this->bAddedDefaultValue_[0] = true;
this->defaultValue_[1] = param2;
- this->bAddedDefaultValue_[1] = true;
this->defaultValue_[2] = param3;
- this->bAddedDefaultValue_[2] = true;
this->defaultValue_[3] = param4;
- this->bAddedDefaultValue_[3] = true;
this->defaultValue_[4] = param5;
- this->bAddedDefaultValue_[4] = true;
return (*this);
}
@@ -252,17 +231,15 @@
Executor& Executor::setDefaultValue(unsigned int index, const MultiType& param)
{
if (index < MAX_FUNCTOR_ARGUMENTS)
- {
this->defaultValue_[index] = param;
- this->bAddedDefaultValue_[index] = true;
- }
+
return (*this);
}
bool Executor::allDefaultValuesSet() const
{
for (unsigned int i = 0; i < this->functor_->getParamCount(); i++)
- if (!this->bAddedDefaultValue_[i])
+ if (this->defaultValue_[i].null())
return false;
return true;
Modified: code/branches/consolecommands3/src/libraries/core/Executor.h
===================================================================
--- code/branches/consolecommands3/src/libraries/core/Executor.h 2010-08-19 00:14:54 UTC (rev 7186)
+++ code/branches/consolecommands3/src/libraries/core/Executor.h 2010-08-19 00:42:40 UTC (rev 7187)
@@ -100,7 +100,7 @@
inline bool defaultValueSet(unsigned int index) const
{
if (index < MAX_FUNCTOR_ARGUMENTS)
- return this->bAddedDefaultValue_[index];
+ return !this->defaultValue_[index].null();
return false;
}
@@ -109,7 +109,6 @@
Functor* functor_;
std::string name_;
MultiType defaultValue_[MAX_FUNCTOR_ARGUMENTS];
- bool bAddedDefaultValue_[MAX_FUNCTOR_ARGUMENTS];
};
class _CoreExport ExecutorStatic : public Executor
Modified: code/branches/consolecommands3/src/libraries/util/MultiType.h
===================================================================
--- code/branches/consolecommands3/src/libraries/util/MultiType.h 2010-08-19 00:14:54 UTC (rev 7186)
+++ code/branches/consolecommands3/src/libraries/util/MultiType.h 2010-08-19 00:42:40 UTC (rev 7187)
@@ -350,8 +350,11 @@
inline uint32_t getNetworkSize() const { assert(this->value_); return this->value_->getSize() + sizeof(uint8_t); }
/** @brief Checks whether the value is a default one. */
- bool hasDefaultValue() const { return this->value_->hasDefaultValue(); }
+ bool hasDefaultValue() const { return this->value_->hasDefaultValue(); }
+ /** @brief Checks if the MT contains no value. */
+ bool null() const { return (!this->value_); }
+
operator char() const;
operator unsigned char() const;
operator short() const;
More information about the Orxonox-commit
mailing list