2014-01-02 21:14:21 +00:00
|
|
|
/*
|
|
|
|
Copyright (c) 2013 Microsoft Corporation. All rights reserved.
|
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
|
|
|
|
Author: Leonardo de Moura
|
|
|
|
*/
|
|
|
|
#pragma once
|
2014-04-29 18:52:09 +00:00
|
|
|
#include "library/io_state.h"
|
2014-01-02 21:14:21 +00:00
|
|
|
|
|
|
|
namespace lean {
|
|
|
|
/**
|
|
|
|
\brief Base class for \c regular and \c diagnostic wrapper classes.
|
|
|
|
*/
|
|
|
|
class io_state_stream {
|
|
|
|
protected:
|
2014-07-10 17:32:00 +00:00
|
|
|
environment const & m_env;
|
|
|
|
formatter m_formatter;
|
|
|
|
output_channel & m_stream;
|
2014-08-06 22:25:28 +00:00
|
|
|
io_state_stream(environment const & env, formatter const & fmt, output_channel & s):m_env(env), m_formatter(fmt), m_stream(s) {}
|
2014-01-02 21:14:21 +00:00
|
|
|
public:
|
2014-07-10 17:32:00 +00:00
|
|
|
io_state_stream(environment const & env, io_state const & ios, bool regular = true):
|
|
|
|
m_env(env), m_formatter(ios.get_formatter_factory()(env, ios.get_options())),
|
|
|
|
m_stream(regular ? ios.get_regular_channel() : ios.get_diagnostic_channel()) {}
|
|
|
|
std::ostream & get_stream() const { return m_stream.get_stream(); }
|
2014-01-02 21:14:21 +00:00
|
|
|
void flush() { get_stream().flush(); }
|
2014-07-10 17:32:00 +00:00
|
|
|
formatter const & get_formatter() const { return m_formatter; }
|
|
|
|
options get_options() const { return m_formatter.get_options(); }
|
2014-04-30 17:28:07 +00:00
|
|
|
environment const & get_environment() const { return m_env; }
|
2014-08-06 22:25:28 +00:00
|
|
|
io_state_stream update_options(options const & o) const { return io_state_stream(m_env, m_formatter.update_options(o), m_stream); }
|
2014-01-02 21:14:21 +00:00
|
|
|
};
|
|
|
|
|
2014-07-10 17:32:00 +00:00
|
|
|
inline io_state_stream regular(environment const & env, io_state const & ios) { return io_state_stream(env, ios, true); }
|
|
|
|
inline io_state_stream diagnostic(environment const & env, io_state const & ios) { return io_state_stream(env, ios, false); }
|
2014-01-02 21:14:21 +00:00
|
|
|
|
|
|
|
// hack for using std::endl with channels
|
|
|
|
struct endl_class { endl_class() {} };
|
|
|
|
const endl_class endl;
|
|
|
|
|
|
|
|
class kernel_exception;
|
2014-12-15 19:04:55 +00:00
|
|
|
class generic_exception;
|
2014-01-02 21:14:21 +00:00
|
|
|
|
|
|
|
io_state_stream const & operator<<(io_state_stream const & out, endl_class);
|
|
|
|
io_state_stream const & operator<<(io_state_stream const & out, expr const & e);
|
|
|
|
io_state_stream const & operator<<(io_state_stream const & out, kernel_exception const & ex);
|
2014-12-15 19:04:55 +00:00
|
|
|
io_state_stream const & operator<<(io_state_stream const & out, generic_exception const & ex);
|
2014-11-27 17:43:58 +00:00
|
|
|
io_state_stream const & operator<<(io_state_stream const & out, format const & f);
|
2014-01-02 21:14:21 +00:00
|
|
|
template<typename T> io_state_stream const & operator<<(io_state_stream const & out, T const & t) {
|
|
|
|
out.get_stream() << t;
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
}
|