Commit 5e7b99b9 authored by Dominik Charousset's avatar Dominik Charousset

Make use of noexcept, relates #253

parent 3d3abfa9
This document specifies how to contribute code to this repository. This document specifies how to contribute code to CAF.
Git Workflow Git Workflow
============ ============
CAF's git workflow encompasses the following key aspects. (For general git Our git workflow encompasses the following key aspects. (For general git
style guidelines, see <https://github.com/agis-/git-style-guide>.) style guidelines, see <https://github.com/agis-/git-style-guide>.)
- The `master` branch always reflects a *production-ready* state, i.e., - The `master` branch always reflects a *production-ready* state, i.e.,
...@@ -87,7 +87,7 @@ public: ...@@ -87,7 +87,7 @@ public:
// suppress redundant @return if you start the brief description with "Returns" // suppress redundant @return if you start the brief description with "Returns"
/// Returns the name of this instance. /// Returns the name of this instance.
inline const std::string& name() const { inline const std::string& name() const noexcept {
return name_; return name_;
} }
...@@ -100,10 +100,10 @@ public: ...@@ -100,10 +100,10 @@ public:
void print_name() const; void print_name() const;
/// Does something (maybe). /// Does something (maybe).
void do_something(); void do_something() noexcept;
/// Does something else. /// Does something else but is guaranteed to never throw.
void do_something_else(); void do_something_else() noexcept;
private: private:
std::string name_; std::string name_;
...@@ -156,7 +156,7 @@ void my_class::do_something() { ...@@ -156,7 +156,7 @@ void my_class::do_something() {
} }
} }
void my_class::do_something_else() { void my_class::do_something_else() noexcept {
switch (default_name[0]) { switch (default_name[0]) {
case 'a': case 'a':
// handle a // handle a
...@@ -273,6 +273,9 @@ General ...@@ -273,6 +273,9 @@ General
- Protect single-argument constructors with `explicit` to avoid implicit conversions. - Protect single-argument constructors with `explicit` to avoid implicit conversions.
- Use noexcept whenever it makes sense, in particular for move construction and assignment,
as long as it does not limit future design space.
Naming Naming
------ ------
......
...@@ -58,13 +58,13 @@ public: ...@@ -58,13 +58,13 @@ public:
// -- overridden observers of type_erased_tuple ------------------------------ // -- overridden observers of type_erased_tuple ------------------------------
size_t size() const override; size_t size() const noexcept override;
uint32_t type_token() const override; uint32_t type_token() const noexcept override;
rtti_pair type(size_t pos) const override; rtti_pair type(size_t pos) const noexcept override;
const void* get(size_t pos) const override; const void* get(size_t pos) const noexcept override;
std::string stringify(size_t pos) const override; std::string stringify(size_t pos) const override;
......
...@@ -62,13 +62,13 @@ public: ...@@ -62,13 +62,13 @@ public:
// -- overridden observers of type_erased_tuple ------------------------------ // -- overridden observers of type_erased_tuple ------------------------------
size_t size() const override; size_t size() const noexcept override;
uint32_t type_token() const override; uint32_t type_token() const noexcept override;
rtti_pair type(size_t pos) const override; rtti_pair type(size_t pos) const noexcept override;
const void* get(size_t pos) const override; const void* get(size_t pos) const noexcept override;
std::string stringify(size_t pos) const override; std::string stringify(size_t pos) const override;
......
...@@ -57,13 +57,13 @@ public: ...@@ -57,13 +57,13 @@ public:
// -- overridden observers of type_erased_tuple ------------------------------ // -- overridden observers of type_erased_tuple ------------------------------
size_t size() const override; size_t size() const noexcept override;
uint32_t type_token() const override; uint32_t type_token() const noexcept override;
rtti_pair type(size_t pos) const override; rtti_pair type(size_t pos) const noexcept override;
const void* get(size_t pos) const override; const void* get(size_t pos) const noexcept override;
std::string stringify(size_t pos) const override; std::string stringify(size_t pos) const override;
......
...@@ -58,13 +58,13 @@ public: ...@@ -58,13 +58,13 @@ public:
// -- overridden observers of type_erased_tuple ------------------------------ // -- overridden observers of type_erased_tuple ------------------------------
size_t size() const override; size_t size() const noexcept override;
uint32_t type_token() const override; uint32_t type_token() const noexcept override;
rtti_pair type(size_t pos) const override; rtti_pair type(size_t pos) const noexcept override;
const void* get(size_t pos) const override; const void* get(size_t pos) const noexcept override;
std::string stringify(size_t pos) const override; std::string stringify(size_t pos) const override;
......
...@@ -38,84 +38,95 @@ namespace detail { ...@@ -38,84 +38,95 @@ namespace detail {
class message_data : public ref_counted, public type_erased_tuple { class message_data : public ref_counted, public type_erased_tuple {
public: public:
// -- nested types -----------------------------------------------------------
class cow_ptr;
// -- constructors, destructors, and assignment operators --------------------
message_data() = default; message_data() = default;
message_data(const message_data&) = default; message_data(const message_data&) = default;
~message_data(); ~message_data();
bool shared() const override; // -- pure virtual observers -------------------------------------------------
// nested types virtual cow_ptr copy() const = 0;
class cow_ptr { // -- observers --------------------------------------------------------------
public:
cow_ptr() = default;
cow_ptr(cow_ptr&&) = default;
cow_ptr(const cow_ptr&) = default;
cow_ptr& operator=(cow_ptr&&) = default;
cow_ptr& operator=(const cow_ptr&) = default;
template <class T> using type_erased_tuple::copy;
cow_ptr(intrusive_ptr<T> p) : ptr_(std::move(p)) {
// nop
}
inline cow_ptr(message_data* ptr, bool add_ref) : ptr_(ptr, add_ref) { bool shared() const noexcept override;
// nop };
}
// modifiers class message_data::cow_ptr {
public:
// -- constructors, destructors, and assignment operators ------------------
inline void swap(cow_ptr& other) { cow_ptr() noexcept = default;
ptr_.swap(other.ptr_); cow_ptr(cow_ptr&&) noexcept = default;
} cow_ptr(const cow_ptr&) noexcept = default;
cow_ptr& operator=(cow_ptr&&) noexcept = default;
cow_ptr& operator=(const cow_ptr&) noexcept = default;
inline void reset(message_data* p = nullptr, bool add_ref = true) { template <class T>
ptr_.reset(p, add_ref); cow_ptr(intrusive_ptr<T> p) noexcept : ptr_(std::move(p)) {
} // nop
}
inline message_data* release() { inline cow_ptr(message_data* ptr, bool add_ref) noexcept
return ptr_.detach(); : ptr_(ptr, add_ref) {
} // nop
}
inline void unshare() { // -- modifiers ------------------------------------------------------------
static_cast<void>(get_unshared());
}
inline message_data* operator->() { inline void swap(cow_ptr& other) noexcept {
return get_unshared(); ptr_.swap(other.ptr_);
} }
inline message_data& operator*() { inline void reset(message_data* p = nullptr, bool add_ref = true) noexcept {
return *get_unshared(); ptr_.reset(p, add_ref);
} }
// observers inline message_data* release() noexcept {
return ptr_.detach();
}
inline const message_data* operator->() const { inline void unshare() {
return ptr_.get(); static_cast<void>(get_unshared());
} }
inline const message_data& operator*() const { inline message_data* operator->() {
return *ptr_.get(); return get_unshared();
} }
inline explicit operator bool() const { inline message_data& operator*() {
return static_cast<bool>(ptr_); return *get_unshared();
} }
inline message_data* get() const { // -- observers ------------------------------------------------------------
return ptr_.get();
}
private: inline const message_data* operator->() const noexcept {
message_data* get_unshared(); return ptr_.get();
intrusive_ptr<message_data> ptr_; }
};
using type_erased_tuple::copy; inline const message_data& operator*() const noexcept {
return *ptr_.get();
}
virtual cow_ptr copy() const = 0; inline explicit operator bool() const noexcept {
return static_cast<bool>(ptr_);
}
inline message_data* get() const noexcept {
return ptr_.get();
}
private:
message_data* get_unshared();
intrusive_ptr<message_data> ptr_;
}; };
} // namespace detail } // namespace detail
......
...@@ -157,7 +157,7 @@ public: ...@@ -157,7 +157,7 @@ public:
return data_; return data_;
} }
size_t size() const override { size_t size() const noexcept override {
return sizeof...(Ts); return sizeof...(Ts);
} }
...@@ -165,7 +165,7 @@ public: ...@@ -165,7 +165,7 @@ public:
return message_data::cow_ptr(new tuple_vals(*this), false); return message_data::cow_ptr(new tuple_vals(*this), false);
} }
const void* get(size_t pos) const override { const void* get(size_t pos) const noexcept override {
CAF_ASSERT(pos < size()); CAF_ASSERT(pos < size());
return tup_ptr_access<0, sizeof...(Ts)>::get(pos, data_); return tup_ptr_access<0, sizeof...(Ts)>::get(pos, data_);
} }
...@@ -187,11 +187,11 @@ public: ...@@ -187,11 +187,11 @@ public:
return tup_ptr_access<0, sizeof...(Ts)>::serialize(pos, data_, source); return tup_ptr_access<0, sizeof...(Ts)>::serialize(pos, data_, source);
} }
uint32_t type_token() const override { uint32_t type_token() const noexcept override {
return make_type_token<Ts...>(); return make_type_token<Ts...>();
} }
rtti_pair type(size_t pos) const override { rtti_pair type(size_t pos) const noexcept override {
return types_[pos]; return types_[pos];
} }
......
...@@ -62,12 +62,14 @@ namespace caf { ...@@ -62,12 +62,14 @@ namespace caf {
/// rendering error messages via `actor_system::render(const error&)`. /// rendering error messages via `actor_system::render(const error&)`.
class error : detail::comparable<error> { class error : detail::comparable<error> {
public: public:
error(); error() noexcept;
error(error&&) = default; error(error&&) noexcept = default;
error(const error&) = default; error(const error&) noexcept = default;
error& operator=(error&&) = default; error& operator=(error&&) noexcept = default;
error& operator=(const error&) = default; error& operator=(const error&) noexcept = default;
error(uint8_t code, atom_value category, message context = message{});
error(uint8_t code, atom_value category) noexcept;
error(uint8_t code, atom_value category, message msg) noexcept;
template <class E, template <class E,
class = typename std::enable_if< class = typename std::enable_if<
...@@ -81,16 +83,24 @@ public: ...@@ -81,16 +83,24 @@ public:
} }
/// Returns the category-specific error code, whereas `0` means "no error". /// Returns the category-specific error code, whereas `0` means "no error".
uint8_t code() const; inline uint8_t code() const noexcept {
return code_;
}
/// Returns the category of this error. /// Returns the category of this error.
atom_value category() const; inline atom_value category() const noexcept {
return category_;
}
/// Returns optional context information to this error. /// Returns optional context information to this error.
message& context(); inline message& context() noexcept {
return context_;
}
/// Returns optional context information to this error. /// Returns optional context information to this error.
const message& context() const; inline const message& context() const noexcept {
return context_;
}
/// Returns `code() != 0`. /// Returns `code() != 0`.
inline explicit operator bool() const noexcept { inline explicit operator bool() const noexcept {
...@@ -103,18 +113,18 @@ public: ...@@ -103,18 +113,18 @@ public:
} }
/// Sets the error code to 0. /// Sets the error code to 0.
void clear(); inline void clear() noexcept {
code_ = 0;
/// Creates a flag storing the context size and the error code. context_.reset();
uint32_t compress_code_and_size() const; }
friend void serialize(serializer& sink, error& x, const unsigned int); friend void serialize(serializer& sink, error& x, const unsigned int);
friend void serialize(deserializer& source, error& x, const unsigned int); friend void serialize(deserializer& source, error& x, const unsigned int);
int compare(uint8_t code, atom_value category) const; int compare(const error&) const noexcept;
int compare(const error&) const; int compare(uint8_t code, atom_value category) const noexcept;
private: private:
uint8_t code_; uint8_t code_;
......
...@@ -46,24 +46,24 @@ public: ...@@ -46,24 +46,24 @@ public:
// tell actor_cast this pointer can be null // tell actor_cast this pointer can be null
static constexpr bool has_non_null_guarantee = false; static constexpr bool has_non_null_guarantee = false;
constexpr intrusive_ptr() : ptr_(nullptr) { constexpr intrusive_ptr() noexcept : ptr_(nullptr) {
// nop // nop
} }
intrusive_ptr(pointer raw_ptr, bool add_ref = true) { intrusive_ptr(pointer raw_ptr, bool add_ref = true) noexcept {
set_ptr(raw_ptr, add_ref); set_ptr(raw_ptr, add_ref);
} }
intrusive_ptr(intrusive_ptr&& other) : ptr_(other.detach()) { intrusive_ptr(intrusive_ptr&& other) noexcept : ptr_(other.detach()) {
// nop // nop
} }
intrusive_ptr(const intrusive_ptr& other) { intrusive_ptr(const intrusive_ptr& other) noexcept {
set_ptr(other.get(), true); set_ptr(other.get(), true);
} }
template <class Y> template <class Y>
intrusive_ptr(intrusive_ptr<Y> other) : ptr_(other.detach()) { intrusive_ptr(intrusive_ptr<Y> other) noexcept : ptr_(other.detach()) {
static_assert(std::is_convertible<Y*, T*>::value, static_assert(std::is_convertible<Y*, T*>::value,
"Y* is not assignable to T*"); "Y* is not assignable to T*");
} }
...@@ -92,67 +92,67 @@ public: ...@@ -92,67 +92,67 @@ public:
return detach(); return detach();
} }
void reset(pointer new_value = nullptr, bool add_ref = true) { void reset(pointer new_value = nullptr, bool add_ref = true) noexcept {
auto old = ptr_; auto old = ptr_;
set_ptr(new_value, add_ref); set_ptr(new_value, add_ref);
if (old) if (old)
intrusive_ptr_release(old); intrusive_ptr_release(old);
} }
intrusive_ptr& operator=(pointer ptr) { intrusive_ptr& operator=(pointer ptr) noexcept {
reset(ptr); reset(ptr);
return *this; return *this;
} }
intrusive_ptr& operator=(intrusive_ptr other) { intrusive_ptr& operator=(intrusive_ptr other) noexcept {
swap(other); swap(other);
return *this; return *this;
} }
pointer get() const { pointer get() const noexcept {
return ptr_; return ptr_;
} }
pointer operator->() const { pointer operator->() const noexcept {
return ptr_; return ptr_;
} }
reference operator*() const { reference operator*() const noexcept {
return *ptr_; return *ptr_;
} }
bool operator!() const { bool operator!() const noexcept {
return ! ptr_; return ! ptr_;
} }
explicit operator bool() const { explicit operator bool() const noexcept {
return ptr_ != nullptr; return ptr_ != nullptr;
} }
ptrdiff_t compare(const_pointer ptr) const { ptrdiff_t compare(const_pointer ptr) const noexcept {
return static_cast<ptrdiff_t>(get() - ptr); return static_cast<ptrdiff_t>(get() - ptr);
} }
ptrdiff_t compare(const intrusive_ptr& other) const { ptrdiff_t compare(const intrusive_ptr& other) const noexcept {
return compare(other.get()); return compare(other.get());
} }
ptrdiff_t compare(std::nullptr_t) const { ptrdiff_t compare(std::nullptr_t) const noexcept {
return reinterpret_cast<ptrdiff_t>(get()); return reinterpret_cast<ptrdiff_t>(get());
} }
template <class C> template <class C>
intrusive_ptr<C> downcast() const { intrusive_ptr<C> downcast() const noexcept {
return (ptr_) ? dynamic_cast<C*>(get()) : nullptr; return (ptr_) ? dynamic_cast<C*>(get()) : nullptr;
} }
template <class C> template <class C>
intrusive_ptr<C> upcast() const { intrusive_ptr<C> upcast() const noexcept {
return (ptr_) ? static_cast<C*>(get()) : nullptr; return (ptr_) ? static_cast<C*>(get()) : nullptr;
} }
private: private:
void set_ptr(pointer raw_ptr, bool add_ref) { void set_ptr(pointer raw_ptr, bool add_ref) noexcept {
ptr_ = raw_ptr; ptr_ = raw_ptr;
if (raw_ptr && add_ref) if (raw_ptr && add_ref)
intrusive_ptr_add_ref(raw_ptr); intrusive_ptr_add_ref(raw_ptr);
......
This diff is collapsed.
...@@ -61,20 +61,20 @@ public: ...@@ -61,20 +61,20 @@ public:
// -- pure virtual observers ------------------------------------------------- // -- pure virtual observers -------------------------------------------------
/// Returns the size of this tuple. /// Returns the size of this tuple.
virtual size_t size() const = 0; virtual size_t size() const noexcept = 0;
/// Returns whether multiple references to this tuple exist. /// Returns whether multiple references to this tuple exist.
virtual bool shared() const = 0; virtual bool shared() const noexcept = 0;
/// Returns a type hint for the element types. /// Returns a type hint for the element types.
virtual uint32_t type_token() const = 0; virtual uint32_t type_token() const noexcept = 0;
/// Returns the type number and `std::type_info` object for /// Returns the type number and `std::type_info` object for
/// the element at position `pos`. /// the element at position `pos`.
virtual rtti_pair type(size_t pos) const = 0; virtual rtti_pair type(size_t pos) const noexcept = 0;
/// Returns the element at position `pos`. /// Returns the element at position `pos`.
virtual const void* get(size_t pos) const = 0; virtual const void* get(size_t pos) const noexcept = 0;
/// Returns a string representation of the element at position `pos`. /// Returns a string representation of the element at position `pos`.
virtual std::string stringify(size_t pos) const = 0; virtual std::string stringify(size_t pos) const = 0;
...@@ -95,19 +95,19 @@ public: ...@@ -95,19 +95,19 @@ public:
/// Saves the content of the tuple to `sink`. /// Saves the content of the tuple to `sink`.
void save(serializer& sink) const; void save(serializer& sink) const;
/// Checks whether the type of the stored value matches /// Checks whether the type of the stored value at position `pos`
/// the type nr and type info object. /// matches type number `n` and run-time type information `p`.
bool matches(size_t pos, uint16_t tnr, const std::type_info* tinf) const; bool matches(size_t pos, uint16_t n, const std::type_info* p) const noexcept;
// -- inline observers ------------------------------------------------------- // -- inline observers -------------------------------------------------------
/// Returns the type number for the element at position `pos`. /// Returns the type number for the element at position `pos`.
inline uint16_t type_nr(size_t pos) const { inline uint16_t type_nr(size_t pos) const noexcept {
return type(pos).first; return type(pos).first;
} }
/// Checks whether the type of the stored value matches `rtti`. /// Checks whether the type of the stored value matches `rtti`.
inline bool matches(size_t pos, const rtti_pair& rtti) const { inline bool matches(size_t pos, const rtti_pair& rtti) const noexcept {
return matches(pos, rtti.first, rtti.second); return matches(pos, rtti.first, rtti.second);
} }
}; };
...@@ -162,23 +162,23 @@ public: ...@@ -162,23 +162,23 @@ public:
// -- overridden observers --------------------------------------------------- // -- overridden observers ---------------------------------------------------
size_t size() const override { size_t size() const noexcept override {
return sizeof...(Ts); return sizeof...(Ts);
} }
bool shared() const override { bool shared() const noexcept override {
return false; return false;
} }
uint32_t type_token() const override { uint32_t type_token() const noexcept override {
return make_type_token<Ts...>(); return make_type_token<Ts...>();
} }
rtti_pair type(size_t pos) const override { rtti_pair type(size_t pos) const noexcept override {
return ptrs_[pos]->type(); return ptrs_[pos]->type();
} }
const void* get(size_t pos) const override { const void* get(size_t pos) const noexcept override {
return ptrs_[pos]->get(); return ptrs_[pos]->get();
} }
......
...@@ -50,24 +50,26 @@ public: ...@@ -50,24 +50,26 @@ public:
// tell actor_cast this pointer can be null // tell actor_cast this pointer can be null
static constexpr bool has_non_null_guarantee = false; static constexpr bool has_non_null_guarantee = false;
constexpr weak_intrusive_ptr() : ptr_(nullptr) { constexpr weak_intrusive_ptr() noexcept : ptr_(nullptr) {
// nop // nop
} }
weak_intrusive_ptr(pointer raw_ptr, bool add_ref = true) { weak_intrusive_ptr(pointer raw_ptr, bool add_ref = true) noexcept {
set_ptr(raw_ptr, add_ref); set_ptr(raw_ptr, add_ref);
} }
weak_intrusive_ptr(weak_intrusive_ptr&& other) : ptr_(other.detach()) { weak_intrusive_ptr(weak_intrusive_ptr&& other) noexcept
: ptr_(other.detach()) {
// nop // nop
} }
weak_intrusive_ptr(const weak_intrusive_ptr& other) { weak_intrusive_ptr(const weak_intrusive_ptr& other) noexcept {
set_ptr(other.get(), true); set_ptr(other.get(), true);
} }
template <class Y> template <class Y>
weak_intrusive_ptr(weak_intrusive_ptr<Y> other) : ptr_(other.detach()) { weak_intrusive_ptr(weak_intrusive_ptr<Y> other) noexcept
: ptr_(other.detach()) {
static_assert(std::is_convertible<Y*, T*>::value, static_assert(std::is_convertible<Y*, T*>::value,
"Y* is not assignable to T*"); "Y* is not assignable to T*");
} }
...@@ -103,50 +105,50 @@ public: ...@@ -103,50 +105,50 @@ public:
intrusive_ptr_release_weak(old); intrusive_ptr_release_weak(old);
} }
weak_intrusive_ptr& operator=(pointer ptr) { weak_intrusive_ptr& operator=(pointer ptr) noexcept {
reset(ptr); reset(ptr);
return *this; return *this;
} }
weak_intrusive_ptr& operator=(weak_intrusive_ptr other) { weak_intrusive_ptr& operator=(weak_intrusive_ptr other) noexcept {
swap(other); swap(other);
return *this; return *this;
} }
pointer get() const { pointer get() const noexcept {
return ptr_; return ptr_;
} }
pointer operator->() const { pointer operator->() const noexcept {
return ptr_; return ptr_;
} }
reference operator*() const { reference operator*() const noexcept {
return *ptr_; return *ptr_;
} }
bool operator!() const { bool operator!() const noexcept {
return ! ptr_; return ! ptr_;
} }
explicit operator bool() const { explicit operator bool() const noexcept {
return static_cast<bool>(ptr_); return static_cast<bool>(ptr_);
} }
ptrdiff_t compare(const_pointer ptr) const { ptrdiff_t compare(const_pointer ptr) const noexcept {
return static_cast<ptrdiff_t>(get() - ptr); return static_cast<ptrdiff_t>(get() - ptr);
} }
ptrdiff_t compare(const weak_intrusive_ptr& other) const { ptrdiff_t compare(const weak_intrusive_ptr& other) const noexcept {
return compare(other.get()); return compare(other.get());
} }
ptrdiff_t compare(std::nullptr_t) const { ptrdiff_t compare(std::nullptr_t) const noexcept {
return reinterpret_cast<ptrdiff_t>(get()); return reinterpret_cast<ptrdiff_t>(get());
} }
/// Tries to upgrade this weak reference to a strong reference. /// Tries to upgrade this weak reference to a strong reference.
intrusive_ptr<T> lock() const { intrusive_ptr<T> lock() const noexcept {
if (! ptr_ || ! intrusive_ptr_upgrade_weak(ptr_)) if (! ptr_ || ! intrusive_ptr_upgrade_weak(ptr_))
return nullptr; return nullptr;
// reference count already increased by intrusive_ptr_upgrade_weak // reference count already increased by intrusive_ptr_upgrade_weak
...@@ -156,14 +158,14 @@ public: ...@@ -156,14 +158,14 @@ public:
/// Tries to upgrade this weak reference to a strong reference. /// Tries to upgrade this weak reference to a strong reference.
/// Returns a pointer with increased strong reference count /// Returns a pointer with increased strong reference count
/// on success, `nullptr` otherwise. /// on success, `nullptr` otherwise.
pointer get_locked() const { pointer get_locked() const noexcept {
if (! ptr_ || ! intrusive_ptr_upgrade_weak(ptr_)) if (! ptr_ || ! intrusive_ptr_upgrade_weak(ptr_))
return nullptr; return nullptr;
return ptr_; return ptr_;
} }
private: private:
void set_ptr(pointer raw_ptr, bool add_ref) { void set_ptr(pointer raw_ptr, bool add_ref) noexcept {
ptr_ = raw_ptr; ptr_ = raw_ptr;
if (raw_ptr && add_ref) if (raw_ptr && add_ref)
intrusive_ptr_add_weak_ref(raw_ptr); intrusive_ptr_add_weak_ref(raw_ptr);
......
...@@ -69,21 +69,21 @@ void concatenated_tuple::load(size_t pos, deserializer& source) { ...@@ -69,21 +69,21 @@ void concatenated_tuple::load(size_t pos, deserializer& source) {
selected.first->load(selected.second, source); selected.first->load(selected.second, source);
} }
size_t concatenated_tuple::size() const { size_t concatenated_tuple::size() const noexcept {
return size_; return size_;
} }
uint32_t concatenated_tuple::type_token() const { uint32_t concatenated_tuple::type_token() const noexcept {
return type_token_; return type_token_;
} }
message_data::rtti_pair concatenated_tuple::type(size_t pos) const { message_data::rtti_pair concatenated_tuple::type(size_t pos) const noexcept {
CAF_ASSERT(pos < size()); CAF_ASSERT(pos < size());
auto selected = select(pos); auto selected = select(pos);
return selected.first->type(selected.second); return selected.first->type(selected.second);
} }
const void* concatenated_tuple::get(size_t pos) const { const void* concatenated_tuple::get(size_t pos) const noexcept {
CAF_ASSERT(pos < size()); CAF_ASSERT(pos < size());
auto selected = select(pos); auto selected = select(pos);
return selected.first->get(selected.second); return selected.first->get(selected.second);
......
...@@ -64,19 +64,20 @@ void decorated_tuple::load(size_t pos, deserializer& source) { ...@@ -64,19 +64,20 @@ void decorated_tuple::load(size_t pos, deserializer& source) {
return decorated_->load(mapping_[pos], source); return decorated_->load(mapping_[pos], source);
} }
size_t decorated_tuple::size() const { size_t decorated_tuple::size() const noexcept {
return mapping_.size(); return mapping_.size();
} }
uint32_t decorated_tuple::type_token() const { uint32_t decorated_tuple::type_token() const noexcept {
return type_token_; return type_token_;
} }
message_data::rtti_pair decorated_tuple::type(size_t pos) const { message_data::rtti_pair decorated_tuple::type(size_t pos) const noexcept {
CAF_ASSERT(pos < size());
return decorated_->type(mapping_[pos]); return decorated_->type(mapping_[pos]);
} }
const void* decorated_tuple::get(size_t pos) const { const void* decorated_tuple::get(size_t pos) const noexcept {
CAF_ASSERT(pos < size()); CAF_ASSERT(pos < size());
return decorated_->get(mapping_[pos]); return decorated_->get(mapping_[pos]);
} }
......
...@@ -62,21 +62,20 @@ void dynamic_message_data::load(size_t pos, deserializer& source) { ...@@ -62,21 +62,20 @@ void dynamic_message_data::load(size_t pos, deserializer& source) {
elements_[pos]->load(source); elements_[pos]->load(source);
} }
size_t dynamic_message_data::size() const { size_t dynamic_message_data::size() const noexcept {
return elements_.size(); return elements_.size();
} }
uint32_t dynamic_message_data::type_token() const { uint32_t dynamic_message_data::type_token() const noexcept {
return type_token_; return type_token_;
} }
auto dynamic_message_data::type(size_t pos) const -> rtti_pair { auto dynamic_message_data::type(size_t pos) const noexcept -> rtti_pair {
CAF_ASSERT(pos < size()); CAF_ASSERT(pos < size());
return elements_[pos]->type(); return elements_[pos]->type();
} }
const void* dynamic_message_data::get(size_t pos) const { const void* dynamic_message_data::get(size_t pos) const noexcept {
CAF_ASSERT(pos < size());
CAF_ASSERT(pos < size()); CAF_ASSERT(pos < size());
return elements_[pos]->get(); return elements_[pos]->get();
} }
......
...@@ -25,37 +25,21 @@ ...@@ -25,37 +25,21 @@
namespace caf { namespace caf {
error::error() : code_(0), category_(atom("")) { error::error() noexcept : code_(0), category_(atom("")) {
// nop // nop
} }
error::error(uint8_t x, atom_value y, message z) error::error(uint8_t x, atom_value y) noexcept : code_(x), category_(y) {
// nop
}
error::error(uint8_t x, atom_value y, message z) noexcept
: code_(x), : code_(x),
category_(y), category_(y),
context_(std::move(z)) { context_(std::move(z)) {
// nop // nop
} }
uint8_t error::code() const {
return code_;
}
atom_value error::category() const {
return category_;
}
message& error::context() {
return context_;
}
const message& error::context() const {
return context_;
}
void error::clear() {
code_ = 0;
}
void serialize(serializer& sink, error& x, const unsigned int) { void serialize(serializer& sink, error& x, const unsigned int) {
sink << x.code_ << x.category_ << x.context_; sink << x.code_ << x.category_ << x.context_;
} }
...@@ -64,7 +48,11 @@ void serialize(deserializer& source, error& x, const unsigned int) { ...@@ -64,7 +48,11 @@ void serialize(deserializer& source, error& x, const unsigned int) {
source >> x.code_ >> x.category_ >> x.context_; source >> x.code_ >> x.category_ >> x.context_;
} }
int error::compare(uint8_t x, atom_value y) const { int error::compare(const error& x) const noexcept {
return compare(x.code(), x.category());
}
int error::compare(uint8_t x, atom_value y) const noexcept {
// exception: all errors with default value are considered no error -> equal // exception: all errors with default value are considered no error -> equal
if (code_ == 0 && x == 0) if (code_ == 0 && x == 0)
return 0; return 0;
...@@ -75,10 +63,6 @@ int error::compare(uint8_t x, atom_value y) const { ...@@ -75,10 +63,6 @@ int error::compare(uint8_t x, atom_value y) const {
return static_cast<int>(code_) - x; return static_cast<int>(code_) - x;
} }
int error::compare(const error& x) const {
return compare(x.code(), x.category());
}
std::string to_string(const error& x) { std::string to_string(const error& x) {
if (! x) if (! x)
return "no-error"; return "no-error";
......
...@@ -71,21 +71,21 @@ void merged_tuple::load(size_t pos, deserializer& source) { ...@@ -71,21 +71,21 @@ void merged_tuple::load(size_t pos, deserializer& source) {
data_[p.first]->load(p.second, source); data_[p.first]->load(p.second, source);
} }
size_t merged_tuple::size() const { size_t merged_tuple::size() const noexcept {
return mapping_.size(); return mapping_.size();
} }
uint32_t merged_tuple::type_token() const { uint32_t merged_tuple::type_token() const noexcept {
return type_token_; return type_token_;
} }
merged_tuple::rtti_pair merged_tuple::type(size_t pos) const { merged_tuple::rtti_pair merged_tuple::type(size_t pos) const noexcept {
CAF_ASSERT(pos < mapping_.size()); CAF_ASSERT(pos < mapping_.size());
auto& p = mapping_[pos]; auto& p = mapping_[pos];
return data_[p.first]->type(p.second); return data_[p.first]->type(p.second);
} }
const void* merged_tuple::get(size_t pos) const { const void* merged_tuple::get(size_t pos) const noexcept {
CAF_ASSERT(pos < mapping_.size()); CAF_ASSERT(pos < mapping_.size());
auto& p = mapping_[pos]; auto& p = mapping_[pos];
return data_[p.first]->get(p.second); return data_[p.first]->get(p.second);
......
...@@ -34,24 +34,28 @@ ...@@ -34,24 +34,28 @@
namespace caf { namespace caf {
message::message(message&& other) : vals_(std::move(other.vals_)) { message::message(message&& other) noexcept : vals_(std::move(other.vals_)) {
// nop // nop
} }
message::message(const data_ptr& ptr) : vals_(ptr) { message::message(const data_ptr& ptr) noexcept : vals_(ptr) {
// nop // nop
} }
message& message::operator=(message&& other) { message& message::operator=(message&& other) noexcept {
vals_.swap(other.vals_); vals_.swap(other.vals_);
return *this; return *this;
} }
void message::reset(raw_ptr new_ptr, bool add_ref) { message::~message() {
// nop
}
void message::reset(raw_ptr new_ptr, bool add_ref) noexcept {
vals_.reset(new_ptr, add_ref); vals_.reset(new_ptr, add_ref);
} }
void message::swap(message& other) { void message::swap(message& other) noexcept {
vals_.swap(other.vals_); vals_.swap(other.vals_);
} }
...@@ -60,11 +64,6 @@ void* message::get_mutable(size_t p) { ...@@ -60,11 +64,6 @@ void* message::get_mutable(size_t p) {
return vals_->get_mutable(p); return vals_->get_mutable(p);
} }
const void* message::at(size_t p) const {
CAF_ASSERT(vals_);
return vals_->get(p);
}
message message::from(const type_erased_tuple* ptr) { message message::from(const type_erased_tuple* ptr) {
if (! ptr) if (! ptr)
return message{}; return message{};
...@@ -86,11 +85,6 @@ message message::copy_from(const type_erased_tuple* ptr) { ...@@ -86,11 +85,6 @@ message message::copy_from(const type_erased_tuple* ptr) {
return mb.move_to_message(); return mb.move_to_message();
} }
bool message::match_element(size_t pos, uint16_t typenr,
const std::type_info* rtti) const {
return vals_->matches(pos, typenr, rtti);
}
message& message::operator+=(const message& x) { message& message::operator+=(const message& x) {
auto tmp = *this + x; auto tmp = *this + x;
swap(tmp); swap(tmp);
......
...@@ -28,7 +28,7 @@ message_data::~message_data() { ...@@ -28,7 +28,7 @@ message_data::~message_data() {
// nop // nop
} }
bool message_data::shared() const { bool message_data::shared() const noexcept {
return ! unique(); return ! unique();
} }
......
...@@ -57,7 +57,7 @@ void type_erased_tuple::save(serializer& sink) const { ...@@ -57,7 +57,7 @@ void type_erased_tuple::save(serializer& sink) const {
} }
bool type_erased_tuple::matches(size_t pos, uint16_t nr, bool type_erased_tuple::matches(size_t pos, uint16_t nr,
const std::type_info* ptr) const { const std::type_info* ptr) const noexcept {
CAF_ASSERT(pos < size()); CAF_ASSERT(pos < size());
auto tp = type(pos); auto tp = type(pos);
if (tp.first != nr) if (tp.first != nr)
......
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