Skip to content

Commit

Permalink
Remove unnecessary include in cache and make the class use the rule of 0
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonMaracine committed Apr 5, 2024
1 parent 8fcd17f commit c95a05a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 21 deletions.
22 changes: 3 additions & 19 deletions src/resmanager/detail/cache.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#pragma once

#include <memory>
#include <unordered_map>
#include <cstddef>
#include <utility>
Expand All @@ -14,22 +13,7 @@ namespace resmanager {
public:
using ResourceType = typename L::ResourceType;

Cache() = default;
~Cache() = default;
Cache(const Cache&) = default;
Cache& operator=(const Cache&) = default;

Cache(Cache&& other) noexcept {
cache = std::move(other.cache);
}

Cache& operator=(Cache&& other) noexcept {
cache = std::move(other.cache);

return *this;
}

// If already present, return the resource directly, otherwise load it
// If already present, return the resource directly, otherwise load and then return it
template<typename... Args>
ResourceType load(const K id, Args&&... args) {
if (auto iter = cache.find(id); iter != cache.end()) {
Expand All @@ -53,9 +37,9 @@ namespace resmanager {
return resource;
}

// Get the resource
// Get the resource; throws std::out_of_range, if resource is not found
ResourceType operator[](const K id) const {
return cache.at(id);
return cache.at(id); // TODO maybe handle exception here and return null
}

// Check if the resource is present
Expand Down
2 changes: 1 addition & 1 deletion src/resmanager/detail/hashing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <cstdint>
#include <cstddef>
#include <string>
#include <functional>
#include <functional> // For std::hash

// Implements the Fowler-Noll-Vo hash algorithm, or more exactly FNV-1a

Expand Down
2 changes: 1 addition & 1 deletion src/resmanager/detail/version.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
namespace resmanager {
inline constexpr unsigned int VERSION_MAJOR = 0;
inline constexpr unsigned int VERSION_MINOR = 8;
inline constexpr unsigned int VERSION_PATCH = 1;
inline constexpr unsigned int VERSION_PATCH = 2;
}

0 comments on commit c95a05a

Please sign in to comment.