11#if !defined(ALIB_C20_MODULES) || ((ALIB_C20_MODULES != 0) && (ALIB_C20_MODULES != 1))
12# error "Symbol ALIB_C20_MODULES has to be given to the compiler as either 0 or 1"
36 export module ALib.Strings.StdIOStream;
98template<
typename TChar>
142 namespace APPENDABLES {
230template<
typename TChar =
nchar,
232 bool TSynced =
false,
234requires (::std::is_same_v<TChar, char> || ::std::is_same_v<TChar, wchar_t>)
254 #if defined(__cpp_lib_syncbuf) || DOXYGEN
259 ::std::basic_osyncstream< TChar,
260 ::std::char_traits<TChar>,
264 ::std::basic_ostream<TChar>&
ostream;
272 template<
typename TSrc>
280 #if !ALIB_SINGLE_THREADED && (defined(__cpp_lib_syncbuf) || DOXYGEN )
284 if constexpr (TSynced)
286 && (
ostream.get_wrapped() == ::std::cout.rdbuf()
287 ||
ostream.get_wrapped() == ::std::cerr.rdbuf() ) )
293 lineEnd= src.
IndexOf(
'\n', lineStart);
302 if (src.
CharAt(writeEnd - 1) ==
'\r' )
304 if (writeEnd > lineStart) {
305 if constexpr (::std::is_same_v<TChar, TSrc>) {
308 ostream.write( src.
Buffer() + lineStart, writeEnd - lineStart );
316 if ( printedWidth ) {
317 if constexpr (::std::is_same_v<TChar, wchar>)
318 *printedWidth= converter.
Length();
320 *printedWidth= line.
Length();
328 if constexpr ( ::std::is_same_v<TChar, nchar> )
ostream.write(
"\n", 1 );
329 else ostream.write( L
"\n", 1 );
331 if constexpr ( ::std::is_same_v<TChar, nchar> )
ostream.write(
"\r\n", 2 );
332 else ostream.write( L
"\r\n", 2 );
334 lineStart= lineEnd + 1;
343 #if !defined(__cpp_lib_syncbuf) || ALIB_SINGLE_THREADED || DOXYGEN
351 OStreamWriter(::std::basic_ostream<TChar>& os, TAllocator& alloc)
356 OStreamWriter(::std::basic_ostream<TChar>& os, TAllocator& alloc)
359 , ostream { os.rdbuf() ,
lang::StdAllocator<TChar, TAllocator>(alloc) } {}
407 while (count >= alc.Length() ) {
408 ostream.write(alc.Buffer(), alc.Length());
409 count-= alc.Length();
413 ostream.write(alc.Buffer(), count);
420template<
typename TChar =
nchar,
422 bool TSynced =
false,
430template<
typename TChar =
nchar,
432 bool TSynced =
false,
498template<
typename TChar =
nchar,
500 bool TSynced =
false,
512 namespace strings {
namespace compatibility {
namespace std {
527 if (
string.IsNotEmpty() )
528 stream.write(
string.Buffer(),
string.Length() );
543 stream->write(
string.Buffer(),
string.Length() );
620 if (
string.IsNotEmpty() ) {
621 #if ALIB_CHARACTERS_NATIVE_WCHAR
622 stream.write(
string.Buffer(),
string.Length() );
658 string << alib::strings::compatibility::std::TIStreamLine<alib::nchar>( &stream,
676 if (stream !=
nullptr)
677 string << alib::strings::compatibility::std::TIStreamLine<alib::nchar>( stream,
701inline std::basic_istream<wchar_t>&
operator>>( std::basic_istream<wchar_t>& stream,
703 #if ALIB_CHARACTERS_NATIVE_WCHAR
704 string << alib::strings::compatibility::std::TIStreamLine<wchar_t>( &stream,
709 converter << alib::strings::compatibility::std::TIStreamLine<wchar_t>( &stream,
711 string.Reset( converter );
730inline std::basic_istream<wchar_t>*
operator>>( std::basic_istream<wchar_t>* stream,
734 if (stream !=
nullptr)
752template<
typename TAppendable>
755std::ostream&
operator<<( std::ostream& stream,
const TAppendable& appendable ) {
776template<
typename TAppendable>
779std::ostream*
operator<<( std::ostream* stream,
const TAppendable& appendable ) {
780 if (stream !=
nullptr)
797template<
typename TAppendable>
800std::wostream&
operator<<( std::wostream& stream,
const TAppendable& appendable ) {
801 #if ALIB_CHARACTERS_NATIVE_WCHAR
826template<
typename TAppendable,
typename TAllocator>
829std::wostream*
operator<<( std::wostream* stream,
const TAppendable& appendable ) {
830 if (stream !=
nullptr)
838 }}
namespace APPENDABLES {
void Set(OwnablePointer ownable)
TAString & _(const TAppendable &src)
void DbgDisableBufferReplacementWarning()
constexpr integer Length() const
integer IndexOf(TChar needle, integer startIdx=0) const
TChar CharAt(integer idx) const
constexpr bool IsNotEmpty() const
constexpr const TChar * Buffer() const
integer WStringLength() const
void Read(NAString &target)
compatibility::std::TIStreamLine< nchar > readOp
void Read(WAString &target)
void SetStream(::std::istream *is)
::std::istream * GetStream()
NAString converter
The string buffer used for conversion.
IStreamReader()
Constructor.Invokes SetStream passing std::cin.
void Write(const NString &src, integer *printedWidth=nullptr)
::std::conditional_t< TSynced &&!ALIB_SINGLE_THREADED, ::std::basic_osyncstream< TChar, ::std::char_traits< TChar >, lang::StdAllocator< TChar, TAllocator > >, ::std::basic_ostream< TChar > & > ostream
void Write(const XString &src, integer *printedWidth=nullptr)
::std::ostream & GetStream()
OStreamWriter(::std::basic_ostream< TChar > &os)
void Write(const WString &src, integer *printedWidth=nullptr)
static constexpr lang::LineFeeds TargetLF
OStreamWriter(::std::basic_ostream< TChar > &os, TAllocator &alloc)
void doWrite(const TString< TSrc > &src, integer *printedWidth)
TChar CharType
Exposes template parameter TChar.
lang::AllocatorMember< TAllocator > allocBase
The type of the base class that stores the allocator.
void Fill(const TChar fillChar, integer count)
static constexpr bool Synced
TAllocator AllocatorType
Exposes template parameter TAllocator.
#define ALIB_COMMA_CALLER_PRUNED
#define ALIB_ASSERT_WARNING(cond, domain,...)
#define ALIB_STRINGS_SUPPRESS_STD_OSTREAM_OPERATOR(TYPE)
#define ALIB_SINGLE_THREADED
LineFeeds
Denotes line-feed encoding sequences "\n" and "\r\n".
@ WindowsOS
WindowsOS style line-feeds "\r\n".
@ Platform
Platform specific. Equals to either 'Unix' or 'WindowsOS'.
@ Unix
Unix-style line-feeds "\n".
@ Keep
Chooses not no clear existing data.
@ Clear
Chooses to clear existing data.
ALIB_EXPORT std::istream & operator>>(std::istream &stream, alib::NAString &string)
ALIB_EXPORT std::ostream & operator<<(std::ostream &stream, const alib::NString &string)
ALIB_DLL Lock STD_IOSTREAMS_LOCK
strings::TAString< wchar, lang::HeapAllocator > WAString
Type alias in namespace alib.
strings::compatibility::std::IStreamReader IStreamReader
Type alias in namespace alib.
strings::TString< xchar > XString
Type alias in namespace alib.
lang::integer integer
Type alias in namespace alib.
strings::TString< nchar > NString
Type alias in namespace alib.
strings::TAString< nchar, lang::HeapAllocator > NAString
Type alias in namespace alib.
strings::compatibility::std::TIStreamLine< alib::nchar > IStreamLineN
Type alias in namespace alib.
strings::TString< wchar > WString
Type alias in namespace alib.
strings::compatibility::std::TIStreamLine< alib::character > IStreamLine
Type alias in namespace alib.
characters::nchar nchar
Type alias in namespace alib.
strings::TLocalString< xchar, TCapacity, lang::HeapAllocator > XLocalString
Type alias in namespace alib.
NLocalString< 256 > NString256
Type alias name for TLocalString<nchar,256>.
strings::compatibility::std::OStreamWriter< TChar, TAllocator, TSynced, TTargetLF > OStreamWriter
Type alias in namespace alib.
strings::compatibility::std::TIStreamLine< alib::wchar > IStreamLineW
Type alias in namespace alib.
strings::TLocalString< wchar, TCapacity, lang::HeapAllocator > WLocalString
Type alias in namespace alib.
TAllocator & GetAllocator() const noexcept
void operator()(TAString< TChar, lang::HeapAllocator > &target, const compatibility::std::TIStreamLine< TChar > &reader)
::std::basic_istream< alib::character > * IStream
TIStreamLine(::std::basic_istream< TChar > *istream, lang::CurrentData targetData=lang::CurrentData::Clear, integer bufferSize=256, integer maxLineWidth=4096)
lang::CurrentData TargetData