-
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 7a62fc3
Showing
10 changed files
with
270 additions
and
206 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
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,53 @@ | ||
#ifndef CLOYSTER_SERVICES_FILES_H | ||
#define CLOYSTER_SERVICES_FILES_H | ||
|
||
#include <filesystem> | ||
#include <string> | ||
#include <concepts> | ||
#include <vector> | ||
|
||
#include <cloysterhpc/concepts.h> | ||
|
||
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>>; | ||
}; | ||
|
||
/** | ||
* @brief Represents a KeyFile hiding the implementation details behind Impl | ||
*/ | ||
class KeyFile { | ||
struct Impl; // Pointer to Implementation (PIMPL) pattern | ||
std::unique_ptr<Impl> m_impl; | ||
explicit KeyFile(Impl&& impl); | ||
public: | ||
~KeyFile(); // The destructor is required to be defined in | ||
// the .cpp file where the size of Impl is known | ||
|
||
// Moveable, not Copiable | ||
KeyFile(const KeyFile&) = delete; | ||
KeyFile(KeyFile&& file) = default; | ||
KeyFile& operator=(const KeyFile&) = delete; | ||
KeyFile& operator=(KeyFile&&) = default; | ||
|
||
[[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>); | ||
static_assert(concepts::IsMoveable<KeyFile>); | ||
static_assert(!concepts::IsCopyable<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.