ALib C++ Library
Library Version: 2402 R1
Documentation generated by doxygen
Loading...
Searching...
No Matches
std_strings_iostream.hpp
Go to the documentation of this file.
1/** ************************************************************************************************
2 * \file
3 * This header file is part of the \aliblong.<br>
4 * With the inclusion of this header compatibility features between \alib and the C++ standard
5 * library are provided.
6 *
7 * \emoji :copyright: 2013-2024 A-Worx GmbH, Germany.
8 * Published under \ref mainpage_license "Boost Software License".
9 **************************************************************************************************/
10#ifndef HPP_ALIB_COMPATIBILITY_STD_STRINGS_IOSTREAM
11#define HPP_ALIB_COMPATIBILITY_STD_STRINGS_IOSTREAM 1
12
13#if !defined(HPP_ALIB) && !defined(ALIB_DOX)
14# include "alib/alib.hpp"
15#endif
16
17ALIB_ASSERT_MODULE(STRINGS)
18
19#if !defined(HPP_ALIB_COMPATIBILITY_STD_CHARACTERS)
21#endif
22
23#if !defined (_GLIBCXX_IOSTREAM ) && !defined(_IOSTREAM_)
24 #include <iostream>
25#endif
26
27#if !defined (HPP_ALIB_STRINGS_LOCALSTRING)
29#endif
30
31
32namespace alib { namespace strings { namespace compatibility { namespace std {
33
34/** ************************************************************************************************
35 * This template type may be specialized to suppress ambiguities for types \p{T} which
36 * - have <c>std::operator<<(ostream, const T&)</c> defined, \b and
37 * - are \ref alib_strings_assembly_ttostring "appendable" to \alib strings.
38 *
39 * \note
40 * The ambiguity occurs due to the definition of <c>std::operator<<</c> for all appendable
41 * types.
42 *
43 * If a specialization of this template struct exists that inherits <c>std::true_type</c>,
44 * the compiler will not choose the \alib implementation of the operator, which resolves the
45 * ambiguity.
46 *
47 * \see
48 * Specialization might be done with macro
49 * \ref ALIB_STRINGS_SUPPRESS_STD_OSTREAM_OPERATOR.
50 *
51 * @tparam T The appendable type to suppress
52 **************************************************************************************************/
53template<typename T> struct T_SuppressStdOstreamOperator : ::std::false_type {};
54
55#define ALIB_STRINGS_SUPPRESS_STD_OSTREAM_OPERATOR(TYPE) \
56 namespace alib::strings::compatibility::std { \
57 template<> struct T_SuppressStdOstreamOperator<TYPE> : ::std::true_type {}; }
58
59
60/** ************************************************************************************************
61 * Parameter class used to append to objects of type \alib{strings;TAString;AString}, which
62 * invokes the method of the according specialization of template struct
63 * <b>T_Append<ISReadLine,TChar></b>.<br>
64 * This then reads a line of text from the encapsulated \b std::istream and appends that line to the
65 * target \b %AString.
66 *
67 * While, of-course, this class can be created 'inline' (for example, similar objects of parameter
68 * classes found in \alib{strings;TFormat;Format}), in the usual case that a series of lines are to
69 * be read from a \b std::istream, a local object of this type might be created. In case of a
70 * reading loop, rather outside such loop.
71 *
72 * Field #IsEOF can be used to detect the end of the input stream.
73 *
74 * \see
75 * - \alib{strings;compatibility::std::operator>>(std::istream&;NAString& string)} and
76 * \alib{strings;compatibility::std::operator<<(std::ostream&;const NString&)}.
77 * - For a sample, refer to source code of \alib class \b %IniFile, method
78 * \ref alib::config::IniFile::ReadFile "IniFile::ReadFile".
79 *
80 *
81 * @tparam TChar The character type of the input stream as well as the receiving string.<br>
82 * Specializations for character types \alib{characters;nchar},
83 * \alib{characters;wchar} exist. Those have corresponding alias type definition
84 * shortcuts \alib{ISReadLineN} and \alib{ISReadLineW} in namespace #alib.
85 **************************************************************************************************/
86template<typename TChar>
88{
89 /** The input stream to read from. */
90 ::std::basic_istream<TChar>* IStream;
91
92 /** If \c CurrentData::KEEP, the target \c %AString is not cleared before the read operation. */
94
95 /** The amount of characters that the buffer is increased while reading parts of the line. */
97
98 /** The maximum length of a single line to be read. Longer lines get truncated. */
100
101 /**
102 * Indicates if the end of the input stream was detected with the last read operation.
103 * If so, a next read operation will not change the string (or clear it, if #TargetData is
104 * \c false
105 */
106 bool IsEOF = false;
107
108 /** ********************************************************************************************
109 * Constructor.
110 *
111 * @param istream The input stream to read from.
112 * @param targetData If \c CurrentData::Keep, the target \c %AString is not cleared
113 * before the read operation is performed.
114 * Defaults to \c CurrentData::Clear.
115 * @param bufferSize The amount of characters that the buffer is increased while reading
116 * parts of the line. Defaults to 256 characters.
117 * @param maxLineWidth The maximum length of a single line to be read. Longer lines
118 * get truncated. Defaults to 4096 characters.
119 **********************************************************************************************/
120 TISReadLine( ::std::basic_istream<TChar>* istream,
122 integer bufferSize = 256,
123 integer maxLineWidth = 4096 )
124 : IStream (istream),
125 TargetData (targetData),
126 BufferSize (bufferSize),
127 MaxLineWidth(maxLineWidth)
128 {}
129};
130
131
132}} // namespace alib::strings[::compatibility::std]
133
134#if defined(ALIB_DOX)
135 namespace APPENDABLES {
136#endif
137
138/**
139 * Specialization of type-traits struct \alib{strings;T_Append} for type
140 * \alib{strings::compatibility::std;TISReadLine}.
141 * @tparam TChar String character type.
142 */
143template<typename TChar> struct T_Append<compatibility::std::TISReadLine<TChar>, TChar>
144{
145 /** ********************************************************************************************
146 * Reads a line from a text file and appends the contents to \p{target}.
147 * If the end of the input stream was reached, field
148 * \alib{strings::compatibility::std::TISReadLine;IsEOF} of parameter \p{reader} will be set
149 * to \c true what indicates that a next read operation
150 * would fail if it was performed.
151 *
152 * \note
153 * For setting field <em>IsEOF</em> the object will be casted to a non-constant reference.
154 * See functor \alib{strings;T_Append} for an explanation why it is OK to do so.
155 *
156 * @param target The AString object to read into.
157 * @param reader The object holding the \b std::istream and some parameters.
158 **********************************************************************************************/
161};
162
163#if defined(ALIB_DOX)
164} namespace alib::strings[::APPENDABLES]
165#endif
166namespace compatibility { namespace std {
167
168/** ************************************************************************************************
169 * This class is a simple helper class that converts strings of the
170 * \alib{characters;character;default character type} to narrow strings as expected by
171 * \c std::ostream objects.
172 *
173 * The basic goal of this class is to avoid preprocessor directives for code selection when
174 * the default string type of \alib uses wide characters.
175 *
176 * For example, to write string data into a file, the following approach is advised:
177 *
178 * 1. Create an output stream of (derived) type \c std::ostream.
179 * 2. Create an object of this class and pass the output stream via #SetStream.
180 * 3. Write string data stored in objects of platform dependent type alias \ref alib::AString
181 * by passing those to method #Write.
182 *
183 * Within step 3, the compiler chooses the right overloaded version of method #Write. Hence the
184 * potentially needed conversion of the string data done transparently and only if needed.
185 *
186 * \see Class \alib{strings::compatibility::std;StringReader}.
187 **************************************************************************************************/
189{
190 protected:
191 /** The string buffer used for conversion. */
193
194 public:
195 /** The output stream as provided with #SetStream. Will be set to the \c std::cout,
196 respectively \c std::wcout in the constructor. */
197 ::std::ostream* ostream;
198
199 public:
200 /** ****************************************************************************************
201 * Constructor.
202 * Invokes #SetStream passing \c std::cout.
203 ******************************************************************************************/
205 : ostream( &::std::cout )
206 {}
207
208
209 /** ****************************************************************************************
210 * Sets the output stream.
211 *
212 * @param os Pointer to the output stream to write to.
213 ******************************************************************************************/
214 void SetStream( ::std::ostream * os)
215 {
216 ostream= os;
217 }
218
219 /** ****************************************************************************************
220 * Returns the output stream previously set with #SetStream.
221 *
222 * @return The output stream set with #SetStream.
223 ******************************************************************************************/
224 ::std::ostream* GetStream()
225 {
226 return ostream;
227 }
228
229 /** ****************************************************************************************
230 * Write the given narrow string to the stream and return the length of the string given
231 * if it was converted to wide characters.
232 *
233 * \note
234 * The return value is the length of the given string if it was converted to wide string,
235 * even though in this overloaded version it is not needed to be converted.
236 * This is useful to determine the "real" output width when output text is to be formatted.
237 * Of-course, in many locales, this is still not the real output width, because even
238 * uni-code characters are not guaranteed to represent exactly one printable character.
239 * But still, this value is already a much better approximation than the length of the
240 * given narrow string.
241 *
242 * @param src The string to write.
243 * @return Returns the length of the given string as wide string.
244 ******************************************************************************************/
246 {
247 if( ostream == nullptr )
248 {
249 ALIB_WARNING( "STRINGS", "StringWriter::WriteAndGetWideLength: No output stream")
250 return 0;
251 }
252
253 ostream->write( src.Buffer(), src.Length() );
254 return src.WStringLength();
255 }
256
257 /** ****************************************************************************************
258 * Write the given wide string to the stream and returns the length of the string given
259 * @param src The string to write.
260 * @return Returns the length of the given wide string.
261 ******************************************************************************************/
263 {
264 if( ostream == nullptr )
265 {
266 ALIB_WARNING( "STRINGS", "StringWriter::WriteAndGetWideLength: No output stream")
267 return 0;
268 }
269
270 converter.Reset( src );
271 ostream->write( converter.Buffer(), converter.Length() );
272 return src.Length();
273 }
274
275 /** ****************************************************************************************
276 * Write the given narrow string to the stream.
277 *
278 * \note
279 * The return value is the length of the given string if it was converted to wide string,
280 * even in the case that it is not needed to be converted.
281 * This is useful to determine the real output width. Of-course, in many locales, this is
282 * still not the real output width, because even uni-code characters are not guaranteed
283 * to represent exactly one printable character. But still, this value is already a
284 * much better approximation than the length of the given narrow string.
285 *
286 * @param src The string to write.
287 ******************************************************************************************/
288 void Write( const NString& src )
289 {
290 if( ostream == nullptr )
291 {
292 ALIB_WARNING( "STRINGS", "StringWriter::WriteAndGetWideLength: No output stream")
293 return;
294 }
295 ostream->write( src.Buffer(), src.Length() );
296 }
297
298 /** ****************************************************************************************
299 * Write the given wide string to the stream.
300 * @param src The string to write.
301 ******************************************************************************************/
302 void Write( const WString& src )
303 {
304 if( ostream == nullptr )
305 {
306 ALIB_WARNING( "STRINGS", "StringWriter::WriteAndGetWideLength: No output stream")
307 return;
308 }
309 converter.Reset( src );
310 ostream->write( converter.Buffer(), converter.Length() );
311 }
312};
313
314/** ************************************************************************************************
315 * This class is a helper class that converts narrow string data read from an object of
316 * type \c std::istream to the \alib{characters;character;default character type}.
317 *
318 * \see Further explanations are given with sibling class
319 * \alib{strings::compatibility::std;StringWriter}.
320 **************************************************************************************************/
322{
323 protected:
324 /** The string buffer used for conversion. */
326
327 /** The input stream as provided with #SetStream. Will be set to the \c std::cin,
328 respectively \c std::win in the constructor. */
330
331
332 public:
333 /** ****************************************************************************************
334 * Constructor.Invokes #SetStream passing \c std::cin.
335 ******************************************************************************************/
337 : readOp( &::std::cin )
338 {}
339
340
341 /** ****************************************************************************************
342 * Sets the input stream.
343 *
344 * @param is Pointer to the input stream to read from to.
345 ******************************************************************************************/
346 void SetStream( ::std::istream* is ) { readOp.IStream= is;}
347
348 /** ****************************************************************************************
349 * Returns the input stream previously set with #SetStream.
350 *
351 * @return The input stream set with #SetStream.
352 ******************************************************************************************/
353 ::std::istream* GetStream() { return readOp.IStream; }
354
355 /** ****************************************************************************************
356 * Returns \c true if the input stream signaled its end, \c false otherwise.
357 *
358 * @return \c true if the input stream is known to be at its end, \c false otherwise.
359 ******************************************************************************************/
360 bool IsEOF() { return readOp.IsEOF; }
361
362
363 /** ****************************************************************************************
364 * Reads one line of text from the input stream into a narrow string.
365 *
366 * @param target The storage buffer for the string to read. This string will be cleared
367 * independent of the availability of input data.
368 ******************************************************************************************/
369 void Read( NAString& target )
370 {
371 target.Reset( readOp );
372 }
373
374 /** ****************************************************************************************
375 * Reads one line of text from the internal input stream into a wide string.
376 *
377 * @param target The storage buffer for the string to read. This string will be cleared
378 * independent of the availability of input data.
379 ******************************************************************************************/
380 void Read( WAString& target )
381 {
382 target.Reset();
383 converter.Reset( readOp );
384 target << converter;
385 }
386};
387
388}}} // namespace alib[::strings::compatibility::std]
389
390/// Type alias in namespace \b alib.
392
393/// Type alias in namespace \b alib.
395
396/// Type alias in namespace \b alib.
398
399/// Type alias in namespace \b alib.
401
402
403// #################################################################################################
404// #################### std::ostream& operator<< ###############################
405// #################################################################################################
406#if defined(ALIB_DOX)
407 namespace strings { namespace compatibility { namespace std {
408#else
409} // namespace [alib]
410#endif
411
412/** ************************************************************************************************
413 * Copies the contents of the given \b %NString to into the \c std::ostream given as reference.
414 *
415 * \note Unlike this documentation indicates, the operator is defined in the global namespace.
416 * @param stream The ostream object to write the given String into.
417 * @param string The String to write into the given ostream.
418 * @returns The ostream to allow concatenated operations.
419 **************************************************************************************************/
420inline std::ostream& operator<<( std::ostream& stream, const alib::NString& string )
421{
422 if ( string.IsNotEmpty() )
423 stream.write( string.Buffer(), string.Length() );
424 return stream;
425}
426
427/** ************************************************************************************************
428 * Copies the contents of the given \b %NString to into the \c std::ostream given as pointer.
429 *
430 * \note Unlike this documentation indicates, the operator is defined in the global namespace.
431 * @param stream The ostream object to write the given String into.
432 * @param string The String to write into the given ostream.
433 * @returns The ostream to allow concatenated operations.
434 **************************************************************************************************/
435inline std::ostream* operator<<( std::ostream* stream, const alib::NString& string )
436{
437 stream->write( string.Buffer(), string.Length() );
438 return stream;
439}
440
441/** ************************************************************************************************
442 * Copies the contents of the given \b %WString to into the \c std::ostream given as reference.
443 *
444 * \note Unlike this documentation indicates, the operator is defined in the global namespace.
445 * @param stream The ostream object to write the given String into.
446 * @param string The String to write into the given ostream.
447 * @returns The ostream to allow concatenated operations.
448 **************************************************************************************************/
449ALIB_API std::ostream& operator<<( std::ostream& stream, const alib::WString& string );
450
451/** ************************************************************************************************
452 * Copies the contents of the given \b %WString to into the \c std::ostream given as pointer.
453 *
454 * \note Unlike this documentation indicates, the operator is defined in the global namespace.
455 * @param stream The ostream object to write the given String into.
456 * @param string The String to write into the given ostream.
457 * @returns The ostream to allow concatenated operations.
458 **************************************************************************************************/
459inline std::ostream* operator<<( std::ostream* stream, const alib::WString& string )
460{
461 (*stream) << string;
462 return stream;
463}
464
465/** ************************************************************************************************
466 * Copies the contents of the given \b %NString to into the \c std::wostream given as reference.
467 *
468 * \note
469 * This operator uses a local string buffer of 256 bytes size to convert the given narrow string
470 * to an string of \c wchar_t characters that the output stream accepts. In case that
471 * the given \p{string} is larger, a dynamic memory allocation has to be made.<br>
472 * In performance critical code that writes larger string data, a custom conversion method,
473 * that for example reuses a buffer, may be appropriate.
474 *
475 * <p>
476 * \note Unlike this documentation indicates, the operator is defined in the global namespace.
477 * @param stream The ostream object to write the given String into.
478 * @param string The String to write into the given ostream.
479 * @returns The ostream to allow concatenated operations.
480 **************************************************************************************************/
481ALIB_API std::wostream& operator<<( std::wostream& stream, const alib::NString& string );
482
483/** ************************************************************************************************
484 * Copies the contents of the given \b %NString to into the \c std::wostream given as pointer.
485 *
486 * \note Unlike this documentation indicates, the operator is defined in the global namespace.
487 * \see The notes on memory efficiency, documented with operator
488 * \alib{strings::compatibility::std;operator<<(std::wostream&,const NString&)}
489 * which this operator uses inline.
490 * @param stream The ostream object to write the given String into.
491 * @param string The String to write into the given ostream.
492 * @returns The ostream to allow concatenated operations.
493 **************************************************************************************************/
494inline std::wostream* operator<<( std::wostream* stream, const alib::NString& string )
495{
496 (*stream) << string;
497 return stream;
498}
499
500/** ************************************************************************************************
501 * Copies the contents of the given \b %WString to into the \c std::wostream given as reference.
502 *
503 * \note Unlike this documentation indicates, the operator is defined in the global namespace.
504 * @param stream The ostream object to write the given String into.
505 * @param string The String to write into the given ostream.
506 * @returns The ostream to allow concatenated operations.
507 **************************************************************************************************/
508inline std::wostream& operator<<( std::wostream& stream, const alib::WString& string )
509{
510 if ( string.IsNotEmpty() )
511 {
512 #if ALIB_CHARACTERS_NATIVE_WCHAR
513 stream.write( string.Buffer(), string.Length() );
514 #else
515 alib::XLocalString<1024> converter( string );
517 stream.write( converter.Buffer(), converter.Length() );
518 #endif
519 }
520 return stream;
521}
522
523/** ************************************************************************************************
524 * Copies the contents of the given \b %WString to into the \c std::wostream given as pointer.
525 *
526 * \note Unlike this documentation indicates, the operator is defined in the global namespace.
527 * @param stream The ostream object to write the given String into.
528 * @param string The String to write into the given ostream.
529 * @returns The ostream to allow concatenated operations.
530 **************************************************************************************************/
531inline std::wostream* operator<<( std::wostream* stream, const alib::WString& string )
532{
533 (*stream) << string;
534 return stream;
535}
536
537/** ************************************************************************************************
538 * Clears the given \b %NAString and extracts data from the std::istream into it. The extractions
539 * ends with either the end of the std::istream or when reading a newline character.
540 *
541 * \note Unlike this documentation indicates, the operator is defined in the global namespace.
542 * @param stream The istream object to extract data from.
543 * @param string The AString to receive data.
544 * @returns The ostream to allow concatenated operations.
545 **************************************************************************************************/
546inline std::istream& operator>>( std::istream& stream, alib::NAString& string )
547{
548 string << alib::strings::compatibility::std::TISReadLine<alib::nchar>( &stream,
550 return stream;
551}
552
553/** ************************************************************************************************
554 * Clears the given \b %NAString and extracts data from the std::istream into it. The extractions
555 * ends with either the end of the std::istream or when reading a newline character.
556 *
557 * \note Unlike this documentation indicates, the operator is defined in the global namespace.
558 * @param stream The istream object to extract data from.
559 * @param string The AString to receive data.
560 * @returns The ostream to allow concatenated operations.
561 **************************************************************************************************/
562inline std::istream* operator>>( std::istream* stream, alib::NAString& string )
563{
564 ALIB_ASSERT_WARNING ( stream != nullptr, "STRINGS", "Given std::IStream is nullptr" )
565
566 if (stream != nullptr)
567 string << alib::strings::compatibility::std::TISReadLine<alib::nchar>( stream,
569 return stream;
570}
571
572/** ************************************************************************************************
573 * Clears the given \b %WAString and extracts data from the std::istream into it. The extractions
574 * ends with either the end of the std::istream or when reading a newline character.
575 *
576 * \note
577 * If code selection symbol \ref ALIB_CHARACTERS_NATIVE_WCHAR evaluates to false, a local buffer
578 * is used to convert the string of \c wchar_t characters that the input stream provides.
579 * In case that the string read from the stream is larger, a dynamic memory allocation has to
580 * be made.<br>
581 * In performance critical code that receives larger string data, a custom conversion method,
582 * that for example reuses a buffer, may be appropriate.
583 *
584 * <p>
585 * \note Unlike this documentation indicates, the operator is defined in the global namespace.
586 * @param stream The istream object to extract data from.
587 * @param string The AString to receive data.
588 * @returns The ostream to allow concatenated operations.
589 **************************************************************************************************/
590inline std::basic_istream<wchar_t>& operator>>( std::basic_istream<wchar_t>& stream,
591 alib::WAString& string )
592{
593 #if ALIB_CHARACTERS_NATIVE_WCHAR
594 string << alib::strings::compatibility::std::TISReadLine<wchar_t>( &stream,
596 #else
597 alib::XLocalString<1024> converter;
599 converter << alib::strings::compatibility::std::TISReadLine<wchar_t>( &stream,
601 string.Reset( converter );
602 #endif
603 return stream;
604}
605
606/** ************************************************************************************************
607 * Clears the given \b %WAString and extracts data from the std::istream into it. The extractions
608 * ends with either the end of the std::istream or when reading a newline character.
609 *
610 * \note Unlike this documentation indicates, the operator is defined in the global namespace.
611 *
612 * \see The notes on memory efficiency, documented with operator
613 * \alib{strings::compatibility::std;operator>>(std::basic_istream<wchar_t>&, WAString& )}
614 * which this operator uses inline.
615 * @param stream The istream object to extract data from.
616 * @param string The AString to receive data.
617 * @returns The ostream to allow concatenated operations.
618 **************************************************************************************************/
619inline std::basic_istream<wchar_t>* operator>>( std::basic_istream<wchar_t>* stream,
620 alib::WAString& string )
621{
622 ALIB_ASSERT_WARNING ( stream != nullptr, "STRINGS", "Given std::istream is nullptr" )
623
624 if (stream != nullptr)
625 (*stream) >> string;
626 return stream;
627}
628
629
630/** ************************************************************************************************
631 * Copies the contents of the given \ref alib_strings_assembly_ttostring "appendable type"
632 * the \c std::ostream given as reference.
633 *
634 * \note Unlike this documentation indicates, this operator is defined in the global namespace.
635 *
636 * @tparam TAppendable The appendable type.
637 * @param stream The \c std::ostream object to write the given String into.
638 * @param appendable The object whose contents is to be written into the given \p{stream}.
639 * @returns The ostream to allow concatenated operations.
640 **************************************************************************************************/
641template<typename TAppendable,
642 typename TEnableIf= typename std::enable_if< alib::strings::TT_IsAppendable<TAppendable,alib::nchar>::value
644 >::type>
645std::ostream& operator<<( std::ostream& stream, const TAppendable& appendable )
646{
649
650 if ( buf._(appendable).IsNotEmpty() )
651 stream.write( buf.Buffer(), buf.Length() );
652 return stream;
653}
654
655/** ************************************************************************************************
656 * Copies the contents of the given \alib{strings;T_Append;appendable type} the \c std::ostream
657 * given as pointer.
658 *
659 * \note Unlike this documentation indicates, this operator is defined in the global namespace.
660 *
661 * @tparam TAppendable The appendable type.
662 * @param stream The \c std::ostream object to write the given String into.
663 * @param appendable The object whose contents is to be written into the given \p{stream}.
664 * @returns The ostream to allow concatenated operations.
665 **************************************************************************************************/
666template<typename TAppendable,
667 typename TEnableIf= typename std::enable_if< alib::strings::TT_IsAppendable<TAppendable,alib::nchar>::value
669 >::type>
670
671std::ostream* operator<<( std::ostream* stream, const TAppendable& appendable )
672{
673 if (stream != nullptr)
674 operator<<( * stream, appendable );
675 return stream;
676}
677
678/** ************************************************************************************************
679 * Copies the contents of the given \alib{strings;T_Append;appendable type} the \c std::ostream
680 * given as reference.
681 *
682 * \note Unlike this documentation indicates, this operator is defined in the global namespace.
683 *
684 * @tparam TAppendable The appendable type.
685 * @param stream The \c std::ostream object to write the given String into.
686 * @param appendable The object whose contents is to be written into the given \p{stream}.
687 * @returns The ostream to allow concatenated operations.
688 **************************************************************************************************/
689template<typename TAppendable,
690 typename TEnableIf= typename std::enable_if< alib::strings::TT_IsAppendable<TAppendable,alib::wchar>::value
692 >::type>
693
694std::wostream& operator<<( std::wostream& stream, const TAppendable& appendable )
695{
696 #if ALIB_CHARACTERS_NATIVE_WCHAR
698 #else
700 #endif
702
703 if ( buf._(appendable).IsNotEmpty() )
704 stream.write( buf.Buffer(), buf.Length() );
705 return stream;
706}
707
708/** ************************************************************************************************
709 * Copies the contents of the given \alib{strings;T_Append;appendable type} the \c std::ostream
710 * given as pointer.
711 *
712 * \note Unlike this documentation indicates, this operator is defined in the global namespace.
713 *
714 * @tparam TAppendable The appendable type.
715 * @param stream The \c std::ostream object to write the given String into.
716 * @param appendable The object whose contents is to be written into the given \p{stream}.
717 * @returns The ostream to allow concatenated operations.
718 **************************************************************************************************/
719template<typename TAppendable,
720 typename TEnableIf= typename std::enable_if< alib::strings::TT_IsAppendable<TAppendable,alib::wchar>::value
722 >::type>
723std::wostream* operator<<( std::wostream* stream, const TAppendable& appendable )
724{
725 if (stream != nullptr)
726 operator<<( * stream, appendable );
727 return stream;
728}
729
730
731
732#if defined(ALIB_DOX)
733 }} namespace APPENDABLES {
734#else
735 namespace alib { namespace strings { // the real namespace
736#endif
737
738
740 ::operator()( TAString<char >& target, const strings::compatibility::std::TISReadLine<char >& reader );
741
743 ::operator()( TAString<wchar_t>& target, const strings::compatibility::std::TISReadLine<wchar_t>& reader );
744
745#if defined(ALIB_DOX)
746 }} // namespace alib[::strings::APPENDABLES]
747#else
748 } // namespace alib[::strings]
749#endif
750
751} // namespace [alib]
752
753
758
763
764#endif // HPP_ALIB_COMPATIBILITY_STD_STRINGS_IOSTREAM
TAString & _(const TString< TChar > &src, integer regionStart, integer regionLength=MAX_LEN)
Definition astring.hpp:1056
void DbgDisableBufferReplacementWarning()
Definition astring.hpp:353
constexpr bool IsNotEmpty() const
Definition string.hpp:420
constexpr integer Length() const
Definition string.hpp:357
constexpr const TChar * Buffer() const
Definition string.hpp:350
integer WStringLength() const
compatibility::std::TISReadLine< nchar > readOp
#define ALIB_WARNING(...)
Definition alib.hpp:981
#define ALIB_ASSERT_MODULE(modulename)
Definition alib.hpp:190
#define ALIB_API
Definition alib.hpp:538
#define ALIB_STRINGS_SUPPRESS_STD_OSTREAM_OPERATOR(TYPE)
#define ALIB_ASSERT_WARNING(cond,...)
Definition alib.hpp:985
@ Keep
Chooses not no clear existing data.
@ Clear
Chooses to clear existing data.
std::ostream & operator<<(std::ostream &stream, const alib::NString &string)
std::istream & operator>>(std::istream &stream, alib::NAString &string)
Definition alib.cpp:57
lang::integer integer
Type alias in namespace alib.
Definition integers.hpp:286
void operator()(TAString< TChar > &target, const compatibility::std::TISReadLine< TChar > &reader)
TISReadLine(::std::basic_istream< TChar > *istream, lang::CurrentData targetData=lang::CurrentData::Clear, integer bufferSize=256, integer maxLineWidth=4096)