Commit dd8f1f1a authored by Dominik Charousset's avatar Dominik Charousset

Use new `deep_to_string` in actor ostream

parent 8a072b53
...@@ -21,13 +21,10 @@ ...@@ -21,13 +21,10 @@
#define CAF_ACTOR_OSTREAM_HPP #define CAF_ACTOR_OSTREAM_HPP
#include "caf/actor.hpp" #include "caf/actor.hpp"
#include "caf/message.hpp" #include "caf/deep_to_string.hpp"
namespace caf { namespace caf {
class local_actor;
class scoped_actor;
/// Provides support for thread-safe output operations on character streams. The /// Provides support for thread-safe output operations on character streams. The
/// stream operates on a per-actor basis and will print only complete lines or /// stream operates on a per-actor basis and will print only complete lines or
/// when explicitly forced to flush its buffer. The stream will convert *any* /// when explicitly forced to flush its buffer. The stream will convert *any*
...@@ -45,7 +42,7 @@ public: ...@@ -45,7 +42,7 @@ public:
/// Open redirection file in append mode. /// Open redirection file in append mode.
static constexpr int append = 0x01; static constexpr int append = 0x01;
explicit actor_ostream(local_actor* self); explicit actor_ostream(abstract_actor* self);
/// Writes `arg` to the buffer allocated for the calling actor. /// Writes `arg` to the buffer allocated for the calling actor.
actor_ostream& write(std::string arg); actor_ostream& write(std::string arg);
...@@ -54,31 +51,23 @@ public: ...@@ -54,31 +51,23 @@ public:
actor_ostream& flush(); actor_ostream& flush();
/// Redirects all further output from `self` to `file_name`. /// Redirects all further output from `self` to `file_name`.
static void redirect(local_actor* self, std::string file_name, int flags = 0); static void redirect(abstract_actor* self, std::string file_name, int flags = 0);
/// Redirects all further output from any actor that did not /// Redirects all further output from any actor that did not
/// redirect its output to `fname`. /// redirect its output to `fname`.
static void redirect_all(actor_system& sys, std::string fname, int flags = 0); static void redirect_all(actor_system& sys, std::string fname, int flags = 0);
/// Writes `arg` to the buffer allocated for the calling actor.
inline actor_ostream& operator<<(std::string arg) {
return write(std::move(arg));
}
/// Writes `arg` to the buffer allocated for the calling actor. /// Writes `arg` to the buffer allocated for the calling actor.
inline actor_ostream& operator<<(const char* arg) { inline actor_ostream& operator<<(const char* arg) {
return *this << std::string{arg}; return write(arg);
} }
/// Writes `to_string(arg)` to the buffer allocated for the calling actor, /// Writes `to_string(arg)` to the buffer allocated for the calling actor,
/// calling either `std::to_string` or `caf::to_string` depending on /// calling either `std::to_string` or `caf::to_string` depending on
/// the argument. /// the argument.
template <class T> template <class T>
inline typename std::enable_if< inline actor_ostream& operator<<(const T& arg) {
! std::is_convertible<T, std::string>::value, actor_ostream& return write(deep_to_string(arg));
>::type operator<<(const T& arg) {
using std::to_string;
return write(to_string(arg));
} }
/// Apply `f` to `*this`. /// Apply `f` to `*this`.
...@@ -86,15 +75,13 @@ public: ...@@ -86,15 +75,13 @@ public:
return f(*this); return f(*this);
} }
actor_ostream& operator<<(const message& msg);
private: private:
local_actor* self_; intrusive_ptr<abstract_actor> self_;
actor printer_; actor printer_;
}; };
/// Convenience factory function for creating an actor output stream. /// Convenience factory function for creating an actor output stream.
actor_ostream aout(local_actor* self); actor_ostream aout(abstract_actor* self);
/// Convenience factory function for creating an actor output stream. /// Convenience factory function for creating an actor output stream.
actor_ostream aout(scoped_actor& self); actor_ostream aout(scoped_actor& self);
......
...@@ -19,34 +19,35 @@ ...@@ -19,34 +19,35 @@
#include "caf/actor_ostream.hpp" #include "caf/actor_ostream.hpp"
#include "caf/all.hpp" #include "caf/send.hpp"
#include "caf/local_actor.hpp"
#include "caf/scoped_actor.hpp" #include "caf/scoped_actor.hpp"
#include "caf/abstract_actor.hpp"
#include "caf/scheduler/abstract_coordinator.hpp" #include "caf/scheduler/abstract_coordinator.hpp"
namespace caf { namespace caf {
actor_ostream::actor_ostream(local_actor* self) actor_ostream::actor_ostream(abstract_actor* self)
: self_(self), : self_(self),
printer_(self->system().scheduler().printer()) { printer_(self->system().scheduler().printer()) {
// nop // nop
} }
actor_ostream& actor_ostream::write(std::string arg) { actor_ostream& actor_ostream::write(std::string arg) {
send_as(self_, printer_, add_atom::value, std::move(arg)); send_as(actor_cast<actor>(self_), printer_, add_atom::value, std::move(arg));
return *this; return *this;
} }
actor_ostream& actor_ostream::flush() { actor_ostream& actor_ostream::flush() {
send_as(self_, printer_, flush_atom::value); send_as(actor_cast<actor>(self_), printer_, flush_atom::value);
return *this; return *this;
} }
void actor_ostream::redirect(local_actor* self, std::string fn, int flags) { void actor_ostream::redirect(abstract_actor* self, std::string fn, int flags) {
if (! self) if (! self)
return; return;
send_as(self, self->system().scheduler().printer(), intrusive_ptr<abstract_actor> ptr{self};
send_as(actor_cast<actor>(ptr), self->system().scheduler().printer(),
redirect_atom::value, self->address(), std::move(fn), flags); redirect_atom::value, self->address(), std::move(fn), flags);
} }
...@@ -55,11 +56,7 @@ void actor_ostream::redirect_all(actor_system& sys, std::string fn, int flags) { ...@@ -55,11 +56,7 @@ void actor_ostream::redirect_all(actor_system& sys, std::string fn, int flags) {
redirect_atom::value, std::move(fn), flags); redirect_atom::value, std::move(fn), flags);
} }
actor_ostream& actor_ostream::operator<<(const message&) { actor_ostream aout(abstract_actor* self) {
return *this << "-message-to-string-not-implemented-yet-";
}
actor_ostream aout(local_actor* self) {
return actor_ostream{self}; return actor_ostream{self};
} }
......
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