CAF  0.17.3
Public Types | Public Member Functions | Static Public Member Functions | Related Functions | List of all members
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:
caf::type_erased_tuple

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.
 

Public Member Functions

 message (none_t) noexcept
 
 message (const message &) noexcept=default
 
messageoperator= (const message &) noexcept=default
 
 message (message &&) noexcept
 
messageoperator= (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.
 
error_code< secload (size_t pos, binary_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.
 
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.
 
error_code< secsave (size_t pos, binary_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. More...
 
error load (deserializer &source) override
 Load the content for the tuple from source.
 
error_code< secload (binary_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.
 
error_code< secsave (binary_serializer &sink) const override
 Saves the content of the tuple to sink.
 
optional< messageapply (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_ptrvals ()
 Returns a mutable reference to the content. More...
 
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.
 
const void * at (size_t p) const noexcept
 Returns a const pointer to the element at position p.
 
const data_ptrvals () const noexcept
 Returns a reference to the content.
 
const data_ptrcvals () const noexcept
 Returns a reference to the content.
 
- Public Member Functions inherited from caf::type_erased_tuple
 type_erased_tuple (const type_erased_tuple &)=default
 
type_erased_tupleoperator= (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 >
move_if_unshared (size_t pos)
 Convenience function for moving a value out of the tuple if it is unshared. More...
 
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

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 Functions

(Note that these are not member functions.)

template<class T , class... Ts>
message make_message (T &&x, Ts &&... xs)
 Returns a new message containing the values (x, xs...).
 
message make_message ()
 Returns an empty message.
 
CAF_CORE_EXPORT error inspect (serializer &sink, message &msg)
 
CAF_CORE_EXPORT error_code< secinspect (binary_serializer &sink, message &msg)
 
CAF_CORE_EXPORT error inspect (deserializer &source, message &msg)
 
CAF_CORE_EXPORT error_code< secinspect (binary_deserializer &source, message &msg)
 
CAF_CORE_EXPORT std::string to_string (const message &msg)
 

Detailed Description

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

Member Function Documentation

◆ shared()

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

Returns whether multiple references to this tuple exist.

The default implementation returns false.

Reimplemented from 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: