Misc Improvements (#7)
* get rid of optional<ptr> -> double indirection * more optional cleanup * fix * add more render pixel type options * towards different views * missing virtual declaration of ShowImage * fix runtime * init image view factory * fix build Render Image close button re-enable add readme init documentation use awesomeDoxygen ci build docs install doxygen id token permission add pages write permission
This commit is contained in:
committed by
Maximilian Kueffner
parent
0be064bb8e
commit
235d00192a
@@ -1,6 +1,7 @@
|
||||
set(RESOURCELIBNAME pixelariumresourcelib)
|
||||
|
||||
set(RESOURCELIBSRC
|
||||
resource.hpp
|
||||
resource.cpp)
|
||||
|
||||
add_library(${RESOURCELIBNAME} STATIC
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
#include <cstddef>
|
||||
#include <functional>
|
||||
#include <mutex>
|
||||
#include <optional>
|
||||
|
||||
using pixelarium::imaging::IPixelariumImage;
|
||||
using namespace std;
|
||||
@@ -22,10 +21,10 @@ size_t GenerateId() { return id_.fetch_add(1, memory_order_relaxed); }
|
||||
/// @brief Retrieves a resource from the pool.
|
||||
/// @param id The ID of the resource to retrieve.
|
||||
/// @return A pointer to the resource if found, otherwise an empty optional.
|
||||
std::optional<std::weak_ptr<IPixelariumImage>> pixelarium::resources::ImageResourcePool::GetResource(ResourceKey id) const
|
||||
std::weak_ptr<IPixelariumImage> pixelarium::resources::ImageResourcePool::GetResource(ResourceKey id) const
|
||||
{
|
||||
auto search{this->resources_.find(id)};
|
||||
if (search == this->resources_.end()) return std::nullopt;
|
||||
if (search == this->resources_.end()) return {};
|
||||
|
||||
return search->second;
|
||||
}
|
||||
@@ -81,7 +80,7 @@ bool pixelarium::resources::ImageResourcePool::DeleteResource(ResourceKey id)
|
||||
/// @param func A function to call for each resource. The function should accept the resource ID and a const reference
|
||||
/// to a PixelariumImage.
|
||||
void pixelarium::resources::ImageResourcePool::EnumerateResources(
|
||||
const std::function<void(ResourceKey, size_t, const imaging:: IPixelariumImage&)>& func)
|
||||
const std::function<void(ResourceKey, size_t, const imaging::IPixelariumImage&)>& func)
|
||||
{
|
||||
size_t idx{0};
|
||||
for (const auto& e : this->resources_)
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <optional>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "imaging/IPixelariumImage.hpp"
|
||||
@@ -16,13 +15,14 @@ using ResourceKey = size_t;
|
||||
struct empty_resource_exception : public std::exception
|
||||
{
|
||||
empty_resource_exception() {};
|
||||
empty_resource_exception(const char* msg) : message_(msg) {};
|
||||
const char* what() { return message_; }
|
||||
empty_resource_exception(std::string& msg) : message_(msg) {};
|
||||
const std::string& what() { return message_; }
|
||||
|
||||
private:
|
||||
const char* message_ = "Empty Resource";
|
||||
std::string message_ = "Empty Resource";
|
||||
};
|
||||
|
||||
|
||||
struct IResource
|
||||
{
|
||||
virtual ~IResource() = default;
|
||||
@@ -36,7 +36,7 @@ class IResourcePool
|
||||
{
|
||||
public:
|
||||
virtual ~IResourcePool() = default;
|
||||
virtual std::optional<std::weak_ptr<ResT>> GetResource(size_t id) const = 0;
|
||||
virtual std::weak_ptr<ResT> GetResource(size_t id) const = 0;
|
||||
virtual ResourceKey SetResource(std::unique_ptr<ResT> res) = 0;
|
||||
virtual bool ModifyResource(ResourceKey id, std::unique_ptr<ResT> res) = 0;
|
||||
virtual bool DeleteResource(ResourceKey id) = 0;
|
||||
@@ -61,7 +61,7 @@ class ImageResourcePool : public IResourcePool<imaging::IPixelariumImage>
|
||||
ImageResourcePool& operator=(ImageResourcePool&) = delete;
|
||||
ImageResourcePool& operator=(ImageResourcePool&&) = delete;
|
||||
|
||||
std::optional<std::weak_ptr<imaging::IPixelariumImage>> GetResource(ResourceKey id) const override;
|
||||
std::weak_ptr<imaging::IPixelariumImage> GetResource(ResourceKey id) const override;
|
||||
ResourceKey SetResource(std::unique_ptr<imaging::IPixelariumImage> res) override;
|
||||
bool ModifyResource(ResourceKey id, std::unique_ptr<imaging::IPixelariumImage> res) override;
|
||||
bool DeleteResource(ResourceKey id) override;
|
||||
|
||||
Reference in New Issue
Block a user