ConfigCmdManager.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #include "common/make_unique.h"
  2. #include "core/Assert.h"
  3. #include "core/ConfigCmdManager.h"
  4. #include "core/ConfigCmdManagerCommands.h"
  5. template<>ConfigCmdManager *Ogre::Singleton<ConfigCmdManager>::msSingleton = nullptr;
  6. ConfigCmdManager::ConfigCmdManager()
  7. {
  8. InitCmd();
  9. }
  10. ConfigCmdManager::~ConfigCmdManager()
  11. {
  12. }
  13. void
  14. ConfigCmdManager::AddCommand(const Ogre::String& name, const Ogre::String& description, const Ogre::String& params_description, ConfigCmdHandler handler, ConfigCmdCompletion completion)
  15. {
  16. QGEARS_ASSERT(name != "", "Command name shouldn't be empty.");
  17. QGEARS_ASSERT(handler, "Null command handler.");
  18. // see if command already added
  19. for(unsigned int i = 0; i < m_Commands.size(); ++i)
  20. {
  21. QGEARS_ASSERT(m_Commands[i]->GetName() != name, "Command already exist.");
  22. }
  23. m_Commands.emplace_back(std::make_unique<ConfigCmd>(name, description, params_description, handler, completion));
  24. }
  25. void
  26. ConfigCmdManager::ExecuteString(const Ogre::String& cmd_string)
  27. {
  28. }
  29. ConfigCmd*
  30. ConfigCmdManager::Find(const Ogre::String& name) const
  31. {
  32. for(unsigned int i = 0; i < m_Commands.size(); ++i)
  33. {
  34. if(m_Commands[i]->GetName() == name)
  35. {
  36. return m_Commands[i].get();
  37. }
  38. }
  39. return nullptr;
  40. }
  41. int
  42. ConfigCmdManager::GetConfigCmdNumber()
  43. {
  44. return m_Commands.size();
  45. }
  46. ConfigCmd*
  47. ConfigCmdManager::GetConfigCmd(unsigned int i) const
  48. {
  49. if(i < m_Commands.size())
  50. {
  51. return m_Commands[i].get();
  52. }
  53. return nullptr;
  54. }