11#if !defined(ALIB_C20_MODULES) || ((ALIB_C20_MODULES != 0) && (ALIB_C20_MODULES != 1))
12# error "Configuration MACRO 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 {
231template<
typename TChar =
nchar,
233 bool TSynced =
false,
235requires (::std::is_same_v<TChar, char> || ::std::is_same_v<TChar, wchar_t>)
255 #if defined(__cpp_lib_syncbuf) || DOXYGEN
260 ::std::basic_osyncstream< TChar,
261 ::std::char_traits<TChar>,
265 ::std::basic_ostream<TChar>&
ostream;
273 template<
typename TSrc>
281 #if !ALIB_SINGLE_THREADED && (defined(__cpp_lib_syncbuf) || DOXYGEN )
285 if constexpr (TSynced)
287 && (
ostream.get_wrapped() == ::std::cout.rdbuf()
288 ||
ostream.get_wrapped() == ::std::cerr.rdbuf() ) )
294 lineEnd= src.
IndexOf(
'\n', lineStart);
303 if (src.
CharAt(writeEnd - 1) ==
'\r' )
305 if (writeEnd > lineStart) {
306 if constexpr (::std::is_same_v<TChar, TSrc>) {
309 ostream.write( src.
Buffer() + lineStart, writeEnd - lineStart );
317 if ( printedWidth ) {
318 if constexpr (::std::is_same_v<TChar, wchar>)
319 *printedWidth= converter.
Length();
321 *printedWidth= line.
Length();
329 if constexpr ( ::std::is_same_v<TChar, nchar> )
ostream.write(
"\n", 1 );
330 else ostream.write( L
"\n", 1 );
332 if constexpr ( ::std::is_same_v<TChar, nchar> )
ostream.write(
"\r\n", 2 );
333 else ostream.write( L
"\r\n", 2 );
335 lineStart= lineEnd + 1;
344 #if !defined(__cpp_lib_syncbuf) || ALIB_SINGLE_THREADED || DOXYGEN
352 OStreamWriter(::std::basic_ostream<TChar>& os, TAllocator& alloc)
357 OStreamWriter(::std::basic_ostream<TChar>& os, TAllocator& alloc)
360 , ostream { os.rdbuf() ,
lang::StdAllocator<TChar, TAllocator>(alloc) } {}
408 while (count >= alc.Length() ) {
409 ostream.write(alc.Buffer(), alc.Length());
410 count-= alc.Length();
414 ostream.write(alc.Buffer(), count);
421template<
typename TChar =
nchar,
423 bool TSynced =
false,
431template<
typename TChar =
nchar,
433 bool TSynced =
false,
462 :
readOp( &::
std::cin,
lang::CurrentData::Clear, bufferSize, maxLineWidth )
505template<
typename TChar =
nchar,
507 bool TSynced =
false,
519 namespace strings {
namespace compatibility {
namespace std {
534 if (
string.IsNotEmpty() )
535 stream.write(
string.Buffer(),
string.Length() );
550 stream->write(
string.Buffer(),
string.Length() );
627 if (
string.IsNotEmpty() ) {
628 #if ALIB_CHARACTERS_NATIVE_WCHAR
629 stream.write(
string.Buffer(),
string.Length() );
665 string << alib::strings::compatibility::std::TIStreamLine<alib::nchar>( &stream,
683 if (stream !=
nullptr)
684 string << alib::strings::compatibility::std::TIStreamLine<alib::nchar>( stream,
708inline std::basic_istream<wchar_t>&
operator>>( std::basic_istream<wchar_t>& stream,
710 #if ALIB_CHARACTERS_NATIVE_WCHAR
711 string << alib::strings::compatibility::std::TIStreamLine<wchar_t>( &stream,
716 converter << alib::strings::compatibility::std::TIStreamLine<wchar_t>( &stream,
718 string.Reset( converter );
737inline std::basic_istream<wchar_t>*
operator>>( std::basic_istream<wchar_t>* stream,
741 if (stream !=
nullptr)
759template<
typename TAppendable>
762std::ostream&
operator<<( std::ostream& stream,
const TAppendable& appendable ) {
783template<
typename TAppendable>
786std::ostream*
operator<<( std::ostream* stream,
const TAppendable& appendable ) {
787 if (stream !=
nullptr)
804template<
typename TAppendable>
807std::wostream&
operator<<( std::wostream& stream,
const TAppendable& appendable ) {
808 #if ALIB_CHARACTERS_NATIVE_WCHAR
833template<
typename TAppendable,
typename TAllocator>
836std::wostream*
operator<<( std::wostream* stream,
const TAppendable& appendable ) {
837 if (stream !=
nullptr)
845 }}
namespace APPENDABLES {
#define ALIB_COMMA_CALLER_PRUNED
#define ALIB_SINGLE_THREADED
#define ALIB_ASSERT_WARNING(cond, domain,...)
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
IStreamReader(integer bufferSize=4096, integer maxLineWidth=4096)
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.
::std::conditional_t< TSynced &&!0, ::std::basic_osyncstream< TChar, ::std::char_traits< TChar >, lang::StdAllocator< TChar, TAllocator > >, ::std::basic_ostream< TChar > & > ostream
void Write(const NString &src, integer *printedWidth=nullptr)
void Write(const XString &src, integer *printedWidth=nullptr)
::std::ostream & GetStream()
OStreamWriter(::std::basic_ostream< TChar > &os)
lang::AllocatorMember< TAllocator > allocBase
The type of the base class that stores the allocator.
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.
void Fill(const TChar fillChar, integer count)
static constexpr bool Synced
TAllocator AllocatorType
Exposes template parameter TAllocator.
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)
strings::TString< nchar > NString
Type alias in namespace alib.
strings::compatibility::std::IStreamReader IStreamReader
Type alias in namespace alib.
strings::TString< wchar > WString
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.
strings::TString< xchar > XString
Type alias in namespace alib.
strings::TAString< nchar, lang::HeapAllocator > NAString
Type alias in namespace alib.
lang::integer integer
Type alias in namespace alib.
strings::compatibility::std::TIStreamLine< alib::character > IStreamLine
Type alias in namespace alib.
strings::TLocalString< xchar, TCapacity, lang::HeapAllocator > XLocalString
Type alias in namespace alib.
characters::nchar nchar
Type alias in namespace alib.
strings::compatibility::std::TIStreamLine< alib::nchar > IStreamLineN
Type alias in namespace alib.
NLocalString< 256 > NString256
Type alias name for #"TLocalString;TLocalString<nchar,256>".
strings::TAString< wchar, lang::HeapAllocator > WAString
Type alias in namespace alib.
strings::compatibility::std::OStreamWriter< TChar, TAllocator, TSynced, TTargetLF > OStreamWriter
Type alias in namespace alib.
#define ALIB_STRINGS_SUPPRESS_STD_OSTREAM_OPERATOR(TYPE)
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=4096, integer maxLineWidth=4096)
lang::CurrentData TargetData