Skip to content

Commit

Permalink
Fix doxygen, harmonize actor handles, use noexcept
Browse files Browse the repository at this point in the history
  • Loading branch information
Neverlord committed Jun 30, 2015
1 parent e6cb917 commit 1028e5b
Show file tree
Hide file tree
Showing 11 changed files with 203 additions and 190 deletions.
91 changes: 49 additions & 42 deletions libcaf_core/caf/actor.hpp
Expand Up @@ -38,7 +38,9 @@ namespace caf {
class scoped_actor;

struct invalid_actor_t {
constexpr invalid_actor_t() {}
constexpr invalid_actor_t() {
// nop
}
};

/// Identifies an invalid {@link actor}.
Expand All @@ -59,36 +61,40 @@ class actor : detail::comparable<actor>,
detail::comparable<actor, actor_addr>,
detail::comparable<actor, invalid_actor_t>,
detail::comparable<actor, invalid_actor_addr_t> {

public:
// grant access to private ctor
friend class local_actor;

// allow conversion via actor_cast
template <class T, typename U>
friend T actor_cast(const U&);

public:

actor() = default;

actor(actor&&) = default;

actor(const actor&) = default;
actor& operator=(actor&&) = default;
actor& operator=(const actor&) = default;

template <class T>
actor(intrusive_ptr<T> ptr,
typename std::enable_if<is_convertible_to_actor<T>::value>::type* = 0)
: ptr_(std::move(ptr)) {}
template <class T,
class Enable =
typename std::enable_if<
is_convertible_to_actor<T>::value
>::type>
actor(intrusive_ptr<T> ptr) : ptr_(std::move(ptr)) {
// nop
}

template <class T>
actor(T* ptr,
typename std::enable_if<is_convertible_to_actor<T>::value>::type* = 0)
: ptr_(ptr) {}
template <class T,
class Enable =
typename std::enable_if<
is_convertible_to_actor<T>::value
>::type>
actor(T* ptr) : ptr_(ptr) {
// nop
}

actor(const invalid_actor_t&);

actor& operator=(actor&&) = default;

actor& operator=(const actor&) = default;

template <class T>
typename std::enable_if<is_convertible_to_actor<T>::value, actor&>::type
operator=(intrusive_ptr<T> ptr) {
Expand All @@ -107,55 +113,56 @@ class actor : detail::comparable<actor>,

actor& operator=(const invalid_actor_t&);

inline operator bool() const {
/// Returns the address of the stored actor.
actor_addr address() const noexcept;

/// Returns `*this != invalid_actor`.
inline operator bool() const noexcept {
return static_cast<bool>(ptr_);
}

inline bool operator!() const {
/// Returns `*this == invalid_actor`.
inline bool operator!() const noexcept {
return ! ptr_;
}

/// Returns a handle that grants access to actor operations such as enqueue.
inline abstract_actor* operator->() const {
return ptr_.get();
}
/// Returns whether this is an handle to a remote actor.
bool is_remote() const noexcept;

/// Returns the ID of this actor.
actor_id id() const noexcept;

/// Exchange content of `*this` and `other`.
void swap(actor& other) noexcept;

/// @cond PRIVATE

inline abstract_actor& operator*() const {
return *ptr_;
inline abstract_actor* operator->() const noexcept {
return ptr_.get();
}

intptr_t compare(const actor& other) const;
intptr_t compare(const actor&) const noexcept;

intptr_t compare(const actor_addr&) const;
intptr_t compare(const actor_addr&) const noexcept;

inline intptr_t compare(const invalid_actor_t&) const {
inline intptr_t compare(const invalid_actor_t&) const noexcept {
return ptr_ ? 1 : 0;
}

inline intptr_t compare(const invalid_actor_addr_t&) const {
inline intptr_t compare(const invalid_actor_addr_t&) const noexcept {
return compare(invalid_actor);
}

/// Returns the address of the stored actor.
actor_addr address() const;

/// Returns whether this is an handle to a remote actor.
bool is_remote() const;

actor_id id() const;

void swap(actor& other);
/// @endcond

private:

inline abstract_actor* get() const {
inline abstract_actor* get() const noexcept {
return ptr_.get();
}

actor(abstract_actor*);

abstract_actor_ptr ptr_;

};

} // namespace caf
Expand Down
59 changes: 35 additions & 24 deletions libcaf_core/caf/actor_addr.hpp
Expand Up @@ -45,62 +45,73 @@ constexpr invalid_actor_addr_t invalid_actor_addr = invalid_actor_addr_t{};

/// Stores the address of typed as well as untyped actors.
class actor_addr : detail::comparable<actor_addr>,
detail::comparable<actor_addr, abstract_actor*>,
detail::comparable<actor_addr, abstract_actor_ptr> {

detail::comparable<actor_addr, abstract_actor*>,
detail::comparable<actor_addr, abstract_actor_ptr> {
public:
// grant access to private ctor
friend class actor;
friend class abstract_actor;

template <class T, typename U>
friend T actor_cast(const U&);

public:

actor_addr() = default;

actor_addr(actor_addr&&) = default;

actor_addr(const actor_addr&) = default;

actor_addr& operator=(actor_addr&&) = default;

actor_addr& operator=(const actor_addr&) = default;

actor_addr(const invalid_actor_addr_t&);

actor_addr operator=(const invalid_actor_addr_t&);

inline explicit operator bool() const { return static_cast<bool>(ptr_); }
/// Returns `*this != invalid_actor_addr`.
inline explicit operator bool() const noexcept {
return static_cast<bool>(ptr_);
}

/// Returns `*this == invalid_actor_addr`.
inline bool operator!() const noexcept {
return !ptr_;
}

inline bool operator!() const { return ! ptr_; }
/// Returns whether this is an handle to a remote actor.
bool is_remote() const noexcept;

intptr_t compare(const actor_addr& other) const;
/// Returns the ID of this actor.
actor_id id() const noexcept;

intptr_t compare(const abstract_actor* other) const;
/// Returns the origin node of this actor.
node_id node() const noexcept;

inline intptr_t compare(const abstract_actor_ptr& other) const {
return compare(other.get());
/// Exchange content of `*this` and `other`.
void swap(actor_addr& other) noexcept;

/// @cond PRIVATE

inline abstract_actor* operator->() const noexcept {
return ptr_.get();
}

actor_id id() const;
intptr_t compare(const actor_addr& other) const noexcept;

node_id node() const;
intptr_t compare(const abstract_actor* other) const noexcept;

/// Returns whether this is an address of a remote actor.
bool is_remote() const;
inline intptr_t compare(const abstract_actor_ptr& other) const noexcept {
return compare(other.get());
}

/// Returns the set of accepted messages types as strings or
/// an empty set if this actor is untyped.
std::set<std::string> message_types() const;
/// @endcond

private:

inline abstract_actor* get() const { return ptr_.get(); }
inline abstract_actor* get() const noexcept {
return ptr_.get();
}

explicit actor_addr(abstract_actor*);

abstract_actor_ptr ptr_;

};

} // namespace caf
Expand Down
2 changes: 1 addition & 1 deletion libcaf_core/caf/blocking_actor.hpp
Expand Up @@ -51,7 +51,7 @@ class blocking_actor
~blocking_actor();

/**************************************************************************
* utility stuff and receive() member function family *
* utility stuff and receive() member function family *
**************************************************************************/

using timeout_type = std::chrono::high_resolution_clock::time_point;
Expand Down
5 changes: 0 additions & 5 deletions libcaf_core/caf/config.hpp
Expand Up @@ -38,17 +38,12 @@
#define CAF_VERSION 1400

/// Defined to the major version number of CAF.
///*/
#define CAF_MAJOR_VERSION (CAF_VERSION / 10000)

/**
/// Defined to the minor version number of CAF.
///*/
#define CAF_MINOR_VERSION ((CAF_VERSION / 100) % 100)

/**
/// Defined to the patch version number of CAF.
///*/
#define CAF_PATCH_VERSION (CAF_VERSION % 100)

// This compiler-specific block defines:
Expand Down
40 changes: 18 additions & 22 deletions libcaf_core/caf/detail/comparable.hpp
Expand Up @@ -31,84 +31,80 @@ namespace detail {
/// - `x == 0` if `*this == other`
template <class Subclass, class T = Subclass>
class comparable {

friend bool operator==(const Subclass& lhs, const T& rhs) {
friend bool operator==(const Subclass& lhs, const T& rhs) noexcept {
return lhs.compare(rhs) == 0;
}

friend bool operator==(const T& lhs, const Subclass& rhs) {
friend bool operator==(const T& lhs, const Subclass& rhs) noexcept {
return rhs.compare(lhs) == 0;
}

friend bool operator!=(const Subclass& lhs, const T& rhs) {
friend bool operator!=(const Subclass& lhs, const T& rhs) noexcept {
return lhs.compare(rhs) != 0;
}

friend bool operator!=(const T& lhs, const Subclass& rhs) {
friend bool operator!=(const T& lhs, const Subclass& rhs) noexcept {
return rhs.compare(lhs) != 0;
}

friend bool operator<(const Subclass& lhs, const T& rhs) {
friend bool operator<(const Subclass& lhs, const T& rhs) noexcept {
return lhs.compare(rhs) < 0;
}

friend bool operator>(const Subclass& lhs, const T& rhs) {
friend bool operator>(const Subclass& lhs, const T& rhs) noexcept {
return lhs.compare(rhs) > 0;
}

friend bool operator<(const T& lhs, const Subclass& rhs) {
friend bool operator<(const T& lhs, const Subclass& rhs) noexcept {
return rhs > lhs;
}

friend bool operator>(const T& lhs, const Subclass& rhs) {
friend bool operator>(const T& lhs, const Subclass& rhs) noexcept {
return rhs < lhs;
}

friend bool operator<=(const Subclass& lhs, const T& rhs) {
friend bool operator<=(const Subclass& lhs, const T& rhs) noexcept {
return lhs.compare(rhs) <= 0;
}

friend bool operator>=(const Subclass& lhs, const T& rhs) {
friend bool operator>=(const Subclass& lhs, const T& rhs) noexcept {
return lhs.compare(rhs) >= 0;
}

friend bool operator<=(const T& lhs, const Subclass& rhs) {
friend bool operator<=(const T& lhs, const Subclass& rhs) noexcept {
return rhs >= lhs;
}

friend bool operator>=(const T& lhs, const Subclass& rhs) {
friend bool operator>=(const T& lhs, const Subclass& rhs) noexcept {
return rhs <= lhs;
}

};

template <class Subclass>
class comparable<Subclass, Subclass> {

friend bool operator==(const Subclass& lhs, const Subclass& rhs) {
friend bool operator==(const Subclass& lhs, const Subclass& rhs) noexcept {
return lhs.compare(rhs) == 0;
}

friend bool operator!=(const Subclass& lhs, const Subclass& rhs) {
friend bool operator!=(const Subclass& lhs, const Subclass& rhs) noexcept {
return lhs.compare(rhs) != 0;
}

friend bool operator<(const Subclass& lhs, const Subclass& rhs) {
friend bool operator<(const Subclass& lhs, const Subclass& rhs) noexcept {
return lhs.compare(rhs) < 0;
}

friend bool operator<=(const Subclass& lhs, const Subclass& rhs) {
friend bool operator<=(const Subclass& lhs, const Subclass& rhs) noexcept {
return lhs.compare(rhs) <= 0;
}

friend bool operator>(const Subclass& lhs, const Subclass& rhs) {
friend bool operator>(const Subclass& lhs, const Subclass& rhs) noexcept {
return lhs.compare(rhs) > 0;
}

friend bool operator>=(const Subclass& lhs, const Subclass& rhs) {
friend bool operator>=(const Subclass& lhs, const Subclass& rhs) noexcept {
return lhs.compare(rhs) >= 0;
}

};

} // namespace details
Expand Down
4 changes: 2 additions & 2 deletions libcaf_core/caf/intrusive_ptr.hpp
Expand Up @@ -71,13 +71,13 @@ class intrusive_ptr : detail::comparable<intrusive_ptr<T>>,
}
}

void swap(intrusive_ptr& other) {
void swap(intrusive_ptr& other) noexcept {
std::swap(ptr_, other.ptr_);
}

/// Returns the raw pointer without modifying reference
/// count and sets this to `nullptr`.
pointer release() {
pointer release() noexcept {
auto result = ptr_;
ptr_ = nullptr;
return result;
Expand Down

0 comments on commit 1028e5b

Please sign in to comment.