本文整理汇总了C++中CAF_ASSERT函数的典型用法代码示例。如果您正苦于以下问题:C++ CAF_ASSERT函数的具体用法?C++ CAF_ASSERT怎么用?C++ CAF_ASSERT使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CAF_ASSERT函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: decorated_
decorated_tuple::decorated_tuple(cow_ptr&& d, vector_type&& v)
: decorated_(std::move(d)),
mapping_(std::move(v)),
type_token_(0xFFFFFFFF) {
CAF_ASSERT(mapping_.empty()
|| *(std::max_element(mapping_.begin(), mapping_.end()))
< static_cast<const cow_ptr&>(decorated_)->size());
// calculate type token
for (size_t i = 0; i < mapping_.size(); ++i) {
type_token_ <<= 6;
type_token_ |= decorated_->type_nr_at(mapping_[i]);
}
}
示例2: CAF_ASSERT
message message::drop(size_t n) const {
CAF_ASSERT(vals_);
if (n == 0) {
return *this;
}
if (n >= size()) {
return message{};
}
std::vector<size_t> mapping (size() - n);
size_t i = n;
std::generate(mapping.begin(), mapping.end(), [&] { return i++; });
return message {detail::decorated_tuple::make(vals_, mapping)};
}
示例3: prepend
// acquires both locks
void prepend(pointer value) {
CAF_ASSERT(value != nullptr);
node* tmp = new node(value);
node* first = nullptr;
// acquire both locks since we might touch last_ too
lock_guard guard1(head_lock_);
lock_guard guard2(tail_lock_);
first = head_.load();
CAF_ASSERT(first != nullptr);
auto next = first->next.load();
// first_ always points to a dummy with no value,
// hence we put the new element second
if (next) {
CAF_ASSERT(first != tail_);
tmp->next = next;
} else {
// queue is empty
CAF_ASSERT(first == tail_);
tail_ = tmp;
}
first->next = tmp;
}
示例4: switch
bool downstream_manager::check_paths_impl(path_algorithm algo,
path_predicate&) const noexcept {
// Return the result for empty ranges as specified by the C++ standard.
switch (algo) {
default:
CAF_ASSERT(algo == path_algorithm::all_of);
return true;
case path_algorithm::any_of:
return false;
case path_algorithm::none_of:
return true;
}
}
示例5: m_decorated
decorated_tuple::decorated_tuple(cow_ptr&& d, vector_type&& v)
: m_decorated(std::move(d)),
m_mapping(std::move(v)),
m_type_token(0xFFFFFFFF) {
CAF_ASSERT(m_mapping.empty()
|| *(std::max_element(m_mapping.begin(), m_mapping.end()))
< static_cast<const cow_ptr&>(m_decorated)->size());
// calculate type token
for (size_t i = 0; i < m_mapping.size(); ++i) {
m_type_token <<= 6;
m_type_token |= m_decorated->type_nr_at(m_mapping[i]);
}
}
示例6: synchronized_await
bool synchronized_await(Mutex& mtx, CondVar& cv, const TimePoint& timeout) {
CAF_ASSERT(!closed());
if (try_block()) {
std::unique_lock<Mutex> guard(mtx);
while (blocked()) {
if (cv.wait_until(guard, timeout) == std::cv_status::timeout) {
// if we're unable to set the queue from blocked to empty,
// than there's a new element in the list
return !try_unblock();
}
}
}
return true;
}
示例7: CAF_ASSERT
actor actor::splice_impl(std::initializer_list<actor> xs) {
CAF_ASSERT(xs.size() >= 2);
actor_system* sys = nullptr;
std::vector<strong_actor_ptr> tmp;
for (auto& x : xs) {
if (! sys)
sys = &(x->home_system());
tmp.push_back(actor_cast<strong_actor_ptr>(x));
}
return make_actor<decorator::splitter, actor>(sys->next_actor_id(),
sys->node(), sys,
std::move(tmp),
std::set<std::string>{});
}
示例8: CAF_LOG_TRACE
bool abstract_actor::link_impl(linking_operation op, const actor_addr& other) {
CAF_LOG_TRACE(CAF_ARG(op) << ", " << CAF_TSARG(other));
switch (op) {
case establish_link_op:
return establish_link_impl(other);
case establish_backlink_op:
return establish_backlink_impl(other);
case remove_link_op:
return remove_link_impl(other);
default:
CAF_ASSERT(op == remove_backlink_op);
return remove_backlink_impl(other);
}
}
示例9: run
void run() {
CAF_SET_LOGGER_SYS(&system());
CAF_LOG_TRACE(CAF_ARG(id_));
// scheduling loop
for (;;) {
auto job = policy_.dequeue(this);
CAF_ASSERT(job != nullptr);
CAF_ASSERT(job->subtype() != resumable::io_actor);
CAF_LOG_DEBUG("resume actor:" << CAF_ARG(id_of(job)));
CAF_PUSH_AID_FROM_PTR(dynamic_cast<abstract_actor*>(job));
policy_.before_resume(this, job);
auto res = job->resume(this, max_throughput_);
policy_.after_resume(this, job);
switch (res) {
case resumable::resume_later: {
// keep reference to this actor, as it remains in the "loop"
policy_.resume_job_later(this, job);
break;
}
case resumable::done: {
policy_.after_completion(this, job);
intrusive_ptr_release(job);
break;
}
case resumable::awaiting_message: {
// resumable will maybe be enqueued again later, deref it for now
intrusive_ptr_release(job);
break;
}
case resumable::shutdown_execution_unit: {
policy_.after_completion(this, job);
policy_.before_shutdown(this);
return;
}
}
}
}
示例10: CAF_ASSERT
void scribe::consume(execution_unit* ctx, const void*, size_t num_bytes) {
CAF_ASSERT(ctx != nullptr);
CAF_LOG_TRACE(CAF_ARG(num_bytes));
if (detached()) {
// we are already disconnected from the broker while the multiplexer
// did not yet remove the socket, this can happen if an IO event causes
// the broker to call close_all() while the pollset contained
// further activities for the broker
return;
}
// keep a strong reference to our parent until we leave scope
// to avoid UB when becoming detached during invocation
auto guard = parent_;
auto& buf = rd_buf();
CAF_ASSERT(buf.size() >= num_bytes);
// make sure size is correct, swap into message, and then call client
buf.resize(num_bytes);
auto& msg_buf = msg().buf;
msg_buf.swap(buf);
invoke_mailbox_element(ctx);
// swap buffer back to stream and implicitly flush wr_buf()
msg_buf.swap(buf);
flush();
}
示例11: createExecuteCommand
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void CmdAddItemFeature::onActionTriggered(bool isChecked)
{
if (isCommandEnabled())
{
CmdExecuteCommand* exeCmd = createExecuteCommand();
if (exeCmd)
{
CmdExecCommandManager::instance()->processExecuteCommand(exeCmd);
}
else
{
CAF_ASSERT(0);
}
}
}
示例12: get_mac_addresses
std::vector<iface_info> get_mac_addresses() {
int mib[6];
std::vector<iface_info> result;
mib[0] = CTL_NET;
mib[1] = AF_ROUTE;
mib[2] = 0;
mib[3] = AF_LINK;
mib[4] = NET_RT_IFLIST;
auto indices = if_nameindex();
std::vector<char> buf;
for (auto i = indices; !(i->if_index == 0 && i->if_name == nullptr); ++i) {
mib[5] = static_cast<int>(i->if_index);
size_t len;
if (sysctl(mib, 6, nullptr, &len, nullptr, 0) < 0) {
perror("sysctl 1 error");
exit(3);
}
if (buf.size() < len)
buf.resize(len);
CAF_ASSERT(len > 0);
if (sysctl(mib, 6, buf.data(), &len, nullptr, 0) < 0) {
perror("sysctl 2 error");
exit(5);
}
auto ifm = reinterpret_cast<if_msghdr*>(buf.data());
auto sdl = reinterpret_cast<sockaddr_dl*>(ifm + 1);
auto ptr = reinterpret_cast<unsigned char*>(LLADDR(sdl));
auto uctoi = [](unsigned char c) -> unsigned {
return static_cast<unsigned char>(c);
};
std::ostringstream oss;
oss << std::hex;
oss.fill('0');
oss.width(2);
oss << uctoi(*ptr++);
for (auto j = 0; j < 5; ++j) {
oss << ":";
oss.width(2);
oss << uctoi(*ptr++);
}
auto addr = oss.str();
if (addr != "00:00:00:00:00:00") {
result.emplace_back(i->if_name, std::move(addr));
}
}
if_freenameindex(indices);
return result;
}
示例13: CAF_LOG_TRACE
void monitorable_actor::attach(attachable_ptr ptr) {
CAF_LOG_TRACE("");
CAF_ASSERT(ptr != nullptr);
error fail_state;
auto attached = exclusive_critical_section([&] {
if (getf(is_terminated_flag)) {
fail_state = fail_state_;
return false;
}
attach_impl(ptr);
return true;
});
CAF_LOG_DEBUG("cannot attach functor to terminated actor: call immediately");
if (!attached)
ptr->actor_exited(fail_state, nullptr);
}
示例14: replace_all
void replace_all(std::string& str,
const char (&what)[WhatSize],
const char (&with)[WithSize]) {
// end(what) - 1 points to the null-terminator
auto next = [&](std::string::iterator pos) -> std::string::iterator {
return std::search(pos, str.end(), std::begin(what), std::end(what) - 1);
};
auto i = next(std::begin(str));
while (i != std::end(str)) {
auto before = std::distance(std::begin(str), i);
CAF_ASSERT(before >= 0);
str.replace(i, i + WhatSize - 1, with);
// i became invalidated -> use new iterator pointing
// to the first character after the replaced text
i = next(str.begin() + before + (WithSize - 1));
}
}
示例15: push_front
/// Tries to enqueue a new element to the inbox.
/// @threadsafe
inbox_result push_front(pointer new_element) noexcept {
CAF_ASSERT(new_element != nullptr);
pointer e = stack_.load();
auto eof = stack_closed_tag();
auto blk = reader_blocked_tag();
while (e != eof) {
// A tag is never part of a non-empty list.
new_element->next = e != blk ? e : nullptr;
if (stack_.compare_exchange_strong(e, new_element))
return e == reader_blocked_tag() ? inbox_result::unblocked_reader
: inbox_result::success;
// Continue with new value of `e`.
}
// The queue has been closed, drop messages.
deleter_type d;
d(new_element);
return inbox_result::queue_closed;
}