Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
Copy.inl
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
6
7namespace Stroika::Foundation::Streams {
8
9 /*
10 ********************************************************************************
11 ****************************** Streams::CopyAll ********************************
12 ********************************************************************************
13 */
14 template <typename ELEMENT_TYPE>
15 inline void CopyAll (typename InputStream::Ptr<ELEMENT_TYPE> from, typename OutputStream::Ptr<ELEMENT_TYPE> to, size_t bufferSize)
16 {
17 CopyAll_Buffered<ELEMENT_TYPE> (from, to, bufferSize);
18 }
19
20 /*
21 ********************************************************************************
22 ************************ Streams::CopyAll_OneRead ******************************
23 ********************************************************************************
24 */
25 template <typename ELEMENT_TYPE>
27 {
28 to.Write (from.ReadAll ());
29 }
30
31 /*
32 ********************************************************************************
33 ************************** Streams::CopyAll_Buffered ***************************
34 ********************************************************************************
35 */
36 template <typename ELEMENT_TYPE>
37 void CopyAll_Buffered (typename InputStream::Ptr<ELEMENT_TYPE> from, typename OutputStream::Ptr<ELEMENT_TYPE> to, size_t bufferSize)
38 {
39 Memory::StackBuffer<ELEMENT_TYPE> buf{Memory::eUninitializedIfTrivial, bufferSize};
40 while (size_t n = from.ReadBlocking (span{buf}).size ()) {
41 Assert (n <= buf.size ());
42 to.Write (span{buf.begin (), n});
44 }
45 }
46
47}
void CopyAll_Buffered(typename InputStream::Ptr< ELEMENT_TYPE > from, typename OutputStream::Ptr< ELEMENT_TYPE > to, size_t bufferSize=10 *1024)
Copy the contents of stream 'from' to stream 'to', by reading a chunk at a time - tends to do multipl...
Definition Copy.inl:37
void CopyAll_OneRead(typename InputStream::Ptr< ELEMENT_TYPE > from, typename OutputStream::Ptr< ELEMENT_TYPE > to)
Copy the contents of stream 'from' to stream 'to', by reading ALL of from into memory at once,...
Definition Copy.inl:26
void CopyAll(typename InputStream::Ptr< ELEMENT_TYPE > from, typename OutputStream::Ptr< ELEMENT_TYPE > to, size_t bufferSize=10 *1024)
Copy the contents of stream 'from' to stream 'to'.
Definition Copy.inl:15
Logically halfway between std::array and std::vector; Smart 'direct memory array' - which when needed...
InputStream<>::Ptr is Smart pointer (with abstract Rep) class defining the interface to reading from ...
nonvirtual String ReadAll(size_t upTo=numeric_limits< size_t >::max()) const
nonvirtual optional< ElementType > ReadBlocking() const
ReadBlocking () reads either a single element, or fills in argument intoBuffer - but never blocks (no...
OutputStream<>::Ptr is Smart pointer to a stream-based sink of data.
nonvirtual void Write(span< ELEMENT_TYPE2, EXTENT_2 > elts) const