diff options
| author | Markus Mittendrein <git@maxmitti.tk> | 2019-08-17 22:36:37 +0200 |
|---|---|---|
| committer | Markus Mittendrein <git@maxmitti.tk> | 2019-08-19 18:56:58 +0200 |
| commit | f40a21f5a6ca674d93905269bcb4b21f92c41800 (patch) | |
| tree | 79eb145e8828fdd2131f2a1251bc1f9133cedabc /src/cppc4group.hpp | |
| parent | 9f6da4965422b9f32c6a92b03b662bde025cc72c (diff) | |
| download | cc4group-f40a21f5a6ca674d93905269bcb4b21f92c41800.tar.gz cc4group-f40a21f5a6ca674d93905269bcb4b21f92c41800.zip | |
Add cc4group.addFromDisk with according cc4group.AllowEntryTypes
Diffstat (limited to 'src/cppc4group.hpp')
| -rw-r--r-- | src/cppc4group.hpp | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/src/cppc4group.hpp b/src/cppc4group.hpp index 420893c..7f51629 100644 --- a/src/cppc4group.hpp +++ b/src/cppc4group.hpp @@ -14,6 +14,7 @@ #include <optional> #include <cstdio> #include <functional> +#include <type_traits> class CppC4Group { // all C-related stuff is hidden from this header so it doesn't land in the precious C++-only code this might be used in... @@ -111,12 +112,18 @@ public: using WriteCallback = bool(*)(const void* const data, size_t const size, void* const arg); // these enums are just mapped to their C-counterparts internally - enum TmpMemoryStrategy { + enum class TmpMemoryStrategy { Memory, File, Auto }; + enum class AllowedEntryTypes { + File, + Directory, + All = File | Directory + }; + // use this to set one of the predefined strategies static void setTmpMemoryStrategy(const TmpMemoryStrategy strategy); @@ -167,6 +174,8 @@ public: bool deleteEntry(const std::string& path, const bool recursive = false); bool renameEntry(const std::string& oldPath, const std::string& newPath); + bool addFromDisk(const std::string& path, const std::string& targetPath, const AllowedEntryTypes allowedEntryTypes = AllowedEntryTypes::All); + bool createDirectory(const std::string& path); bool createFile(const std::string& path); @@ -176,3 +185,20 @@ public: // to get the child group out of the optional in case of success, construct a new CppC4Group with the move constructor: CppC4Group child{std::move(*optionalChild)}; std::optional<CppC4Group> openAsChild(const std::string& path); }; + +inline bool operator&(CppC4Group::AllowedEntryTypes lhs, CppC4Group::AllowedEntryTypes rhs) +{ + using T = std::underlying_type_t <CppC4Group::AllowedEntryTypes>; + return static_cast<T>(lhs) & static_cast<T>(rhs); +} + +inline CppC4Group::AllowedEntryTypes operator|(CppC4Group::AllowedEntryTypes lhs, CppC4Group::AllowedEntryTypes rhs) +{ + using T = std::underlying_type_t <CppC4Group::AllowedEntryTypes>; + return static_cast<CppC4Group::AllowedEntryTypes>(static_cast<T>(lhs) | static_cast<T>(rhs)); +} + +inline CppC4Group::AllowedEntryTypes& operator|=(CppC4Group::AllowedEntryTypes& lhs, CppC4Group::AllowedEntryTypes rhs) +{ + return lhs = lhs | rhs; +} |
