- Timestamp:
- Aug 19, 2010, 2:11:28 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/consolecommands3/src/libraries/core/ConsoleCommand.h
r7179 r7185 32 32 #include "CorePrereqs.h" 33 33 34 #include <stack> 34 35 #include <boost/preprocessor/cat.hpp> 35 36 #include <boost/preprocessor/facilities/expand.hpp> … … 179 180 180 181 #define _DeclareConsoleCommandGeneric(group, name, functionpointer) \ 181 orxonox::_ConsoleCommand& BOOST_PP_CAT(__consolecommand_, __LINE__) = (*orxonox::_createConsoleCommand(group, name, orxonox::createFunctor(functionpointer), orxonox::_ConsoleCommand::State::UninitializedActive))182 orxonox::_ConsoleCommand& BOOST_PP_CAT(__consolecommand_, __LINE__) = (*orxonox::_createConsoleCommand(group, name, orxonox::createFunctor(functionpointer), false)) 182 183 183 184 … … 193 194 194 195 public: 195 struct State196 {197 enum Enum198 {199 UninitializedActive,200 UninitializedInactive,201 Active,202 Inactive203 };204 };205 206 struct ObjectPointer207 {208 enum Enum209 {210 Null,211 RawCopy,212 CastViaBaseObject213 };214 };215 216 196 struct _ConsoleCommandManipulator 217 197 { … … 220 200 221 201 template <class F> 222 inline _ConsoleCommandManipulator& setFunction(F function, _ConsoleCommand::ObjectPointer::Enum mode = _ConsoleCommand::ObjectPointer::Null)223 { if (this->command_) { this->command_->setFunctor(createFunctor(function), mode); } return *this; }202 inline _ConsoleCommandManipulator& setFunction(F function, bool bForce = false) 203 { if (this->command_) { this->command_->setFunctor(createFunctor(function), bForce); } return *this; } 224 204 template <class F, class O> 225 inline _ConsoleCommandManipulator& setFunction(F function, O* object) 226 { if (this->command_) { this->command_->setFunctor(createFunctor(function, object)); } return *this; } 227 inline _ConsoleCommandManipulator& setFunction(Functor* functor) 228 { if (this->command_) { this->command_->setFunctor(functor); } return *this; } 229 inline _ConsoleCommandManipulator& setFunction(const _ConsoleCommand* command) 230 { if (this->command_) { this->command_->setFunctor(command->functor_); } return *this; } 231 inline _ConsoleCommandManipulator& setFunction(const _ConsoleCommandManipulator& manipulator) 232 { if (this->command_) { this->command_->setFunctor(manipulator.command_->functor_); } return *this; } 205 inline _ConsoleCommandManipulator& setFunction(F function, O* object, bool bForce = false) 206 { if (this->command_) { this->command_->setFunctor(createFunctor(function, object), bForce); } return *this; } 207 inline _ConsoleCommandManipulator& setFunction(Functor* functor, bool bForce = false) 208 { if (this->command_) { this->command_->setFunctor(functor, bForce); } return *this; } 233 209 234 210 template <class F> 235 inline _ConsoleCommandManipulator& pushFunction(F function, _ConsoleCommand::ObjectPointer::Enum mode = _ConsoleCommand::ObjectPointer::Null)236 { if (this->command_) { this->command_->pushFunctor(createFunctor(function), mode); } return *this; }211 inline _ConsoleCommandManipulator& pushFunction(F function, bool bForce = false) 212 { if (this->command_) { this->command_->pushFunctor(createFunctor(function), bForce); } return *this; } 237 213 template <class F, class O> 238 inline _ConsoleCommandManipulator& pushFunction(F function, O* object) 239 { if (this->command_) { this->command_->pushFunctor(createFunctor(function, object)); } return *this; } 240 inline _ConsoleCommandManipulator& pushFunction(Functor* functor) 241 { if (this->command_) { this->command_->pushFunctor(functor); } return *this; } 242 inline _ConsoleCommandManipulator& pushFunction(const _ConsoleCommand* command) 243 { if (this->command_) { this->command_->pushFunctor(command->functor_); } return *this; } 244 inline _ConsoleCommandManipulator& pushFunction(const _ConsoleCommandManipulator& manipulator) 245 { if (this->command_) { this->command_->pushFunctor(manipulator.command_->functor_); } return *this; } 214 inline _ConsoleCommandManipulator& pushFunction(F function, O* object, bool bForce = false) 215 { if (this->command_) { this->command_->pushFunctor(createFunctor(function, object), bForce); } return *this; } 216 inline _ConsoleCommandManipulator& pushFunction(Functor* functor, bool bForce = false) 217 { if (this->command_) { this->command_->pushFunctor(functor, bForce); } return *this; } 246 218 247 219 inline _ConsoleCommandManipulator& popFunction() … … 250 222 inline _ConsoleCommandManipulator& setObject(void* object) 251 223 { if (this->command_) { this->command_->setObject(object); } return *this; } 252 inline _ConsoleCommandManipulator& setObject(BaseObject* object) 253 { if (this->command_) { this->command_->setObject(object); } return *this; } 224 inline _ConsoleCommandManipulator& pushObject(void* object) 225 { if (this->command_) { this->command_->pushObject(object); } return *this; } 226 inline _ConsoleCommandManipulator& popObject() 227 { if (this->command_) { this->command_->popObject(); } return *this; } 228 229 inline void* getObject() const 230 { if (this->command_) { return this->command_->getObject(); } else { return 0; } } 254 231 255 232 inline _ConsoleCommandManipulator& setActive(bool bActive) … … 261 238 262 239 public: 263 _ConsoleCommand(const std::string& group, const std::string& name, Functor* functor, State::Enum state = State::Active);240 _ConsoleCommand(const std::string& group, const std::string& name, Functor* functor, bool bInitialized = true); 264 241 265 242 _ConsoleCommand& addShortcut(); … … 268 245 _ConsoleCommand& addGroup(const std::string& group, const std::string& name); 269 246 270 void setActive(bool bActive); 271 inline State::Enum getState() const 272 { return this->state_; } 247 inline void setActive(bool bActive) 248 { this->bActive_ = bActive; } 273 249 inline bool isActive() const 274 { return (this->state_ == State::Active); } 250 { return (this->bActive_ && this->bInitialized_); } 251 252 inline _ConsoleCommandManipulator getManipulator() const 253 { return this; } 275 254 276 255 static inline const std::map<std::string, std::map<std::string, _ConsoleCommand*> >& getCommands() … … 281 260 static const _ConsoleCommand* getCommand(const std::string& group, const std::string& name, bool bPrintError = false); 282 261 283 inline _ConsoleCommandManipulator getManipulator() const284 { return this; }285 286 262 private: 287 263 static std::map<std::string, std::map<std::string, _ConsoleCommand*> >& getCommandMap(); 288 264 static void registerCommand(const std::string& group, const std::string& name, _ConsoleCommand* command); 289 265 290 void setInitialized(bool bInitialized); 291 292 void setFunctor(Functor* functor, _ConsoleCommand::ObjectPointer::Enum mode = _ConsoleCommand::ObjectPointer::Null); 293 void pushFunctor(Functor* functor, _ConsoleCommand::ObjectPointer::Enum mode = _ConsoleCommand::ObjectPointer::Null); 266 bool setFunctor(Functor* functor, bool bForce = false); 267 void pushFunctor(Functor* functor, bool bForce = false); 294 268 void popFunctor(); 269 Functor* getFunctor() const; 270 295 271 bool functionHeaderMatches(Functor* functor) const; 296 272 297 273 void setObject(void* object); 298 void setObject(BaseObject* object); 299 300 State::Enum state_; 274 void pushObject(void* object); 275 void popObject(); 276 void* getObject() const; 277 278 bool bActive_; 279 bool bInitialized_; 301 280 const std::type_info& functionHeader_; 281 std::stack<Functor*> functorStack_; 282 std::stack<void*> objectStack_; 302 283 }; 303 284 304 inline _ConsoleCommand* _createConsoleCommand(const std::string& name, Functor* functor, _ConsoleCommand::State::Enum state = _ConsoleCommand::State::Active)305 { 306 return new _ConsoleCommand("", name, functor, state);307 } 308 309 inline _ConsoleCommand* _createConsoleCommand(const std::string& group, const std::string& name, Functor* functor, _ConsoleCommand::State::Enum state = _ConsoleCommand::State::Active)310 { 311 return new _ConsoleCommand(group, name, functor, state);285 inline _ConsoleCommand* _createConsoleCommand(const std::string& name, Functor* functor, bool bInitialized = true) 286 { 287 return new _ConsoleCommand("", name, functor, bInitialized); 288 } 289 290 inline _ConsoleCommand* _createConsoleCommand(const std::string& group, const std::string& name, Functor* functor, bool bInitialized = true) 291 { 292 return new _ConsoleCommand(group, name, functor, bInitialized); 312 293 } 313 294 }
Note: See TracChangeset
for help on using the changeset viewer.