/usr/include/caf/message_builder.hpp is in libcaf-dev 0.13.2-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | /******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright (C) 2011 - 2015 *
* Dominik Charousset <dominik.charousset (at) haw-hamburg.de> *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#ifndef CAF_MESSAGE_BUILDER_HPP
#define CAF_MESSAGE_BUILDER_HPP
#include <vector>
#include "caf/message.hpp"
#include "caf/message_handler.hpp"
#include "caf/uniform_type_info.hpp"
namespace caf {
/**
* Provides a convenient interface for createing `message` objects
* from a series of values using the member function `append`.
*/
class message_builder {
public:
message_builder(const message_builder&) = delete;
message_builder& operator=(const message_builder&) = delete;
message_builder();
~message_builder();
/**
* Creates a new instance and immediately calls `append(first, last)`.
*/
template <class Iter>
message_builder(Iter first, Iter last) {
init();
append(first, last);
}
/**
* Adds `what` to the elements of the buffer.
*/
message_builder& append(uniform_value what);
/**
* Appends all values in range [first, last).
*/
template <class Iter>
message_builder& append(Iter first, Iter last) {
using vtype = typename std::decay<decltype(*first)>::type;
using converted = typename detail::implicit_conversions<vtype>::type;
auto uti = uniform_typeid<converted>();
for (; first != last; ++first) {
auto uval = uti->create();
*reinterpret_cast<converted*>(uval->val) = *first;
append(std::move(uval));
}
return *this;
}
/**
* Adds `x` to the elements of the buffer.
*/
template <class T>
message_builder& append(T x) {
return append_impl<T>(std::move(x));
}
/**
* Converts the buffer to an actual message object without
* invalidating this message builder (nor clearing it).
*/
message to_message() const;
/**
* Converts the buffer to an actual message object and transfers
* ownership of the data to it, leaving this object in an invalid state.
* @warning Calling *any* member function on this object afterwards
* is undefined behavior (dereferencing a `nullptr`)
*/
message move_to_message();
/**
* @copydoc message::extract
*/
inline message extract(message_handler f) const {
return to_message().extract(f);
}
/**
* @copydoc message::extract_opts
*/
inline message::cli_res extract_opts(std::vector<message::cli_arg> xs,
message::help_factory f
= nullptr) const {
return to_message().extract_opts(std::move(xs), std::move(f));
}
/**
* @copydoc message::apply
*/
optional<message> apply(message_handler handler);
/**
* Removes all elements from the buffer.
*/
void clear();
/**
* Returns whether the buffer is empty.
*/
bool empty() const;
/**
* Returns the number of elements in the buffer.
*/
size_t size() const;
private:
void init();
template <class T>
message_builder&
append_impl(typename unbox_message_element<
typename detail::implicit_conversions<T>::type
>::type what) {
using type = decltype(what);
auto uti = uniform_typeid<type>();
auto uval = uti->create();
*reinterpret_cast<type*>(uval->val) = std::move(what);
return append(std::move(uval));
}
class dynamic_msg_data;
dynamic_msg_data* data();
const dynamic_msg_data* data() const;
intrusive_ptr<ref_counted> m_data; // hide dynamic_msg_data implementation
};
} // namespace caf
#endif // CAF_MESSAGE_BUILDER_HPP
|