1
0
forked from Alepha/Alepha

Relocate StackableStreambuf to IOStreams.

This commit is contained in:
2023-11-10 13:30:08 -05:00
parent 6d8e503562
commit db70cb3b08
10 changed files with 17 additions and 16 deletions

View 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 > &&params )
{
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;
}