Commit c03cd963 authored by Dominik Charousset's avatar Dominik Charousset

Move observer_state to private core-test header

parent 6743514e
...@@ -56,7 +56,6 @@ caf_add_component( ...@@ -56,7 +56,6 @@ caf_add_component(
async.read_result async.read_result
async.write_result async.write_result
exit_reason exit_reason
flow.observer_state
flow.op.state flow.op.state
intrusive.inbox_result intrusive.inbox_result
intrusive.task_result intrusive.task_result
......
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
#include "caf/error.hpp" #include "caf/error.hpp"
#include "caf/flow/coordinated.hpp" #include "caf/flow/coordinated.hpp"
#include "caf/flow/coordinator.hpp" #include "caf/flow/coordinator.hpp"
#include "caf/flow/observer_state.hpp"
#include "caf/flow/subscription.hpp" #include "caf/flow/subscription.hpp"
#include "caf/intrusive_ptr.hpp" #include "caf/intrusive_ptr.hpp"
#include "caf/logger.hpp" #include "caf/logger.hpp"
......
// This file is part of CAF, the C++ Actor Framework. See the file LICENSE in
// the main distribution directory for license terms and copyright or visit
// https://github.com/actor-framework/actor-framework/blob/master/LICENSE.
#pragma once
#include "caf/default_enum_inspect.hpp"
#include "caf/detail/core_export.hpp"
namespace caf::flow {
/// Represents the current state of an @ref observer.
enum class observer_state {
/// Indicates that no callbacks were called yet.
idle,
/// Indicates that on_subscribe was called.
subscribed,
/// Indicates that on_complete was called.
completed,
/// Indicates that on_error was called.
aborted
};
/// Returns whether `x` represents a final state, i.e., `completed`, `aborted`
/// or `disposed`.
constexpr bool is_final(observer_state x) noexcept {
return static_cast<int>(x) >= static_cast<int>(observer_state::completed);
}
/// Returns whether `x` represents an active state, i.e., `idle` or
/// `subscribed`.
constexpr bool is_active(observer_state x) noexcept {
return static_cast<int>(x) <= static_cast<int>(observer_state::subscribed);
}
/// @relates sec
CAF_CORE_EXPORT std::string to_string(observer_state);
/// @relates observer_state
CAF_CORE_EXPORT bool from_string(std::string_view, observer_state&);
/// @relates observer_state
CAF_CORE_EXPORT bool from_integer(std::underlying_type_t<observer_state>,
observer_state&);
/// @relates observer_state
template <class Inspector>
bool inspect(Inspector& f, observer_state& x) {
return default_enum_inspect(f, x);
}
} // namespace caf::flow
...@@ -47,6 +47,56 @@ private: ...@@ -47,6 +47,56 @@ private:
namespace caf::flow { namespace caf::flow {
std::string to_string(observer_state x) {
switch (x) {
default:
return "???";
case observer_state::idle:
return "caf::flow::observer_state::idle";
case observer_state::subscribed:
return "caf::flow::observer_state::subscribed";
case observer_state::completed:
return "caf::flow::observer_state::completed";
case observer_state::aborted:
return "caf::flow::observer_state::aborted";
}
}
bool from_string(std::string_view in, observer_state& out) {
if (in == "caf::flow::observer_state::idle") {
out = observer_state::idle;
return true;
}
if (in == "caf::flow::observer_state::subscribed") {
out = observer_state::subscribed;
return true;
}
if (in == "caf::flow::observer_state::completed") {
out = observer_state::completed;
return true;
}
if (in == "caf::flow::observer_state::aborted") {
out = observer_state::aborted;
return true;
}
return false;
}
bool from_integer(std::underlying_type_t<observer_state> in,
observer_state& out) {
auto result = static_cast<observer_state>(in);
switch (result) {
default:
return false;
case observer_state::idle:
case observer_state::subscribed:
case observer_state::completed:
case observer_state::aborted:
out = result;
return true;
}
}
disposable make_trivial_disposable() { disposable make_trivial_disposable() {
return disposable{make_counted<trivial_impl>()}; return disposable{make_counted<trivial_impl>()};
} }
......
...@@ -20,6 +20,45 @@ ...@@ -20,6 +20,45 @@
namespace caf::flow { namespace caf::flow {
/// Represents the current state of an @ref observer.
enum class observer_state {
/// Indicates that no callbacks were called yet.
idle,
/// Indicates that on_subscribe was called.
subscribed,
/// Indicates that on_complete was called.
completed,
/// Indicates that on_error was called.
aborted
};
/// Returns whether `x` represents a final state, i.e., `completed`, `aborted`
/// or `disposed`.
constexpr bool is_final(observer_state x) noexcept {
return static_cast<int>(x) >= static_cast<int>(observer_state::completed);
}
/// Returns whether `x` represents an active state, i.e., `idle` or
/// `subscribed`.
constexpr bool is_active(observer_state x) noexcept {
return static_cast<int>(x) <= static_cast<int>(observer_state::subscribed);
}
/// @relates observer_state
std::string to_string(observer_state);
/// @relates observer_state
bool from_string(std::string_view, observer_state&);
/// @relates observer_state
bool from_integer(std::underlying_type_t<observer_state>, observer_state&);
/// @relates observer_state
template <class Inspector>
bool inspect(Inspector& f, observer_state& x) {
return default_enum_inspect(f, x);
}
/// Returns a trivial disposable that wraps an atomic flag. /// Returns a trivial disposable that wraps an atomic flag.
disposable make_trivial_disposable(); disposable make_trivial_disposable();
......
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