forked from Alepha/Alepha
Exception state masking.
This commit is contained in:
38
IOStreams/EnableExceptions.h
Normal file
38
IOStreams/EnableExceptions.h
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
static_assert( __cplusplus > 2020'99 );
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Alepha/Alepha.h>
|
||||||
|
|
||||||
|
namespace Alepha::Hydrogen::IOStreams ::detail:: EnableExceptions_m
|
||||||
|
{
|
||||||
|
inline namespace exports
|
||||||
|
{
|
||||||
|
class EnableExceptions;
|
||||||
|
}
|
||||||
|
|
||||||
|
class exports::EnableExceptions
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
std::ios *ios;
|
||||||
|
std::ios_base::iostate oldState;
|
||||||
|
|
||||||
|
public:
|
||||||
|
~EnableExceptions()
|
||||||
|
{
|
||||||
|
ios->exceptions( oldState );
|
||||||
|
}
|
||||||
|
|
||||||
|
explicit
|
||||||
|
EnableExceptions( std::ios &ios )
|
||||||
|
: ios( &ios ), oldState( ios.exceptions() )
|
||||||
|
{
|
||||||
|
ios.exceptions( std::ios_base::badbit | std::ios_base::failbit );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace Alepha::Hydrogen::IOStreams::inline exports::inline EnableExceptions_m
|
||||||
|
{
|
||||||
|
using namespace detail::EnableExceptions_m::exports;
|
||||||
|
}
|
Reference in New Issue
Block a user