Commit d5284194 authored by Dominik Charousset's avatar Dominik Charousset

Remove `message_iterator`

parent 18c47cbd
......@@ -58,7 +58,6 @@ set (LIBCAF_CORE_SRCS
src/message_builder.cpp
src/message_data.cpp
src/message_handler.cpp
src/message_iterator.cpp
src/node_id.cpp
src/ref_counted.cpp
src/response_promise.cpp
......
......@@ -31,30 +31,20 @@
#include "caf/uniform_type_info.hpp"
#include "caf/detail/type_list.hpp"
#include "caf/detail/message_iterator.hpp"
namespace caf {
namespace detail {
class message_data : public ref_counted {
using super = ref_counted;
public:
message_data();
// mutators
virtual void* mutable_at(size_t pos) = 0;
virtual void* mutable_native_data();
// accessors
virtual size_t size() const = 0;
virtual message_data* copy() const = 0;
virtual const void* at(size_t pos) const = 0;
std::string tuple_type_names() const;
/**
......@@ -78,22 +68,6 @@ class message_data : public ref_counted {
bool equals(const message_data& other) const;
using const_iterator = message_iterator;
inline const_iterator begin() const {
return {this};
}
inline const_iterator cbegin() const {
return {this};
}
inline const_iterator end() const {
return {this, size()};
}
inline const_iterator cend() const {
return {this, size()};
}
class ptr {
public:
......
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright (C) 2011 - 2014 *
* 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_DETAIL_MESSAGE_ITERATOR_HPP
#define CAF_DETAIL_MESSAGE_ITERATOR_HPP
#include <cstddef>
#include <typeinfo>
#include "caf/fwd.hpp"
namespace caf {
namespace detail {
class message_data;
class message_iterator {
public:
using pointer = message_data*;
using const_pointer = const message_data*;
message_iterator(const_pointer data, size_t pos = 0);
message_iterator(const message_iterator&) = default;
message_iterator& operator=(const message_iterator&) = default;
inline message_iterator& operator++() {
++m_pos;
return *this;
}
inline message_iterator& operator--() {
--m_pos;
return *this;
}
inline message_iterator operator+(size_t offset) {
return {m_data, m_pos + offset};
}
inline message_iterator& operator+=(size_t offset) {
m_pos += offset;
return *this;
}
inline message_iterator operator-(size_t offset) {
return {m_data, m_pos - offset};
}
inline message_iterator& operator-=(size_t offset) {
m_pos -= offset;
return *this;
}
inline size_t position() const {
return m_pos;
}
inline const_pointer data() const {
return m_data;
}
const void* value() const;
bool match_element(uint16_t typenr, const std::type_info* rtti) const;
template <class T>
const T& value_as() const {
return *reinterpret_cast<const T*>(value());
}
inline message_iterator& operator*() {
return *this;
}
private:
size_t m_pos;
const message_data* m_data;
};
inline bool operator==(const message_iterator& lhs,
const message_iterator& rhs) {
return lhs.data() == rhs.data() && lhs.position() == rhs.position();
}
inline bool operator!=(const message_iterator& lhs,
const message_iterator& rhs) {
return !(lhs == rhs);
}
} // namespace detail
} // namespace caf
#endif // CAF_DETAIL_MESSAGE_ITERATOR_HPP
......@@ -40,12 +40,12 @@ struct meta_element {
atom_value v;
uint16_t typenr;
const std::type_info* type;
bool (*fun)(const meta_element&, const message_iterator&, void**);
bool (*fun)(const meta_element&, const message&, size_t, void**);
};
bool match_element(const meta_element&, const message_iterator&, void**);
bool match_element(const meta_element&, const message&, size_t, void**);
bool match_atom_constant(const meta_element&, const message_iterator&, void**);
bool match_atom_constant(const meta_element&, const message&, size_t, void**);
template <class T, uint16_t TN = detail::type_nr<T>::value>
struct meta_element_factory {
......
......@@ -58,11 +58,6 @@ class message {
*/
using data_ptr = detail::message_data::ptr;
/**
* An iterator to access each element as `const void*.
*/
using const_iterator = detail::message_data::const_iterator;
/**
* Creates an empty tuple.
*/
......@@ -166,16 +161,6 @@ class message {
return *reinterpret_cast<T*>(mutable_at(p));
}
/**
* Returns an iterator to the beginning.
*/
const_iterator begin() const;
/**
* Returns an iterator to the end.
*/
const_iterator end() const;
/**
* Returns a copy-on-write pointer to the internal data.
*/
......
......@@ -112,14 +112,6 @@ optional<message> message::apply(message_handler handler) {
return handler(*this);
}
message::const_iterator message::begin() const {
return m_vals ? m_vals->begin() : const_iterator{nullptr, 0};
}
message::const_iterator message::end() const {
return m_vals ? m_vals->end() : const_iterator{nullptr, 0};
}
message message::filter_impl(size_t start, message_handler handler) const {
auto s = size();
for (size_t i = start; i < s; ++i) {
......
......@@ -29,8 +29,6 @@ class message_builder::dynamic_msg_data : public detail::message_data {
public:
using super = message_data;
using message_data::const_iterator;
dynamic_msg_data() : m_type_token(0xFFFFFFFF) {
// nop
}
......
......@@ -24,10 +24,6 @@
namespace caf {
namespace detail {
message_data::message_data() {
// nop
}
bool message_data::equals(const message_data& other) const {
if (this == &other) {
return true;
......
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright (C) 2011 - 2014 *
* 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. *
******************************************************************************/
#include "caf/detail/message_iterator.hpp"
#include "caf/detail/message_data.hpp"
namespace caf {
namespace detail {
message_iterator::message_iterator(const_pointer dataptr, size_t pos)
: m_pos(pos),
m_data(dataptr) {
// nop
}
const void* message_iterator::value() const {
return m_data->at(m_pos);
}
bool message_iterator::match_element(uint16_t typenr,
const std::type_info* rtti) const {
return m_data->match_element(m_pos, typenr, rtti);
}
} // namespace detail
} // namespace caf
......@@ -28,26 +28,27 @@ bool is_wildcard(const meta_element& me) {
return me.typenr == 0 && me.type == nullptr;
}
bool match_element(const meta_element& me, const message_iterator& iter,
void** storage) {
bool match_element(const meta_element& me, const message& msg,
size_t pos, void** storage) {
CAF_REQUIRE(me.typenr != 0 || me.type != nullptr);
if (!iter.match_element(me.typenr, me.type)) {
if (!msg.match_element(pos, me.typenr, me.type)) {
return false;
}
if (storage) {
*storage = const_cast<void*>(iter.value());
*storage = const_cast<void*>(msg.at(pos));
}
return true;
}
bool match_atom_constant(const meta_element& me, const message_iterator& iter,
void** storage) {
bool match_atom_constant(const meta_element& me, const message& msg,
size_t pos, void** storage) {
CAF_REQUIRE(me.typenr == detail::type_nr<atom_value>::value);
if (!iter.match_element(detail::type_nr<atom_value>::value, nullptr)) {
if (!msg.match_element(pos, detail::type_nr<atom_value>::value, nullptr)) {
return false;
}
if (storage) {
if (iter.value_as<atom_value>() != me.v) {
auto ptr = msg.at(pos);
if (me.v != *reinterpret_cast<const atom_value*>(ptr)) {
return false;
}
// This assignment casts `atom_value` to `atom_constant<V>*`.
......@@ -56,7 +57,7 @@ bool match_atom_constant(const meta_element& me, const message_iterator& iter,
// throughout the runtime of the program and the atom constant
// does not have any members. Hence, this is nonetheless safe since
// we are never actually going to dereference the pointer.
*storage = const_cast<void*>(iter.value());
*storage = const_cast<void*>(ptr);
}
return true;
}
......@@ -87,10 +88,10 @@ class set_commit_rollback {
size_t m_fallback_pos;
};
bool try_match(message_iterator mbegin, message_iterator mend,
bool try_match(const message& msg, size_t msg_pos, size_t msg_size,
pattern_iterator pbegin, pattern_iterator pend,
set_commit_rollback& storage) {
while (mbegin != mend) {
while (msg_pos < msg_size) {
if (pbegin == pend) {
return false;
}
......@@ -104,8 +105,8 @@ bool try_match(message_iterator mbegin, message_iterator mend,
// safe current mapping as fallback
storage.commit();
// iterate over remaining values until we found a match
for (; mbegin != mend; ++mbegin) {
if (try_match(mbegin, mend, pbegin, pend, storage)) {
for (; msg_pos < msg_size; ++msg_pos) {
if (try_match(msg, msg_pos, msg_size, pbegin, pend, storage)) {
return true;
}
// restore mapping to fallback (delete invalid mappings)
......@@ -114,13 +115,13 @@ bool try_match(message_iterator mbegin, message_iterator mend,
return false; // no submatch found
}
// inspect current element
if (!pbegin->fun(*pbegin, mbegin, storage.current())) {
if (!pbegin->fun(*pbegin, msg, msg_pos, storage.current())) {
// type mismatch
return false;
}
// next iteration
storage.inc();
++mbegin;
++msg_pos;
++pbegin;
}
// we found a match if we've inspected each element and consumed
......@@ -130,7 +131,7 @@ bool try_match(message_iterator mbegin, message_iterator mend,
bool try_match(const message& msg, pattern_iterator pb, size_t ps, void** out) {
set_commit_rollback scr{out};
return try_match(msg.begin(), msg.end(), pb, pb + ps, scr);
return try_match(msg, 0, msg.size(), pb, pb + ps, scr);
}
} // namespace detail
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment