libcaf
0.13.2
|
Describes a fixed-length, copy-on-write, type-erased tuple with elements of any type. More...
#include <message.hpp>
Classes | |
struct | cli_arg |
Stores the name of a command line option ("<long name>[,<short name>]") along with a description and a callback. More... | |
struct | cli_res |
Stores the result of message::extract_opts . More... | |
Public Types | |
using | help_factory = std::function< std::string(const std::vector< cli_arg > &)> |
Public Member Functions | |
message ()=default | |
Creates an empty message. | |
message (message &&) | |
Move constructor. | |
message (const message &)=default | |
Copy constructor. | |
message & | operator= (message &&) |
Move assignment. | |
message & | operator= (const message &)=default |
Copy assignment. | |
size_t | size () const |
Returns the size of this message. | |
message | drop (size_t n) const |
Creates a new message with all but the first n values. | |
message | drop_right (size_t n) const |
Creates a new message with all but the last n values. | |
message | take (size_t n) const |
Creates a new message from the first n values. | |
message | take_right (size_t n) const |
Creates a new message from the last n values. | |
message | slice (size_t p, size_t n) const |
Creates a new message of size n starting at the element at position p . | |
void * | mutable_at (size_t p) |
Returns a mutable pointer to the element at position p . | |
const void * | at (size_t p) const |
Returns a const pointer to the element at position p . | |
const char * | uniform_name_at (size_t p) const |
Returns the uniform type name for the element at position p . | |
bool | equals (const message &other) const |
Returns true if `*this == other, otherwise false. | |
bool | empty () const |
Returns true if `size() == 0, otherwise false. | |
template<class T > | |
const T & | get_as (size_t p) const |
Returns the value at position p as const reference of type T . | |
template<class T > | |
T & | get_as_mutable (size_t p) |
Returns the value at position p as mutable reference of type T . | |
optional< message > | apply (message_handler handler) |
Returns handler(*this) . | |
message | extract (message_handler handler) const |
Filters this message by applying slices of it to handler and returns the remaining elements of this operation. More... | |
cli_res | extract_opts (std::vector< cli_arg > xs, help_factory f=nullptr) const |
A simplistic interface for using extract to parse command line options. More... | |
template<class T > | |
bool | match_element (size_t p) const |
Queries whether the element at position p is of type T . | |
template<class... Ts> | |
bool | match_elements () const |
Queries whether the types of this message are Ts... . | |
Static Public Member Functions | |
template<class... Ts> | |
static message | concat (const Ts &...xs) |
Concatinate messages. | |
Related Functions | |
(Note that these are not member functions.) | |
bool | operator== (const message &lhs, const message &rhs) |
bool | operator!= (const message &lhs, const message &rhs) |
message | operator+ (const message &lhs, const message &rhs) |
template<class V , class... Ts> | |
std::enable_if< !std::is_same< message, typename std::decay< V >::type >::value||(sizeof...(Ts) >) message::type | make_message (V &&x, Ts &&...xs) |
Returns a new message containing the values (x, xs...) . | |
message | make_message (message other) |
Returns a copy of other . | |
std::string | to_string (const message &what) |
Describes a fixed-length, copy-on-write, type-erased tuple with elements of any type.
message caf::message::extract | ( | message_handler | handler | ) | 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.
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). |
std::invalid_argument | if no name or more than one long name is set |
|
related |