refactor(resource): increased const correctness

This commit is contained in:
2025-04-30 07:36:23 -04:00
parent 90083113b5
commit afccf30840
2 changed files with 6 additions and 8 deletions

View File

@@ -35,10 +35,10 @@
#define TOSTRING(x) STRINGIFY(x) #define TOSTRING(x) STRINGIFY(x)
ResourceManager::ResourceManager() { ResourceManager::ResourceManager() {
std::string defaultDataDir = TOSTRING(DATA_DIR); const std::string defaultDataDir = TOSTRING(DATA_DIR);
m_dataDir = m_config.get<std::string>("Data:Dir", defaultDataDir); m_dataDir = m_config.get<std::string>("Data:Dir", defaultDataDir);
// -- Get the index file path using filesytem to make it a system safe path // -- Get the index file path using filesytem to make it a system safe path
std::string indexFilePath = m_dataDir + "/index.yaml"; const std::string indexFilePath = m_dataDir + "/index.yaml";
// TODO Add checks to make sure data dir exists and index.yaml exists // TODO Add checks to make sure data dir exists and index.yaml exists
const std::filesystem::path indexFile(indexFilePath); const std::filesystem::path indexFile(indexFilePath);
@@ -49,15 +49,13 @@ ResourceManager::ResourceManager() {
} }
std::vector<std::string> ResourceManager::getAvaliableResources() { std::vector<std::string> ResourceManager::getAvaliableResources() const {
std::vector<std::string> resources; const std::vector<std::string> resources = m_resourceConfig.keys();
resources = m_resourceConfig.keys();
return resources; return resources;
} }
const Resource& ResourceManager::getResource(const std::string &name) const { const Resource& ResourceManager::getResource(const std::string &name) const {
auto it = m_resources.find(name); if (const auto it = m_resources.find(name); it != m_resources.end()) {
if (it != m_resources.end()) {
return it->second; return it->second;
} }
throw std::runtime_error("Resource " + name + " not found"); throw std::runtime_error("Resource " + name + " not found");

View File

@@ -90,7 +90,7 @@ public:
* std::vector<std::string> resources = manager.getAvaliableResources(); * std::vector<std::string> resources = manager.getAvaliableResources();
* @endcode * @endcode
*/ */
std::vector<std::string> getAvaliableResources(); std::vector<std::string> getAvaliableResources() const;
/** /**
* @brief Gets a resource by name. * @brief Gets a resource by name.