Changeset 931 for code/branches/core2/src
- Timestamp:
- Mar 27, 2008, 3:56:13 AM (17 years ago)
- Location:
- code/branches/core2/src
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core2/src/orxonox/core/Executor.cc
r871 r931 39 39 this->bAddedDescription_ = false; 40 40 this->bAddedDescriptionReturnvalue_ = false; 41 41 42 this->bAddedDescriptionParam_[0] = false; 42 43 this->bAddedDescriptionParam_[1] = false; … … 44 45 this->bAddedDescriptionParam_[3] = false; 45 46 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; 46 53 } 47 54 48 55 Executor::~Executor() 49 56 { 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; 50 104 } 51 105 … … 77 131 void Executor::descriptionParam(int param, const std::string& description) 78 132 { 79 if (param > 0 && param <= 5)133 if (param >= 0 && param < MAX_FUNCTOR_ARGUMENTS) 80 134 { 81 135 if (!this->bAddedDescriptionParam_[param]) … … 94 148 const std::string& Executor::getDescriptionParam(int param) const 95 149 { 96 if (param > 0 && param <= 5) 97 { 150 if (param >= 0 && param < MAX_FUNCTOR_ARGUMENTS) 98 151 return GetLocalisation(this->descriptionParam_[param]); 99 }100 152 101 153 return this->descriptionParam_[0]; … … 116 168 return GetLocalisation(this->descriptionReturnvalue_); 117 169 } 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 } 118 229 } -
code/branches/core2/src/orxonox/core/Executor.h
r871 r931 32 32 #include "CorePrereqs.h" 33 33 #include "Functor.h" 34 #include "util/SubString.h" 35 34 36 35 37 namespace orxonox … … 41 43 virtual ~Executor(); 42 44 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 44 56 { (*this->functor_)(param1, param2, param3, param4, param5); } 57 58 bool parse(const std::string& params, const std::string& delimiter = " ") const; 45 59 46 60 void setName(const std::string name); … … 69 83 { return this->functor_->getTypenameReturnvalue(); } 70 84 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 71 92 protected: 72 93 Functor* functor_; … … 77 98 LanguageEntryLabel description_; 78 99 LanguageEntryLabel descriptionReturnvalue_; 79 LanguageEntryLabel descriptionParam_[ 5];100 LanguageEntryLabel descriptionParam_[MAX_FUNCTOR_ARGUMENTS]; 80 101 81 102 bool bAddedDescription_; 82 103 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]; 84 108 }; 85 109 … … 89 113 ExecutorStatic(FunctorStatic* functor, const std::string& name = "") : Executor(functor, name) {} 90 114 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); }94 115 }; 95 116 … … 101 122 virtual ~ExecutorMember() {} 102 123 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 } 114 247 }; 115 248 } -
code/branches/core2/src/orxonox/core/Functor.h
r925 r931 35 35 #include "CorePrereqs.h" 36 36 37 #define MAX_FUNCTOR_ARGUMENTS 5 37 38 38 39 enum FunctionType … … 80 81 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; 81 82 82 inline int getParamCount() const { return this->numParams_; }83 inline unsigned int getParamCount() const { return this->numParams_; } 83 84 inline bool hasReturnvalue() const { return this->hasReturnValue_; } 84 85 inline FunctionType getType() const { return this->type_; } … … 89 90 90 91 protected: 91 int numParams_;92 unsigned int numParams_; 92 93 bool hasReturnValue_; 93 94 FunctionType type_; … … 95 96 96 97 std::string typeReturnvalue_; 97 std::string typeParam_[ 5];98 std::string typeParam_[MAX_FUNCTOR_ARGUMENTS]; 98 99 }; 99 100 -
code/branches/core2/src/orxonox/core/Language.cc
r871 r931 61 61 { 62 62 // Check if the translation is more than just an empty string 63 if ( localisation.compare("") != 0)63 if ((localisation != "") && (localisation.size() > 0)) 64 64 { 65 65 this->localisedEntry_ = localisation; … … 244 244 245 245 // Check if the line is empty 246 if ( lineString.compare("") != 0)246 if ((lineString != "") && (lineString.size() > 0)) 247 247 { 248 248 unsigned int pos = lineString.find('='); … … 288 288 289 289 // Check if the line is empty 290 if ( lineString.compare("") != 0)290 if ((lineString != "") && (lineString.size() > 0)) 291 291 { 292 292 unsigned int pos = lineString.find('='); -
code/branches/core2/src/orxonox/core/XMLPort.h
r902 r931 102 102 const std::string& getDescription(); 103 103 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 115 104 protected: 116 105 std::string classname_; 117 106 std::string paramname_; 118 MultiTypeMath defaultValues_[5];119 107 120 108 private: … … 247 235 { 248 236 Element* xmlsubelement; 249 if ( this->sectionname_ != "")237 if ((this->sectionname_ != "") && (this->sectionname_.size() > 0)) 250 238 xmlsubelement = xmlelement.FirstChildElement(this->sectionname_, false); 251 239 else -
code/branches/core2/src/orxonox/objects/Model.cc
r902 r931 81 81 } 82 82 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; 91 93 } 92 94 -
code/branches/core2/src/util/Convert.h
r925 r931 541 541 }; 542 542 543 544 ////////////////545 // XMLElement //546 ////////////////547 548 // orxonox::Element to std::string549 template <>550 class Converter<orxonox::Element, std::string>551 {552 public:553 bool operator()(std::string* output, const orxonox::Element& input) const554 {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::Element567 template <>568 class Converter<std::string, orxonox::Element>569 {570 public:571 bool operator()(orxonox::Element* output, const std::string& input) const572 {573 std::istringstream istream(input);574 if (istream >> (*output))575 return true;576 577 return false;578 }579 };580 581 582 543 #endif /* _Convert_H__ */ -
code/branches/core2/src/util/MultiTypeString.cc
r925 r931 32 32 MultiTypeString::MultiTypeString(MultiType type) : MultiTypePrimitive(type) 33 33 { 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 38 35 } 39 36 -
code/branches/core2/src/util/String.cc
r871 r931 83 83 bool isEmpty(const std::string& str) 84 84 { 85 return getStripped(str) == ""; 85 std::string temp = getStripped(str); 86 return ((temp == "") || (temp.size() == 0)); 86 87 } 87 88
Note: See TracChangeset
for help on using the changeset viewer.