-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Daniel Hilst
committed
Feb 12, 2025
1 parent
f202b6b
commit 425380a
Showing
9 changed files
with
280 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#ifndef CLOYSTER_SERVICES_FILES_H | ||
#define CLOYSTER_SERVICES_FILES_H | ||
|
||
#include <filesystem> | ||
#include <string> | ||
#include <unordered_map> | ||
#include <concepts> | ||
#include <vector> | ||
|
||
namespace cloyster::services::files { | ||
template <typename File> | ||
|
||
concept IsKeyFileReadable = requires(const File& file, const std::string& group, const std::string& key) | ||
{ | ||
{ file.getGroups() } -> std::convertible_to<std::vector<std::string>>; | ||
{ file.getString(group, key) } -> std::same_as<std::string>; | ||
{ file.getBoolean(group, key) } -> std::same_as<bool>; | ||
{ file.getStringOpt(group, key) } -> std::same_as<std::optional<std::string>>; | ||
}; | ||
|
||
// @TODO Tying PIMPL here but failing miserably | ||
// - already tried private function | ||
// - .. public constructor | ||
// - move Impl outside KeyFile | ||
struct KeyFileImpl; | ||
class KeyFile { | ||
using Impl = KeyFileImpl; | ||
|
||
std::unique_ptr<Impl> m_impl; | ||
|
||
explicit KeyFile(const Impl& impl); | ||
public: | ||
|
||
[[nodiscard]] std::vector<std::string> getGroups() const; | ||
[[nodiscard]] std::string getString(const std::string& group, const std::string& key) const; | ||
[[nodiscard]] bool getBoolean(const std::string& group, const std::string& key) const; | ||
[[nodiscard]] std::optional<std::string> getStringOpt(const std::string& group, const std::string& key) const; | ||
|
||
explicit KeyFile(const std::filesystem::path& path); | ||
explicit KeyFile(std::istream& istream); | ||
}; | ||
static_assert(IsKeyFileReadable<KeyFile>); | ||
|
||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Oops, something went wrong.