ConfigCmdManager.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * Copyright (C) 2022 The V-Gears Team
  3. *
  4. * This file is part of V-Gears
  5. *
  6. * V-Gears is free software: you can redistribute it and/or modify it under
  7. * terms of the GNU General Public License as published by the Free Software
  8. * Foundation, version 3.0 (GPLv3) of the License.
  9. *
  10. * V-Gears is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #include "core/Assert.h"
  16. #include "core/ConfigCmdManager.h"
  17. #include "core/ConfigCmdManagerCommands.h"
  18. /**
  19. * Configuration manager singleton.
  20. */
  21. template<>ConfigCmdManager *Ogre::Singleton<ConfigCmdManager>::msSingleton = nullptr;
  22. ConfigCmdManager::ConfigCmdManager(){InitCmd();}
  23. ConfigCmdManager::~ConfigCmdManager(){}
  24. void ConfigCmdManager::AddCommand(
  25. const Ogre::String& name, const Ogre::String& description, const Ogre::String& params_description,
  26. ConfigCmdHandler handler, ConfigCmdCompletion completion
  27. ){
  28. VGEARS_ASSERT(name != "", "Command name shouldn't be empty.");
  29. VGEARS_ASSERT(handler, "Null command handler.");
  30. // Check if command already added
  31. for (unsigned int i = 0; i < commands_.size(); ++ i)
  32. VGEARS_ASSERT(commands_[i]->GetName() != name, "Command already exist.");
  33. commands_.emplace_back(std::make_unique<ConfigCmd>(
  34. name, description, params_description, handler, completion
  35. ));
  36. }
  37. void ConfigCmdManager::ExecuteString(const Ogre::String& cmd_string){}
  38. ConfigCmd* ConfigCmdManager::Find(const Ogre::String& name) const{
  39. for (unsigned int i = 0; i < commands_.size(); ++ i)
  40. if (commands_[i]->GetName() == name) return commands_[i].get();
  41. return nullptr;
  42. }
  43. int ConfigCmdManager::GetConfigCmdNumber(){return commands_.size();}
  44. ConfigCmd* ConfigCmdManager::GetConfigCmd(unsigned int i) const{
  45. if (i < commands_.size()) return commands_[i].get();
  46. return nullptr;
  47. }