5#include "Stroika/Foundation/Characters/LineEndings.h"
11namespace Stroika::Foundation::Streams::OutputStream {
18 template <
typename ELEMENT_TYPE>
23 template <
typename ELEMENT_TYPE>
24 inline Ptr<ELEMENT_TYPE>::Ptr (nullptr_t)
28 template <
typename ELEMENT_TYPE>
31 return Debug::UncheckedDynamicPointerCast<IRep<ELEMENT_TYPE>> (inherited::GetSharedRep ());
33 template <
typename ELEMENT_TYPE>
36 return Debug::UncheckedDynamicCast<const IRep<ELEMENT_TYPE>&> (inherited::GetRepConstRef ());
38 template <
typename ELEMENT_TYPE>
41 return Debug::UncheckedDynamicCast<IRep<ELEMENT_TYPE>&> (inherited::GetRepRWRef ());
43 template <
typename ELEMENT_TYPE>
48 return GetRepConstRef ().GetWriteOffset ();
50 template <
typename ELEMENT_TYPE>
55 Require (offset <
static_cast<SeekOffsetType> (numeric_limits<SignedSeekOffsetType>::max ()));
56 return GetRepRWRef ().SeekWrite (Whence::eFromStart,
static_cast<SignedSeekOffsetType> (offset));
58 template <
typename ELEMENT_TYPE>
63 return GetRepRWRef ().SeekWrite (whence, offset);
65 template <
typename ELEMENT_TYPE>
66 template <
typename ELEMENT_TYPE2,
size_t EXTENT_2>
67 inline void Ptr<ELEMENT_TYPE>::Write (span<ELEMENT_TYPE2, EXTENT_2> elts)
const
68 requires (same_as<ELEMENT_TYPE, remove_cvref_t<ELEMENT_TYPE2>> or
69 (same_as<ELEMENT_TYPE, byte> and (same_as<remove_cvref_t<ELEMENT_TYPE2>, uint8_t>)) or
70 (same_as<ELEMENT_TYPE, Character> and (Characters::IUNICODECanUnambiguouslyConvertFrom<remove_cvref_t<ELEMENT_TYPE2>>)))
74 if (not elts.empty ()) [[likely]] {
75 if constexpr (same_as<ELEMENT_TYPE, byte>) {
76 GetRepRWRef ().Write (Memory::SpanBytesCast<span<const ELEMENT_TYPE>> (elts));
78 else if constexpr (same_as<ELEMENT_TYPE, Character>) {
79 if constexpr (
sizeof (ELEMENT_TYPE2) ==
sizeof (Character)) {
80 GetRepRWRef ().Write (Memory::SpanBytesCast<span<const ELEMENT_TYPE>> (elts));
83 Memory::StackBuffer<Character> buf{Memory::eUninitialized, Characters::UTFConvert::ComputeTargetBufferSize<Character> (elts)};
84 GetRepRWRef ().Write (Characters::UTFConvert::kThe.ConvertSpan (elts, span{buf}));
88 GetRepRWRef ().Write (elts);
92 template <
typename ELEMENT_TYPE>
93 inline void Ptr<ELEMENT_TYPE>::Write (
const Memory::BLOB& blob)
const
94 requires (same_as<ELEMENT_TYPE, byte>)
96 this->Write (blob.As<span<const byte>> ());
98 template <
typename ELEMENT_TYPE>
99 inline void Ptr<ELEMENT_TYPE>::Write (
const ELEMENT_TYPE& e)
const
101 this->Write (span{&e, 1});
103 template <
typename ELEMENT_TYPE>
104 void Ptr<ELEMENT_TYPE>::Write (
const Characters::String& s)
const
105 requires (same_as<ELEMENT_TYPE, Character>)
107 Memory::StackBuffer<Character> ignored;
108 this->Write (s.GetData<Character> (&ignored));
110 template <
typename ELEMENT_TYPE>
111 template <Characters::IUNICODECanUnambiguouslyConvertFrom CHAR_T>
112 inline void Ptr<ELEMENT_TYPE>::Write (
const CHAR_T* cStr)
const
113 requires (same_as<ELEMENT_TYPE, Character>)
115 this->Write (span{cStr, Characters::CString::Length (cStr)});
117 template <
typename ELEMENT_TYPE>
118 template <
typename ELT_2_WRITE>
119 inline void Ptr<ELEMENT_TYPE>::WriteLn (ELT_2_WRITE&& arg)
const
120 requires (same_as<ELEMENT_TYPE, Character>)
122 this->Write (forward<ELT_2_WRITE> (arg));
123 this->Write (Characters::kEOL<Character>);
125 template <
typename ELEMENT_TYPE>
127 requires (same_as<ELEMENT_TYPE, Character>)
131 va_start (argsList, format);
132 Write (Characters::FormatV (format, argsList));
135 template <
typename ELEMENT_TYPE>
139 GetRepRWRef ().CloseWrite ();
140 Ensure (not IsOpen ());
142 template <
typename ELEMENT_TYPE>
146 GetRepRWRef ().CloseWrite ();
150 Ensure (not IsOpen ());
152 template <
typename ELEMENT_TYPE>
156 return GetRepConstRef ().IsOpenWrite ();
158 template <
typename ELEMENT_TYPE>
162 GetRepRWRef ().
Flush ();
164 template <
typename ELEMENT_TYPE>
165 template <
typename T>
167 requires (same_as<ELEMENT_TYPE, Characters::Character>)
170 Write (write2TextStream);
#define RequireNotNull(p)
int64_t SignedSeekOffsetType
shared_lock< const AssertExternallySynchronizedMutex > ReadContext
Instantiate AssertExternallySynchronizedMutex::ReadContext to designate an area of code where protect...
unique_lock< AssertExternallySynchronizedMutex > WriteContext
Instantiate AssertExternallySynchronizedMutex::WriteContext to designate an area of code where protec...
Abstract interface for output stream object. Don't call directly (use Ptr usually) - but use directly...
OutputStream<>::Ptr is Smart pointer to a stream-based sink of data.
nonvirtual void Flush() const
forces any data contained in this stream to be written.