DotNameLib
Loading...
Searching...
No Matches
CustomStringsLoader.hpp
Go to the documentation of this file.
1#pragma once
2
6#include <memory>
7#include <mutex>
8
9namespace dotnamecpp::utils {
10
11 using dotnamecpp::assets::IAssetManager;
12
14 public:
15 CustomStringsLoader(std::shared_ptr<IAssetManager> assetManager,
16 std::shared_ptr<IJsonSerializer> jsonSerializer,
17 std::string filename = "customstrings.json");
18
23 ~CustomStringsLoader() override = default;
24
25 [[nodiscard]] Result<nlohmann::json, JsonError> load() const override;
26
27 [[nodiscard]] std::optional<std::string> getPath(const std::string &id) const override;
28
29 [[nodiscard]]
30 std::optional<std::string> getCustomKey(const std::string &id,
31 const std::string &key) const override;
32 [[nodiscard]]
33 std::optional<std::string> getLocalizedString(const std::string &id,
34 const std::string &locale = "en") const override;
35
36 private:
37 [[nodiscard]] Result<nlohmann::json, JsonError> ensureLoaded() const;
38 [[nodiscard]] std::optional<nlohmann::json> findById(const std::string &id) const;
39
40 std::shared_ptr<IAssetManager> assetManager_;
41 std::shared_ptr<IJsonSerializer> jsonSerializer_;
42 std::string filename_;
43
44 // Cached data
45 mutable std::mutex cacheMutex_;
46 mutable std::optional<nlohmann::json> cachedData_;
47 };
48
49} // namespace dotnamecpp::utils
CustomStringsLoader(std::shared_ptr< IAssetManager > assetManager, std::shared_ptr< IJsonSerializer > jsonSerializer, std::string filename="customstrings.json")
Definition CustomStringsLoader.cpp:6
CustomStringsLoader & operator=(CustomStringsLoader &&)=delete
std::optional< std::string > getLocalizedString(const std::string &id, const std::string &locale="en") const override
Get the Localized String object.
Definition CustomStringsLoader.cpp:103
Result< nlohmann::json, JsonError > load() const override
Load the custom strings JSON data.
Definition CustomStringsLoader.cpp:17
std::optional< std::string > getPath(const std::string &id) const override
Get the Path object.
Definition CustomStringsLoader.cpp:69
CustomStringsLoader(CustomStringsLoader &&)=delete
std::optional< std::string > getCustomKey(const std::string &id, const std::string &key) const override
Get the Custom Key object.
Definition CustomStringsLoader.cpp:86
CustomStringsLoader & operator=(const CustomStringsLoader &)=delete
CustomStringsLoader(const CustomStringsLoader &)=delete
Interface for loading custom strings from JSON.
Definition ICustomStringsLoader.hpp:14
Definition UtilsError.hpp:93
Definition DirectoryManager.cpp:5