ConfigCmdManager.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. #pragma once
  16. #include <OgreSingleton.h>
  17. #include <vector>
  18. #include <memory>
  19. #include "ConfigCmd.h"
  20. /**
  21. * A manager for configuration commands.
  22. */
  23. class ConfigCmdManager : public Ogre::Singleton<ConfigCmdManager>{
  24. public:
  25. /**
  26. * Constructor.
  27. */
  28. ConfigCmdManager();
  29. /**
  30. * Destructor.
  31. */
  32. ~ConfigCmdManager();
  33. /**
  34. * Adds a command to the manager.
  35. *
  36. * @param name[in] Command name.
  37. * @param description[in] Command description.
  38. * @param params_description[in] Command parameters description.
  39. * @param handler[in] Command handler.
  40. * @param completion[in] Command completion.
  41. */
  42. void AddCommand(
  43. const Ogre::String& name, const Ogre::String& description,
  44. const Ogre::String& params_description, ConfigCmdHandler handler,
  45. ConfigCmdCompletion completion
  46. );
  47. /**
  48. * Executes a command.
  49. *
  50. * @param cmd_string[in] The command, in string format.
  51. */
  52. void ExecuteString( const Ogre::String& cmd_string );
  53. /**
  54. * Finds a command by name.
  55. *
  56. * @param name[in] Name of the command.
  57. * @return The command by the name, or nullptr if there is none.
  58. */
  59. ConfigCmd* Find(const Ogre::String& name) const;
  60. /**
  61. * Counts the commands in the manager.
  62. *
  63. * @return The total number of commands
  64. */
  65. int GetConfigCmdNumber();
  66. /**
  67. * Retrieves a command by index.
  68. *
  69. * A command index is the position at which it was added to the
  70. * manager.
  71. */
  72. ConfigCmd* GetConfigCmd(unsigned int i) const;
  73. private:
  74. /**
  75. * Forbidden copy constructor.
  76. *
  77. * @param rhs[in] Manager to not copy.
  78. */
  79. ConfigCmdManager(const ConfigCmdManager& rhs) = delete;
  80. /**
  81. * Forbidden copy constructor.
  82. *
  83. * @param rhs[in] Manager to not copy.
  84. */
  85. ConfigCmdManager operator =(const ConfigCmdManager& rhs) = delete;
  86. /**
  87. * Initializes the command.
  88. *
  89. * Must be called from the constructor.
  90. */
  91. void InitCmd();
  92. /**
  93. * List of command in the manager.
  94. */
  95. std::vector<std::unique_ptr<ConfigCmd>> commands_;
  96. };