diff --git a/include/avk/commands.hpp b/include/avk/commands.hpp index fb4a784..b5c723c 100644 --- a/include/avk/commands.hpp +++ b/include/avk/commands.hpp @@ -1445,7 +1445,13 @@ namespace avk return result; } - // TODO: Comment + /** Convenience function for gathering recorded commands---one avk::command for each entry of a given collection. + * @aCollection Collection to iterate over + * @aGenerator Callback function which must return exactly one command (i.e. must be assignable to avk::recorded_commands_t). + * @example std::vector numbers = {1, 2, 3}; + * avk::command::one_for_each(numbers, [](const int& aNumber) { return ... }; + * @return A vector of recorded commands + */ template inline static std::vector one_for_each(const T& aCollection, F aGenerator) { @@ -1456,7 +1462,13 @@ namespace avk return result; } - // TODO: Comment + /** Convenience function for gathering recorded commands---a collection of commands for each entry of a given collection. + * @aCollection Collection to iterate over + * @aGenerator Callback function which must return a vector of commands (i.e. must be assignable to std::vector). + * @example std::vector numbers = {1, 2, 3}; + * avk::command::one_for_each(numbers, [](const int& aNumber) { return avk::command::gather( ... ); }; + * @return A vector of recorded commands + */ template inline static std::vector many_for_each(const T& aCollection, F aGenerator) { @@ -1470,6 +1482,41 @@ namespace avk return result; } + /** Convenience function for gathering recorded commands, namely a total number of aN. + * @aN Collection to iterate over + * @aGenerator Callback function which must return exactly one command (i.e. must be assignable to avk::recorded_commands_t). + * @example avk::command::one_n_times(5, [](int aIndex) { return ... }; + * @return A vector of recorded commands + */ + template + inline static std::vector one_n_times(I aN, F aGenerator) + { + std::vector result; + for (I i = 0; i < aN; ++i) { + result.push_back(aGenerator(i)); + } + return result; + } + + /** Convenience function for gathering recorded commands, namely a total number of aN. + * @aN Collection to iterate over + * @aGenerator Callback function which must return exactly one command (i.e. must be assignable to avk::recorded_commands_t). + * @example avk::command::many_n_times(5, [](int aIndex) { return avk::command::gather( ... ); }; + * @return A vector of recorded commands + */ + template + inline static std::vector many_n_times(I aN, F aGenerator) + { + std::vector result; + for (I i = 0; i < aN; ++i) { + auto commands = aGenerator(i); + for (auto& command : commands) { + result.push_back(std::move(command)); + } + } + return result; + } + // TODO: Comment template inline static avk::recorded_commands_t conditional(C aCondition, F1 aPositive)