ios: Combine and simplify i/odiagstream

We need this for a rare use-case, so maintaining three flavors of
diagstream is too expensive. Furthermore, the buffering was removed
for simplicity.

Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
2023-07-25 16:31:52 +02:00
parent 516b428d4b
commit 6aa63f3bd6
2 changed files with 61 additions and 241 deletions

View File

@@ -59,18 +59,17 @@ namespace UnitTests
TEST_METHOD(diagstream)
{
constexpr size_t n = 3;
unique_ptr<std::fstream> f[n];
vector<std::fstream*> fv(n);
{
unique_ptr<ofstream> f[n];
vector<ofstream*> fv(n);
for (size_t i = 0; i < n; ++i)
{
for (size_t i = 0; i < n; ++i) {
WCHAR path[MAX_PATH];
ExpandEnvironmentStringsW(stdex::sprintf(L"%%temp%%\\file%zu.dat", NULL, i).c_str(), path, _countof(path));
f[i].reset(new ofstream(path, ios_base::out | ios_base::binary));
f[i].reset(new std::fstream(path, ios_base::out | ios_base::binary));
fv[i] = f[i].get();
}
stdex::odiagstream d(fv.begin(), fv.end(), 8);
stdex::diagstream d(fv.begin(), fv.end());
srand(0);
auto write_some_random = [](_Inout_ ostream& f, _In_ size_t amount)
{
@@ -87,16 +86,13 @@ namespace UnitTests
}
{
unique_ptr<ifstream> f[n];
vector<ifstream*> fv(n);
for (size_t i = 0; i < n; ++i)
{
for (size_t i = 0; i < n; ++i) {
WCHAR path[MAX_PATH];
ExpandEnvironmentStringsW(stdex::sprintf(L"%%temp%%\\file%zu.dat", NULL, i).c_str(), path, _countof(path));
f[i].reset(new ifstream(path, ios_base::in | ios_base::binary));
f[i].reset(new std::fstream(path, ios_base::in | ios_base::binary));
fv[i] = f[i].get();
}
stdex::idiagstream d(fv.begin(), fv.end(), 8);
stdex::diagstream d(fv.begin(), fv.end());
do {
uint32_t r;
d.read(reinterpret_cast<char*>(&r), sizeof(r) / sizeof(char));