Changeset 7158 for code/branches
- Timestamp:
- Jul 21, 2010, 2:43:10 PM (14 years ago)
- Location:
- code/branches/presentation3/src/libraries/core
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation3/src/libraries/core/Executor.cc
r6417 r7158 30 30 #include "Executor.h" 31 31 32 #include <algorithm> 33 32 34 #include "util/Convert.h" 35 #include "util/Debug.h" 36 #include "util/StringUtils.h" 37 #include "util/SubString.h" 33 38 #include "Language.h" 34 39 … … 63 68 bool Executor::parse(const std::string& params, const std::string& delimiter) const 64 69 { 65 EXECUTOR_PARSE(normal); 70 unsigned int paramCount = this->functor_->getParamCount(); 71 72 if (paramCount == 0) 73 { 74 COUT(5) << "Calling Executor " << this->name_ << " through parser without parameters." << std::endl; 75 (*this->functor_)(); 76 } 77 else if (paramCount == 1) 78 { 79 const std::string& temp = getStripped(params); 80 if (!temp.empty()) 81 { 82 COUT(5) << "Calling Executor " << this->name_ << " through parser with one parameter, using whole string: " << params << std::endl; 83 (*this->functor_)(MultiType(params)); 84 } 85 else if (this->bAddedDefaultValue_[0]) 86 { 87 COUT(5) << "Calling Executor " << this->name_ << " through parser with one parameter, using default value: " << this->defaultValue_[0] << std::endl; 88 (*this->functor_)(this->defaultValue_[0]); 89 } 90 else 91 { 92 COUT(2) << "Warning: Can't call executor " << this->name_ << " through parser: Not enough parameters or default values given (input: " << temp << ")." << std::endl; 93 return false; 94 } 95 } 96 else 97 { 98 SubString tokens(params, delimiter, SubString::WhiteSpaces, false, '\\', true, '"', true, '(', ')', true, '\0'); 99 100 for (unsigned int i = tokens.size(); i < this->functor_->getParamCount(); i++) 101 { 102 if (!this->bAddedDefaultValue_[i]) 103 { 104 COUT(2) << "Warning: Can't call executor " << this->name_ << " through parser: Not enough parameters or default values given (input:" << params << ")." << std::endl; 105 return false; 106 } 107 } 108 109 MultiType param[MAX_FUNCTOR_ARGUMENTS]; 110 COUT(5) << "Calling Executor " << this->name_ << " through parser with " << paramCount << " parameters, using " << tokens.size() << " tokens ("; 111 for (unsigned int i = 0; i < tokens.size() && i < MAX_FUNCTOR_ARGUMENTS; i++) 112 { 113 param[i] = tokens[i]; 114 if (i != 0) 115 { 116 COUT(5) << ", "; 117 } 118 COUT(5) << tokens[i]; 119 } 120 COUT(5) << ") and " << std::max((int)paramCount - (int)tokens.size(), 0) << " default values ("; 121 for (unsigned int i = tokens.size(); i < paramCount; i++) 122 { 123 param[i] = this->defaultValue_[i]; 124 if (i != 0) 125 { 126 COUT(5) << ", "; 127 } 128 COUT(5) << this->defaultValue_[i]; 129 } 130 COUT(5) << ")." << std::endl; 131 132 if ((tokens.size() > paramCount) && (this->functor_->getTypenameParam(paramCount - 1) == "string")) 133 param[paramCount - 1] = tokens.subSet(paramCount - 1).join(); 134 135 switch(paramCount) 136 { 137 case 2: 138 (*this->functor_)(param[0], param[1]); 139 break; 140 case 3: 141 (*this->functor_)(param[0], param[1], param[2]); 142 break; 143 case 4: 144 (*this->functor_)(param[0], param[1], param[2], param[3]); 145 break; 146 case 5: 147 (*this->functor_)(param[0], param[1], param[2], param[3], param[4]); 148 break; 149 } 150 } 151 152 return true; 66 153 } 67 154 -
code/branches/presentation3/src/libraries/core/Executor.h
r6417 r7158 33 33 #include "CorePrereqs.h" 34 34 35 #include <algorithm>36 35 #include <string> 37 38 #include "util/Debug.h" 39 #include "util/Math.h" 40 #include "util/StringUtils.h" 41 #include "util/SubString.h" 36 #include "util/MultiType.h" 42 37 #include "Functor.h" 43 44 45 #define EXECUTOR_PARSE_FUNCTORCALL(mode) EXECUTOR_PARSE_FUNCTORCALL##mode46 #define EXECUTOR_PARSE_FUNCTORCALLnormal (*this->functor_)47 #define EXECUTOR_PARSE_FUNCTORCALLobject (*((FunctorMember<T>*)this->functor_))48 49 #define EXECUTOR_PARSE_OBJECT(mode, comma) EXECUTOR_PARSE_OBJECT##mode##comma50 #define EXECUTOR_PARSE_OBJECTnormal051 #define EXECUTOR_PARSE_OBJECTnormal152 #define EXECUTOR_PARSE_OBJECTobject0 object53 #define EXECUTOR_PARSE_OBJECTobject1 object,54 55 #define EXECUTOR_PARSE(mode) \56 unsigned int paramCount = this->functor_->getParamCount(); \57 \58 if (paramCount == 0) \59 { \60 COUT(5) << "Calling Executor " << this->name_ << " through parser without parameters." << std::endl; \61 EXECUTOR_PARSE_FUNCTORCALL(mode)(EXECUTOR_PARSE_OBJECT(mode, 0)); \62 } \63 else if (paramCount == 1) \64 { \65 const std::string& temp = getStripped(params); \66 if (!temp.empty()) \67 { \68 COUT(5) << "Calling Executor " << this->name_ << " through parser with one parameter, using whole string: " << params << std::endl; \69 EXECUTOR_PARSE_FUNCTORCALL(mode)(EXECUTOR_PARSE_OBJECT(mode, 1) MultiType(params)); \70 } \71 else if (this->bAddedDefaultValue_[0]) \72 { \73 COUT(5) << "Calling Executor " << this->name_ << " through parser with one parameter, using default value: " << this->defaultValue_[0] << std::endl; \74 EXECUTOR_PARSE_FUNCTORCALL(mode)(EXECUTOR_PARSE_OBJECT(mode, 1) this->defaultValue_[0]); \75 } \76 else \77 { \78 COUT(2) << "Warning: Can't call executor " << this->name_ << " through parser: Not enough parameters or default values given (input: " << temp << ")." << std::endl; \79 return false; \80 } \81 } \82 else \83 { \84 SubString tokens(params, delimiter, SubString::WhiteSpaces, false, '\\', true, '"', true, '(', ')', true, '\0'); \85 \86 for (unsigned int i = tokens.size(); i < this->functor_->getParamCount(); i++) \87 { \88 if (!this->bAddedDefaultValue_[i]) \89 { \90 COUT(2) << "Warning: Can't call executor " << this->name_ << " through parser: Not enough parameters or default values given (input:" << params << ")." << std::endl; \91 return false; \92 } \93 } \94 \95 MultiType param[MAX_FUNCTOR_ARGUMENTS]; \96 COUT(5) << "Calling Executor " << this->name_ << " through parser with " << paramCount << " parameters, using " << tokens.size() << " tokens ("; \97 for (unsigned int i = 0; i < tokens.size() && i < MAX_FUNCTOR_ARGUMENTS; i++) \98 { \99 param[i] = tokens[i]; \100 if (i != 0) \101 { \102 COUT(5) << ", "; \103 } \104 COUT(5) << tokens[i]; \105 } \106 COUT(5) << ") and " << std::max(static_cast<int>(paramCount) - static_cast<int>(tokens.size()), 0) << " default values ("; \107 for (unsigned int i = tokens.size(); i < paramCount; i++) \108 { \109 param[i] = this->defaultValue_[i]; \110 if (i != 0) \111 { \112 COUT(5) << ", "; \113 } \114 COUT(5) << this->defaultValue_[i]; \115 } \116 COUT(5) << ")." << std::endl; \117 \118 if ((tokens.size() > paramCount) && (this->functor_->getTypenameParam(paramCount - 1) == "string")) \119 param[paramCount - 1] = tokens.subSet(paramCount - 1).join(); \120 \121 switch(paramCount) \122 { \123 case 2: \124 EXECUTOR_PARSE_FUNCTORCALL(mode)(EXECUTOR_PARSE_OBJECT(mode, 1) param[0], param[1]); \125 break; \126 case 3: \127 EXECUTOR_PARSE_FUNCTORCALL(mode)(EXECUTOR_PARSE_OBJECT(mode, 1) param[0], param[1], param[2]); \128 break; \129 case 4: \130 EXECUTOR_PARSE_FUNCTORCALL(mode)(EXECUTOR_PARSE_OBJECT(mode, 1) param[0], param[1], param[2], param[3]); \131 break; \132 case 5: \133 EXECUTOR_PARSE_FUNCTORCALL(mode)(EXECUTOR_PARSE_OBJECT(mode, 1) param[0], param[1], param[2], param[3], param[4]); \134 break; \135 } \136 } \137 \138 return true139 38 140 39 namespace orxonox … … 284 183 bool parse(T* object, const std::string& params, const std::string& delimiter = " ") const 285 184 { 286 EXECUTOR_PARSE(object); 185 static_cast<FunctorMember<T>*>(this->functor_)->setObject(object); 186 if (Executor::parse(params, delimiter)) 187 return true; 188 else 189 { 190 static_cast<FunctorMember<T>*>(this->functor_)->setObject((T*)NULL); 191 return false; 192 } 287 193 } 288 194 289 195 bool parse(const T* object, const std::string& params, const std::string& delimiter = " ") const 290 196 { 291 EXECUTOR_PARSE(object); 197 static_cast<FunctorMember<T>*>(this->functor_)->setObject(object); 198 if (Executor::parse(params, delimiter)) 199 return true; 200 else 201 { 202 static_cast<FunctorMember<T>*>(this->functor_)->setObject((T*)NULL); 203 return false; 204 } 292 205 } 293 206 };
Note: See TracChangeset
for help on using the changeset viewer.