-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
d0b43f2
commit 16e2e94
Showing
7 changed files
with
127 additions
and
91 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,34 @@ | ||
#pragma once | ||
|
||
#include "ap/action/specifiers.hpp" | ||
|
||
namespace ap::action::detail { | ||
|
||
/** | ||
* @brief The concept is satisfied when `AS` is either a valued or void argument action | ||
* @tparam AS The action specifier type. | ||
*/ | ||
template <typename AS> | ||
concept c_action_specifier = ap::detail::c_one_of<AS, action_type::transform, action_type::modify>; | ||
|
||
/// @brief Template argument action callable type alias. | ||
template <c_action_specifier AS, ap::detail::c_argument_value_type T> | ||
using callable_type = typename AS::template type<T>; | ||
|
||
/// @brief Template argument action callabla variant type alias. | ||
template <ap::detail::c_argument_value_type T> | ||
using action_variant_type = | ||
std::variant<callable_type<action_type::transform, T>, callable_type<action_type::modify, T>>; | ||
|
||
/** | ||
* @brief Checks if an argument action variant holds a void action. | ||
* @tparam T The argument value type. | ||
* @param action The action variant. | ||
* @return True if the held action is a void action. | ||
*/ | ||
template <ap::detail::c_argument_value_type T> | ||
[[nodiscard]] constexpr inline bool is_void_action(const action_variant_type<T>& action) noexcept { | ||
return std::holds_alternative<callable_type<action_type::modify, T>>(action); | ||
} | ||
|
||
} // namespace ap::action::detail |
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,24 @@ | ||
#pragma once | ||
|
||
#include "ap/error/exceptions.hpp" | ||
#include "detail/utility.hpp" | ||
|
||
#include <filesystem> | ||
|
||
namespace ap::action { | ||
|
||
/// @brief Returns a default argument action. | ||
template <ap::detail::c_argument_value_type T> | ||
detail::callable_type<ap::action_type::modify, T> none() noexcept { | ||
return [](T&) {}; | ||
} | ||
|
||
/// @brief Returns a predefined action for file name handling arguments. Checks whether a file with the given name exists. | ||
inline detail::callable_type<ap::action_type::modify, std::string> check_file_exists() noexcept { | ||
return [](std::string& file_path) { | ||
if (not std::filesystem::exists(file_path)) | ||
throw argument_parser_exception(std::format("File `{}` does not exists!", file_path)); | ||
}; | ||
} | ||
|
||
} // namespace ap::action |
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,39 @@ | ||
#pragma once | ||
|
||
#include "ap/detail/concepts.hpp" | ||
|
||
#include <functional> | ||
|
||
namespace ap::action_type { | ||
|
||
// TODO: | ||
// * on_read_action | ||
// * on_flag_action | ||
|
||
/* | ||
* @brief Represents a transformating action. | ||
* | ||
* Represents an argument action which transforms the parsed value and | ||
* returns a new value with which the argument will be initialized. | ||
*/ | ||
struct transform { | ||
template <ap::detail::c_argument_value_type T> | ||
using type = std::function<T(const T&)>; | ||
}; | ||
|
||
/* | ||
* @brief Represents a modifying action. | ||
* | ||
* Represents an argument action which modifies the value of an | ||
* already initialized argument. | ||
* | ||
* NOTE: The modify action doesn't have to actually modify the | ||
* underlying value - it can simply perform some action on it. | ||
* Example: `ap::action::check_file_exists` | ||
*/ | ||
struct modify { | ||
template <ap::detail::c_argument_value_type T> | ||
using type = std::function<void(T&)>; | ||
}; | ||
|
||
} // namespace ap::action_type |
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