CAF 0.17.6
|
Provides a convenient interface for createing message
objects from a series of values using the member function append
.
More...
#include <message_builder.hpp>
Public Member Functions | |
message_builder (const message_builder &)=delete | |
message_builder & | operator= (const message_builder &)=delete |
template<class Iter > | |
message_builder (Iter first, Iter last) | |
Creates a new instance and immediately calls append(first, last) . | |
template<class Iter > | |
message_builder & | append (Iter first, Iter last) |
Appends all values in range [first, last). | |
template<class T > | |
message_builder & | append (T &&x) |
Adds x to the elements of the buffer. | |
message_builder & | append_all () |
template<class T , class... Ts> | |
message_builder & | append_all (T &&x, Ts &&... xs) |
template<size_t N, class... Ts> | |
message_builder & | append_tuple (std::integral_constant< size_t, N >, std::integral_constant< size_t, N >, std::tuple< Ts... > &) |
template<size_t I, size_t N, class... Ts> | |
message_builder & | append_tuple (std::integral_constant< size_t, I >, std::integral_constant< size_t, N > e, std::tuple< Ts... > &xs) |
template<class... Ts> | |
message_builder & | append_tuple (std::tuple< Ts... > xs) |
message | to_message () const |
Converts the buffer to an actual message object without invalidating this message builder (nor clearing it). | |
message | move_to_message () |
Converts the buffer to an actual message object and transfers ownership of the data to it, leaving this object in an invalid state. | |
message | extract (message_handler f) const |
Filters this message by applying slices of it to handler and returns the remaining elements of this operation. | |
message::cli_res | extract_opts (std::vector< message::cli_arg > xs, message::help_factory f=nullptr, bool no_help=false) const |
A simplistic interface for using extract to parse command line options. | |
optional< message > | apply (message_handler handler) |
Returns handler(*this) . | |
void | clear () |
Removes all elements from the buffer. | |
bool | empty () const |
Returns whether the buffer is empty. | |
size_t | size () const |
Returns the number of elements in the buffer. | |
Friends | |
class | message |
Provides a convenient interface for createing message
objects from a series of values using the member function append
.
optional< message > caf::message_builder::apply | ( | message_handler | handler | ) |
Returns handler(*this)
.
message caf::message_builder::extract | ( | message_handler | f | ) | const |
Filters this message by applying slices of it to handler
and returns the remaining elements of this operation.
Slices are generated in the sequence [0, size)
, [0, size-1)
, ...
, [1, size-1)
, ...
, [size-1, size)
. Whenever a slice matches, it is removed from the message and the next slice starts at the same index on the reduced message.
For example:
Step-by-step explanation:
(1, 2.f, 3.f, 4)
, no match(1, 2.f, 3.f)
, no match(1, 2.f)
, no match(1)
, no match(2.f, 3.f, 4)
, no match(2.f, 3.f)
, match; new message is (1, 4)
(4)
, no matchSlice 7 is (4)
, i.e., does not contain the first element, because the match on slice 6 occurred at index position 1. The function extract
iterates a message only once, from left to right.
message::cli_res caf::message_builder::extract_opts | ( | std::vector< message::cli_arg > | xs, |
message::help_factory | f = nullptr , |
||
bool | no_help = false |
||
) | const |
A simplistic interface for using extract
to parse command line options.
Usage example:
xs | List of argument descriptors. |
f | Optional factory function to generate help text (overrides the default generator). |
no_help | Suppress generation of default-generated help option. |
std::invalid_argument | if no name or more than one long name is set |
message caf::message_builder::move_to_message | ( | ) |
Converts the buffer to an actual message object and transfers ownership of the data to it, leaving this object in an invalid state.
nullptr
)