- Timestamp:
- Aug 25, 2010, 1:04:55 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/consolecommands3/src/libraries/core/command/ConsoleCommand.h
r7203 r7214 176 176 177 177 #define _SetConsoleCommandGeneric(group, name, functor) \ 178 orxonox::_ConsoleCommand& BOOST_PP_CAT(__consolecommand_, __LINE__) = (*orxonox::_createConsoleCommand(group, name, functor))178 orxonox::_ConsoleCommand& BOOST_PP_CAT(__consolecommand_, __LINE__) = (*orxonox::_createConsoleCommand(group, name, orxonox::createExecutor(functor))) 179 179 180 180 … … 182 182 BOOST_PP_CAT(_DeclareConsoleCommand, ORXONOX_VA_NARGS(__VA_ARGS__))(__VA_ARGS__) 183 183 #define _DeclareConsoleCommand2(name, functionpointer) \ 184 _DeclareConsoleCommandGeneric("", name, functionpointer)184 _DeclareConsoleCommandGeneric("", name, orxonox::createFunctor(functionpointer)) 185 185 #define _DeclareConsoleCommand3(group, name, functionpointer) \ 186 _DeclareConsoleCommandGeneric(group, name, functionpointer) 187 188 #define _DeclareConsoleCommandGeneric(group, name, functionpointer) \ 189 orxonox::_ConsoleCommand& BOOST_PP_CAT(__consolecommand_, __LINE__) = (*orxonox::_createConsoleCommand(group, name, orxonox::createFunctor(functionpointer), false)) 186 _DeclareConsoleCommandGeneric(group, name, orxonox::createFunctor(functionpointer)) 187 #define _DeclareConsoleCommand4(group, name, functionpointer, object) \ 188 _DeclareConsoleCommandGeneric(group, name, orxonox::createFunctor(functionpointer, object)) 189 190 #define _DeclareConsoleCommandGeneric(group, name, functor) \ 191 orxonox::_ConsoleCommand& BOOST_PP_CAT(__consolecommand_, __LINE__) = orxonox::_createConsoleCommand(group, name, orxonox::createExecutor(functor), false) 190 192 191 193 … … 196 198 namespace orxonox 197 199 { 198 class _CoreExport _ConsoleCommand : protected Executor200 class _CoreExport _ConsoleCommand 199 201 { 200 202 friend struct _ConsoleCommandManipulator; 203 204 struct Command 205 { 206 ExecutorPtr executor_; 207 FunctorPtr functor_; 208 }; 201 209 202 210 public: … … 208 216 template <class F> 209 217 inline _ConsoleCommandManipulator& setFunction(F function, bool bForce = false) 210 { if (this->command_) { this->command_->setFunctor(createFunctor(function), bForce); } return *this; } 218 { 219 if (this->command_) 220 { 221 if (this->command_->getExecutor() && this->command_->getFunctor() && this->command_->getFunctor()->getFullIdentifier() == typeid(F)) 222 { 223 FunctorPointer<F>* functor = static_cast<FunctorPointer<F>*>(this->command_->getFunctor().get()); 224 functor->setFunction(function); 225 return *this; 226 } 227 this->command_->setFunction(createFunctor(function), bForce); 228 } 229 return *this; 230 } 211 231 template <class F, class O> 212 232 inline _ConsoleCommandManipulator& setFunction(F function, O* object, bool bForce = false) 213 { if (this->command_) { this->command_->setFunctor(createFunctor(function, object), bForce); } return *this; } 233 { 234 if (this->command_) 235 { 236 if (this->command_->getExecutor() && this->command_->getFunctor() && this->command_->getFunctor()->getFullIdentifier() == typeid(F)) 237 { 238 FunctorPointer<F, O>* functor = static_cast<FunctorPointer<F, O>*>(this->command_->getFunctor().get()); 239 functor->setFunction(function); 240 functor->setObject(object); 241 return *this; 242 } 243 this->command_->setFunction(createFunctor(function, object), bForce); 244 } 245 return *this; 246 } 214 247 inline _ConsoleCommandManipulator& setFunction(const FunctorPtr& functor, bool bForce = false) 215 { if (this->command_) { this->command_->setFunctor(functor, bForce); } return *this; } 248 { if (this->command_) { this->command_->setFunction(functor, bForce); } return *this; } 249 inline _ConsoleCommandManipulator& setFunction(const ExecutorPtr& executor, bool bForce = false) 250 { if (this->command_) { this->command_->setFunction(executor, bForce); } return *this; } 216 251 217 252 template <class F> 218 253 inline _ConsoleCommandManipulator& pushFunction(F function, bool bForce = false) 219 { if (this->command_) { this->command_->pushFunct or(createFunctor(function), bForce); } return *this; }254 { if (this->command_) { this->command_->pushFunction(createFunctor(function), bForce); } return *this; } 220 255 template <class F, class O> 221 256 inline _ConsoleCommandManipulator& pushFunction(F function, O* object, bool bForce = false) 222 { if (this->command_) { this->command_->pushFunct or(createFunctor(function, object), bForce); } return *this; }257 { if (this->command_) { this->command_->pushFunction(createFunctor(function, object), bForce); } return *this; } 223 258 inline _ConsoleCommandManipulator& pushFunction(const FunctorPtr& functor, bool bForce = false) 224 { if (this->command_) { this->command_->pushFunctor(functor, bForce); } return *this; } 259 { if (this->command_) { this->command_->pushFunction(functor, bForce); } return *this; } 260 inline _ConsoleCommandManipulator& pushFunction(const ExecutorPtr& executor, bool bForce = false) 261 { if (this->command_) { this->command_->pushFunction(executor, bForce); } return *this; } 225 262 226 263 inline _ConsoleCommandManipulator& popFunction() 227 { if (this->command_) { this->command_->popFunct or(); } return *this; }264 { if (this->command_) { this->command_->popFunction(); } return *this; } 228 265 229 266 inline _ConsoleCommandManipulator& setObject(void* object) … … 239 276 inline _ConsoleCommandManipulator& setActive(bool bActive) 240 277 { if (this->command_) { this->command_->setActive(bActive); } return *this; } 278 inline _ConsoleCommandManipulator& activate() 279 { return this->setActive(true); } 280 inline _ConsoleCommandManipulator& deactivate() 281 { return this->setActive(false); } 282 283 inline bool isActive() const 284 { return this->command_ ? this->command_->isActive() : false; } 285 inline bool exists() const 286 { return (this->command_ != 0); } 241 287 242 288 private: … … 245 291 246 292 public: 247 _ConsoleCommand(const std::string& group, const std::string& name, const FunctorPtr& functor, bool bInitialized = true); 293 _ConsoleCommand(const std::string& group, const std::string& name, const ExecutorPtr& executor, bool bInitialized = true); 294 ~_ConsoleCommand(); 248 295 249 296 _ConsoleCommand& addShortcut(); … … 254 301 inline void setActive(bool bActive) 255 302 { this->bActive_ = bActive; } 256 inline bool isActive() const 257 { return (this->bActive_ && this->bInitialized_); } 303 inline void activate() 304 { this->setActive(true); } 305 inline void deactivate() 306 { this->setActive(false); } 307 bool isActive() const; 258 308 259 309 inline _ConsoleCommandManipulator getManipulator() const … … 270 320 static std::map<std::string, std::map<std::string, _ConsoleCommand*> >& getCommandMap(); 271 321 static void registerCommand(const std::string& group, const std::string& name, _ConsoleCommand* command); 272 273 bool setFunctor(const FunctorPtr& functor, bool bForce = false); 274 void pushFunctor(const FunctorPtr& functor, bool bForce = false); 275 void popFunctor(); 322 static void unregisterCommand(_ConsoleCommand* command); 323 324 bool headersMatch(const FunctorPtr& functor); 325 bool headersMatch(const ExecutorPtr& executor); 326 327 bool setFunction(const ExecutorPtr& executor, bool bForce = false); 328 bool setFunction(const FunctorPtr& functor, bool bForce = false); 329 void pushFunction(const ExecutorPtr& executor, bool bForce = false); 330 void pushFunction(const FunctorPtr& functor, bool bForce = false); 331 void pushFunction(); 332 void popFunction(); 333 const ExecutorPtr& getExecutor() const; 276 334 const FunctorPtr& getFunctor() const; 277 335 278 bool functionHeaderMatches(const FunctorPtr& functor) const; 279 280 void setObject(void* object); 336 bool setObject(void* object); 281 337 void pushObject(void* object); 282 338 void popObject(); … … 284 340 285 341 bool bActive_; 286 bool bInitialized_; 287 const std::type_info& functionHeader_; 288 std::stack<FunctorPtr> functorStack_; 342 // const std::type_info& functionHeader_; 343 std::string baseName_; 344 ExecutorPtr baseExecutor_; 345 346 ExecutorPtr executor_; 347 std::stack<Command> commandStack_; 289 348 std::stack<void*> objectStack_; 290 349 }; 291 350 292 inline _ConsoleCommand* _createConsoleCommand(const std::string& name, const FunctorPtr& functor, bool bInitialized = true)293 { 294 return new _ConsoleCommand("", name, functor, bInitialized);351 inline _ConsoleCommand* _createConsoleCommand(const std::string& name, const ExecutorPtr& executor, bool bInitialized = true) 352 { 353 return new _ConsoleCommand("", name, executor, bInitialized); 295 354 } 296 355 297 inline _ConsoleCommand* _createConsoleCommand(const std::string& group, const std::string& name, const FunctorPtr& functor, bool bInitialized = true)298 { 299 return new _ConsoleCommand(group, name, functor, bInitialized);356 inline _ConsoleCommand* _createConsoleCommand(const std::string& group, const std::string& name, const ExecutorPtr& executor, bool bInitialized = true) 357 { 358 return new _ConsoleCommand(group, name, executor, bInitialized); 300 359 } 301 360 }
Note: See TracChangeset
for help on using the changeset viewer.