Loading...
Searching...
No Matches
caf::message Class Reference

Describes a fixed-length, copy-on-write, type-erased tuple with elements of any type. More...

`#include <message.hpp>`

Inheritance diagram for caf::message:

## Classes

struct | cli_res
| Stores the result of message::extract_opts. More...
struct | cli_arg
| Stores the name of a command line option ("<long name>[,<short name>]") along with a description and a callback. More...

## Public Types

using | raw_ptr = detail::message_data*
| Raw pointer to content.
using | data_ptr = detail::message_data::cow_ptr
| Copy-on-write pointer to content.
using | help_factory = std::function<std::string (const std::vector<cli_arg>&)>
| Function object for generating CLI argument help text.

## Public Member Functions

| message (none_t) noexcept
| message (const message &) noexcept=default
message & | operator= (const message &) noexcept=default
| message (message &&) noexcept
message & | operator= (message &&) noexcept
| message (data_ptr ptr) noexcept
void * | get_mutable (size_t p) override
| Returns a mutable pointer to the element at position pos.
error | load (size_t pos, deserializer &source) override
| Load the content for the element at position pos from source.
size_t | size () const noexcept override
| Returns the size of this tuple.
uint32_t | type_token () const noexcept override
| Returns a type hint for the element types.
rtti_pair | type (size_t pos) const noexcept override
| Returns the type number and std::type_info object for the element at position pos.
const void * | get (size_t pos) const noexcept override
| Returns the element at position pos.
std::string | stringify (size_t pos) const override
| Returns a string representation of the element at position pos.
type_erased_value_ptr | copy (size_t pos) const override
| Returns a copy of the element at position pos.
error | save (size_t pos, serializer &sink) const override
| Saves the element at position pos to sink.
bool | shared () const noexcept override
| Returns whether multiple references to this tuple exist.
error | load (deserializer &source) override
| Load the content for the tuple from source.
error | save (serializer &sink) const override
| Saves the content of the tuple to sink.
message & | operator+= (const message &x)
| Concatenates *this and x.
optional< message > | apply (message_handler handler)
| Returns handler(*this).
void | force_unshare ()
| Forces the message to copy its content if there are more than one references to the content.
data_ptr & | vals ()
| Returns a mutable reference to the content.
void | swap (message &other) noexcept
| Exchanges content of this and other.
void | reset (raw_ptr new_ptr=nullptr, bool add_ref=true) noexcept
| Assigns new content.
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 | slice (size_t pos, size_t n) const
| Creates a new message of size n starting at the element at position p.
message | extract (message_handler handler) const
| Filters this message by applying slices of it to handler and returns the remaining elements of this operation.
cli_res | extract_opts (std::vector< cli_arg > xs, const help_factory &f=nullptr, bool no_help=false) const
| A simplistic interface for using extract to parse command line options.
const void * | at (size_t p) const noexcept
| Returns a const pointer to the element at position p.
const data_ptr & | vals () const noexcept
| Returns a reference to the content.
const data_ptr & | cvals () const noexcept
| Returns a reference to the content.
message | take (size_t n) const
| Returns the size of this message.
message | take_right (size_t n) const
| Creates a new message from the last n values.
Public Member Functions inherited from caf::type_erased_tuple
| type_erased_tuple (const type_erased_tuple &)=default
type_erased_tuple & | operator= (const type_erased_tuple &)=default
bool | empty () const
| Returns size() == 0.
std::string | stringify () const
| Returns a string representation of the tuple.
bool | matches (size_t pos, uint16_t nr, const std::type_info *ptr) const noexcept
| Checks whether the type of the stored value at position pos matches type number n and run-time type information p.
uint16_t | type_nr (size_t pos) const noexcept
| Returns the type number for the element at position pos.
bool | matches (size_t pos, const rtti_pair &rtti) const noexcept
| Checks whether the type of the stored value matches rtti.
template<class T>
const T & | get_as (size_t pos) const
| Convenience function for *reinterpret_cast<const T*>(get()).
template<class T, size_t Pos>
const T & | get_as (typed_index< T, Pos >) const
template<class... Ts, long... Is>
std::tuple< const Ts &... > | get_as_tuple (detail::type_list< Ts... >, detail::int_list< Is... >) const
template<class... Ts>
std::tuple< const Ts &... > | get_as_tuple () const
template<class T>
T & | get_mutable_as (size_t pos)
| Convenience function for *reinterpret_cast<T*>(get_mutable()).
template<class T>
T | move_if_unshared (size_t pos)
| Convenience function for moving a value out of the tuple if it is unshared.
template<class T>
bool | match_element (size_t pos) const noexcept
| Returns true if the element at pos matches T.
template<class... Ts>
bool | match_elements () const noexcept
| Returns true if the pattern Ts... matches the content of this tuple.
template<class F>
auto | apply (F fun) -> optional< typename detail::get_callable_trait< F >::result_type >

## Static Public Member Functions

template<class... Ts>
static message | concat (const Ts &... xs)
| Creates a new message by concatenating xs....
static message | copy (const type_erased_tuple &xs)
| Creates a new message by copying all elements in a type-erased tuple.
Static Public Member Functions inherited from caf::type_erased_tuple
template<class T, size_t Pos>
static constexpr typed_index< T, Pos > | make_typed_index ()

## Related Symbols

(Note that these are not member symbols.)
template<class T, class... Ts>
std::enable_if<!std::is_same< message, typenamestd::decay< T >::type >::value||(sizeof...(Ts)>0), message >::type | make_message (T &&x, Ts &&... xs)
| Returns a new message containing the values (x, xs...).
message | make_message (message other)
| Returns a copy of `other`.
message | make_message ()
| Returns an empty message.
error | inspect (serializer &sink, message &msg)
error | inspect (deserializer &source, message &msg)
std::string | to_string (const message &msg)
message | operator+ (const message &lhs, const message &rhs)
Related Symbols inherited from caf::type_erased_tuple
template<class... Ts>
detail::type_erased_tuple_view< Ts... > | make_type_erased_tuple_view (Ts &... xs)
template<class Processor>
std::enable_if< Processor::reads_state >::type | serialize (Processor &proc, type_erased_tuple &x)
template<class Processor>
std::enable_if< Processor::writes_state >::type | serialize (Processor &proc, type_erased_tuple &x)
std::string | to_string (const type_erased_tuple &x)

## Detailed Description

Describes a fixed-length, copy-on-write, type-erased tuple with elements of any type.

## Member Function Documentation

## copy()

type_erased_value_ptr caf::message::copy | ( | size_t | pos | ) | const

override virtual

Returns a copy of the element at position pos.

Implements caf::type_erased_tuple.

## extract()

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:

auto msg = make_message(1, 2.f, 3.f, 4);
// extract float and integer pairs
auto msg2 = msg.extract({
[](float, float) { },
[](int, int) { }
});
assert(msg2 == make_message(1, 4));
caf::message::make_message
message make_message()
Returns an empty message.
Definition make_message.hpp:110

Step-by-step explanation:

- Slice 1: (1, 2.f, 3.f, 4), no match
- Slice 2: (1, 2.f, 3.f), no match
- Slice 3: (1, 2.f), no match
- Slice 4: (1), no match
- Slice 5: (2.f, 3.f, 4), no match
- Slice 6: (2.f, 3.f), match; new message is (1, 4)
- Slice 7: (4), no match

Slice 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.

## extract_opts()

cli_res caf::message::extract_opts | ( | std::vector< cli_arg > | xs,
|  | const help_factory & | f = nullptr,
|  | bool | no_help = false ) const

A simplistic interface for using extract to parse command line options.

Usage example:

int main(int argc, char** argv) {
uint16_t port;
string host = "localhost";
auto res = message_builder(argv + 1, argv + argc).extract_opts({
{"port,p", "set port", port},
{"host,H", "set host (default: localhost)", host},
{"verbose,v", "enable verbose mode"}
});
if (!res.error.empty()) {
cerr << res.error << endl;
return 1;
}
if (res.opts.count("help") > 0) {
// CLI arguments contained "-h", "--help", or "-?" (builtin);
cout << res.helptext << endl;
return 0;
}
if (!res.remainder.empty()) {
// ... extract did not consume all CLI arguments ...
}
if (res.opts.count("verbose") > 0) {
// ... enable verbose mode ...
}
// ...
}
caf::message_builder
Provides a convenient interface for createing message objects from a series of values using the membe...
Definition message_builder.hpp:32
caf::message_builder::extract_opts
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.
Definition message_builder.hpp:113

Parameters

  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.

Returns
  A struct containing remainder (i.e. unmatched elements), a set containing the names of all used arguments, and the generated help text.

Exceptions

  std::invalid_argument | if no name or more than one long name is set

## get()

const void * caf::message::get | ( | size_t | pos | ) | const

override virtual noexcept

Returns the element at position pos.

Implements caf::type_erased_tuple.

## get_mutable()

void * caf::message::get_mutable | ( | size_t | pos | ) |

override virtual

Returns a mutable pointer to the element at position pos.

Implements caf::type_erased_tuple.

## load() [1/2]

error caf::message::load | ( | deserializer & | source | ) |

override virtual

Load the content for the tuple from source.

Reimplemented from caf::type_erased_tuple.

## load() [2/2]

error caf::message::load | ( | size_t | pos,
|  | deserializer & | source )

override virtual

Load the content for the element at position pos from source.

Implements caf::type_erased_tuple.

## save() [1/2]

error caf::message::save | ( | serializer & | sink | ) | const

override virtual

Saves the content of the tuple to sink.

Reimplemented from caf::type_erased_tuple.

## save() [2/2]

error caf::message::save | ( | size_t | pos,
|  | serializer & | sink ) const

override virtual

Saves the element at position pos to sink.

Implements caf::type_erased_tuple.

## shared()

bool caf::message::shared | ( |  | ) | const

override virtual noexcept

Returns whether multiple references to this tuple exist.

The default implementation returns false.

Reimplemented from caf::type_erased_tuple.

## size()

size_t caf::message::size | ( |  | ) | const

override virtual noexcept

Returns the size of this tuple.

Implements caf::type_erased_tuple.

## stringify()

std::string caf::message::stringify | ( | size_t | pos | ) | const

override virtual

Returns a string representation of the element at position pos.

Implements caf::type_erased_tuple.

## take()

message caf::message::take | ( | size_t | n | ) | const

Returns the size of this message.

Creates a new message from the first n values.

## type()

rtti_pair caf::message::type | ( | size_t | pos | ) | const

override virtual noexcept

Returns the type number and std::type_info object for the element at position pos.

Implements caf::type_erased_tuple.

## type_token()

uint32_t caf::message::type_token | ( |  | ) | const

override virtual noexcept

Returns a type hint for the element types.

Implements caf::type_erased_tuple.

## vals()

data_ptr & caf::message::vals | ( |  | ) |

Returns a mutable reference to the content.

Callers are responsible for unsharing content if necessary.

The documentation for this class was generated from the following files:

- /build/actor-framework-Z9pIPl/actor-framework-0.17.6/libcaf_core/caf/message.hpp
- /build/actor-framework-Z9pIPl/actor-framework-0.17.6/libcaf_core/caf/make_message.hpp