4#include "Stroika/Foundation/StroikaPreComp.h"
6#include "Stroika/Foundation/Containers/Common.h"
7#include "Stroika/Foundation/Execution/Exceptions.h"
8#include "Stroika/Foundation/Execution/Throw.h"
21using namespace Stroika::Foundation::Memory;
22using namespace Stroika::Foundation::Streams;
26DISABLE_COMPILER_GCC_WARNING_START (
"GCC diagnostic ignored \"-Wdeprecated-declarations\"");
27DISABLE_COMPILER_CLANG_WARNING_START (
"clang diagnostic ignored \"-Wdeprecated-declarations\"");
34wstring Streams::iostream::ReadTextStream (istream& in)
36 streamoff start = in.tellg ();
37 in.seekg (0, ios_base::end);
38 streamoff end = in.tellg ();
39 Assert (start <= end);
42 if ((sizeof (streamoff) > sizeof (
size_t)) and ((end - start) > static_cast<streamoff> (numeric_limits<ptrdiff_t>::max ()))) [[unlikely]] {
46 size_t bufLen =
static_cast<size_t> (end - start);
48 in.seekg (start, ios_base::beg);
49 in.read (
reinterpret_cast<char*
> (buf.begin ()), bufLen);
50 size_t readLen =
static_cast<size_t> (in.gcount ());
51 Assert (readLen <= bufLen);
52 const char* startOfBuf =
reinterpret_cast<const char*
> (
static_cast<const byte*
> (buf));
53 return Characters::MapUNICODETextWithMaybeBOMTowstring (startOfBuf, startOfBuf + readLen);
54 DISABLE_COMPILER_MSC_WARNING_END (6237)
55 DISABLE_COMPILER_MSC_WARNING_END (4127)
58wstring Streams::iostream::ReadTextStream (wistream& in)
60 streamoff start = in.tellg ();
61 in.seekg (0, ios_base::end);
62 streamoff end = in.tellg ();
63 Assert (start <= end);
66 if ((sizeof (streamoff) > sizeof (
size_t)) and ((end - start) > static_cast<streamoff> (numeric_limits<ptrdiff_t>::max ()))) [[unlikely]] {
70 size_t bufLen =
static_cast<size_t> (end - start);
72 in.seekg (start, ios_base::beg);
73 in.read (
reinterpret_cast<wchar_t*
> (buf.begin ()), bufLen);
74 size_t readLen =
static_cast<size_t> (in.gcount ());
75 Assert (readLen <= bufLen);
76 const wchar_t* startOfBuf =
reinterpret_cast<const wchar_t*
> (
static_cast<const wchar_t*
> (buf));
77 return wstring (startOfBuf, startOfBuf + readLen);
78 DISABLE_COMPILER_MSC_WARNING_END (6237)
79 DISABLE_COMPILER_MSC_WARNING_END (4127)
87vector<
byte> Streams::iostream::ReadBytes (istream& in)
89 streamoff start = in.tellg ();
90 in.seekg (0, ios_base::end);
91 streamoff end = in.tellg ();
92 Assert (start <= end);
95 if ((sizeof (streamoff) > sizeof (
size_t)) and ((end - start) > static_cast<streamoff> (numeric_limits<ptrdiff_t>::max ()))) [[unlikely]] {
99 size_t len =
static_cast<size_t> (end - start);
101 in.seekg (start, ios_base::beg);
102 in.read (
reinterpret_cast<char*
> (buf.begin ()), len);
103 size_t xxx =
static_cast<size_t> (in.gcount ());
105 return vector<byte> (
static_cast<const byte*
> (buf),
static_cast<const byte*
> (buf) + xxx);
106 DISABLE_COMPILER_MSC_WARNING_END (6237)
107 DISABLE_COMPILER_MSC_WARNING_END (4127)
115void Streams::iostream::WriteBytes (ostream& out, const vector<
byte>& s)
120DISABLE_COMPILER_MSC_WARNING_END (4996);
121DISABLE_COMPILER_GCC_WARNING_END (
"GCC diagnostic ignored \"-Wdeprecated-declarations\"");
122DISABLE_COMPILER_CLANG_WARNING_END (
"clang diagnostic ignored \"-Wdeprecated-declarations\"");
Logically halfway between std::array and std::vector; Smart 'direct memory array' - which when needed...
DISABLE_COMPILER_MSC_WARNING_START(4996)
CONTAINER::value_type * Start(CONTAINER &c)
For a contiguous container (such as a vector or basic_string) - find the pointer to the start of the ...
void Throw(T &&e2Throw)
identical to builtin C++ 'throw' except that it does helpful, type dependent DbgTrace() messages firs...