forked from Alepha/Alepha
Relocate StackableStreambuf to IOStreams.
This commit is contained in:
69
IOStreams/StackableStreambuf.h
Normal file
69
IOStreams/StackableStreambuf.h
Normal file
@ -0,0 +1,69 @@
|
||||
static_assert( __cplusplus > 2020'99 );
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Alepha/Alepha.h>
|
||||
|
||||
#include <ostream>
|
||||
#include <exception>
|
||||
#include <stdexcept>
|
||||
#include <memory>
|
||||
#include <stack>
|
||||
|
||||
namespace Alepha::Hydrogen::IOStreams ::detail:: stackable_streambuf
|
||||
{
|
||||
inline namespace exports
|
||||
{
|
||||
struct StackableStreambuf;
|
||||
|
||||
template< typename > struct PushStack;
|
||||
|
||||
struct PopStack{};
|
||||
}
|
||||
|
||||
struct exports::StackableStreambuf
|
||||
: virtual public std::streambuf
|
||||
{
|
||||
public:
|
||||
std::streambuf *underlying;
|
||||
|
||||
~StackableStreambuf() override;
|
||||
|
||||
// Children must be created by `new`.
|
||||
explicit StackableStreambuf( std::ostream &host );
|
||||
|
||||
auto out() const { return std::ostream{ underlying }; }
|
||||
|
||||
virtual void writeChar( char ch )= 0;
|
||||
virtual void drain()= 0;
|
||||
|
||||
int overflow( const int ch ) override;
|
||||
|
||||
std::streamsize xsputn( const char *data, std::streamsize amt ) override;
|
||||
};
|
||||
|
||||
template< typename T >
|
||||
struct exports::PushStack
|
||||
: T
|
||||
{
|
||||
using T::T;
|
||||
};
|
||||
|
||||
template< typename T >
|
||||
std::ostream &
|
||||
operator << ( std::ostream &os, PushStack< T > &¶ms )
|
||||
{
|
||||
build_streambuf( os, std::move( params ) );
|
||||
return os;
|
||||
}
|
||||
|
||||
inline namespace impl
|
||||
{
|
||||
std::ostream & operator << ( std::ostream &os, PopStack );
|
||||
}
|
||||
}
|
||||
|
||||
namespace Alepha::Hydrogen::IOStreams::inline exports::inline stackable_streambuf
|
||||
{
|
||||
using namespace detail::stackable_streambuf::exports;
|
||||
}
|
||||
Reference in New Issue
Block a user