Compare commits
2 Commits
feature-st
...
feature-st
| Author | SHA1 | Date | |
|---|---|---|---|
| 798a9dd9b1 | |||
| fe1e056196 |
@ -1,2 +1,2 @@
|
|||||||
api=2307
|
api=2306
|
||||||
patch=0
|
patch=0
|
||||||
|
|||||||
@ -1,3 +0,0 @@
|
|||||||
Test-ICharStream1.C
|
|
||||||
|
|
||||||
EXE = $(FOAM_USER_APPBIN)/Test-ICharStream1
|
|
||||||
@ -5,7 +5,7 @@
|
|||||||
\\ / A nd | www.openfoam.com
|
\\ / A nd | www.openfoam.com
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2020-2023 OpenCFD Ltd.
|
Copyright (C) 2020 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -33,7 +33,6 @@ Description
|
|||||||
|
|
||||||
#include "argList.H"
|
#include "argList.H"
|
||||||
#include "Fstream.H"
|
#include "Fstream.H"
|
||||||
#include "OSspecific.H"
|
|
||||||
#include "etcFiles.H"
|
#include "etcFiles.H"
|
||||||
|
|
||||||
using namespace Foam;
|
using namespace Foam;
|
||||||
@ -45,14 +44,11 @@ int main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
argList::noBanner();
|
argList::noBanner();
|
||||||
argList::noParallel();
|
argList::noParallel();
|
||||||
argList::noParallel();
|
|
||||||
argList::addOption("ignore", "file", "Test readRaw with ignore");
|
|
||||||
|
|
||||||
#include "setRootCase.H"
|
#include "setRootCase.H"
|
||||||
|
|
||||||
// Test with etc/controlDict (mandatory, from distribution)
|
// Test with etc/controlDict (mandatory, from distribution)
|
||||||
|
|
||||||
if (!args.found("ignore"))
|
|
||||||
{
|
{
|
||||||
const fileName inputFile
|
const fileName inputFile
|
||||||
(
|
(
|
||||||
@ -101,43 +97,6 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fileName testFile;
|
|
||||||
if (args.readIfPresent("ignore", testFile))
|
|
||||||
{
|
|
||||||
if (testFile.has_ext("gz"))
|
|
||||||
{
|
|
||||||
testFile.remove_ext();
|
|
||||||
Info<< "stripping extraneous .gz ending" << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
IFstream is(testFile);
|
|
||||||
auto& stdStream = is.stdStream();
|
|
||||||
|
|
||||||
List<char> buffer(1000);
|
|
||||||
|
|
||||||
Info<< "Test readRaw with: " << is.name()
|
|
||||||
<< " compressed:" << int(is.compression())
|
|
||||||
<< " file-size:" << is.fileSize() << nl;
|
|
||||||
|
|
||||||
for (int iter = 0; is.good() && iter < 1000; ++iter)
|
|
||||||
{
|
|
||||||
Info<< "iter:" << iter;
|
|
||||||
if (iter % 2)
|
|
||||||
{
|
|
||||||
Info<< " [read] ";
|
|
||||||
is.readRaw(buffer.data(), buffer.size());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Info<< " [ignore]";
|
|
||||||
is.readRaw(nullptr, buffer.size() / 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
Info<< " : " << stdStream.gcount() << endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Info<< "\nEnd\n" << endl;
|
Info<< "\nEnd\n" << endl;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
3
applications/test/IListStream/Make/files
Normal file
3
applications/test/IListStream/Make/files
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
Test-IListStream.C
|
||||||
|
|
||||||
|
EXE = $(FOAM_USER_APPBIN)/Test-IListStream
|
||||||
@ -5,7 +5,7 @@
|
|||||||
\\ / A nd | www.openfoam.com
|
\\ / A nd | www.openfoam.com
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2017-2023 OpenCFD Ltd.
|
Copyright (C) 2017-2018 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -27,46 +27,14 @@ Description
|
|||||||
|
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include "SpanStream.H"
|
#include "ListStream.H"
|
||||||
|
#include "UListStream.H"
|
||||||
#include "wordList.H"
|
#include "wordList.H"
|
||||||
#include "IOstreams.H"
|
#include "IOstreams.H"
|
||||||
#include "argList.H"
|
#include "argList.H"
|
||||||
|
|
||||||
#include <cctype>
|
|
||||||
#include <cstdio>
|
|
||||||
|
|
||||||
using namespace Foam;
|
using namespace Foam;
|
||||||
|
|
||||||
Ostream& writeList(Ostream& os, const UList<char>& list)
|
|
||||||
{
|
|
||||||
char buf[4];
|
|
||||||
os << list.size() << '(';
|
|
||||||
for (const char c : list)
|
|
||||||
{
|
|
||||||
if (isprint(c))
|
|
||||||
{
|
|
||||||
os << c;
|
|
||||||
}
|
|
||||||
else if (c == '\t')
|
|
||||||
{
|
|
||||||
os << "\\t";
|
|
||||||
}
|
|
||||||
else if (c == '\n')
|
|
||||||
{
|
|
||||||
os << "\\n";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
::snprintf(buf, 4, "%02X", c);
|
|
||||||
os << "\\x" << buf;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
os << ')';
|
|
||||||
|
|
||||||
return os;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Ostream& toString(Ostream& os, const UList<char>& list)
|
Ostream& toString(Ostream& os, const UList<char>& list)
|
||||||
{
|
{
|
||||||
os << '"';
|
os << '"';
|
||||||
@ -125,7 +93,7 @@ int main(int argc, char *argv[])
|
|||||||
// Buffer storage
|
// Buffer storage
|
||||||
DynamicList<char> storage(16);
|
DynamicList<char> storage(16);
|
||||||
|
|
||||||
OCharStream obuf(std::move(storage));
|
OListStream obuf(std::move(storage));
|
||||||
obuf << 1002 << " " << "abcd" << " " << "def" << " " << 3.14159 << ";\n";
|
obuf << 1002 << " " << "abcd" << " " << "def" << " " << 3.14159 << ";\n";
|
||||||
|
|
||||||
// Move contents to output buffer
|
// Move contents to output buffer
|
||||||
@ -136,9 +104,9 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
Info<< "transfer contents to a List" << endl;
|
Info<< "transfer contents to a List" << endl;
|
||||||
|
|
||||||
ICharStream ibuf;
|
IListStream ibuf;
|
||||||
|
|
||||||
// Reclaim data storage from OCharStream -> ICharStream
|
// Reclaim data storage from OListStream -> IListStream
|
||||||
{
|
{
|
||||||
List<char> data;
|
List<char> data;
|
||||||
obuf.swap(data);
|
obuf.swap(data);
|
||||||
@ -193,43 +161,6 @@ int main(int argc, char *argv[])
|
|||||||
Info<<nl << "swapped out:";
|
Info<<nl << "swapped out:";
|
||||||
printInfo(newvalues);
|
printInfo(newvalues);
|
||||||
|
|
||||||
{
|
|
||||||
iliststream is(std::move(newvalues));
|
|
||||||
|
|
||||||
char c = 0;
|
|
||||||
|
|
||||||
Info<< nl
|
|
||||||
<< "getting values from iliststream of "
|
|
||||||
<< is.list() << endl;
|
|
||||||
|
|
||||||
// Info<< " (" << is.tellg() << " " << is.remaining() << ")";
|
|
||||||
// Info<< "get:";
|
|
||||||
while (is.get(c))
|
|
||||||
{
|
|
||||||
Info<< ' ' << c;
|
|
||||||
// Info<< " (" << is.tellg() << " " << is.remaining() << ")";
|
|
||||||
}
|
|
||||||
Info<< " - end" << nl;
|
|
||||||
|
|
||||||
// Info<< "remaining: " << is.list() << endl;
|
|
||||||
// Info<< "remaining: " << is.remaining() << endl;
|
|
||||||
|
|
||||||
// Manipulate the list view
|
|
||||||
{
|
|
||||||
UList<char> chars(is.list());
|
|
||||||
Foam::reverse(chars);
|
|
||||||
}
|
|
||||||
|
|
||||||
is.rewind();
|
|
||||||
|
|
||||||
Info<< "get:";
|
|
||||||
while (is.get(c))
|
|
||||||
{
|
|
||||||
Info<< ' ' << c;
|
|
||||||
}
|
|
||||||
Info<< " - end" << nl;
|
|
||||||
}
|
|
||||||
|
|
||||||
Info<< "\nEnd\n" << endl;
|
Info<< "\nEnd\n" << endl;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -28,6 +28,8 @@ Description
|
|||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include "argList.H"
|
#include "argList.H"
|
||||||
|
#include "ListStream.H"
|
||||||
|
#include "UListStream.H"
|
||||||
#include "wordList.H"
|
#include "wordList.H"
|
||||||
#include "IOstreams.H"
|
#include "IOstreams.H"
|
||||||
#include "argList.H"
|
#include "argList.H"
|
||||||
|
|||||||
@ -1,3 +0,0 @@
|
|||||||
Test-OCharStream1.C
|
|
||||||
|
|
||||||
EXE = $(FOAM_USER_APPBIN)/Test-OCharStream1
|
|
||||||
@ -74,7 +74,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
Info<< "counter state: " << (cnt.stdStream().rdstate()) << nl
|
Info<< "counter state: " << (cnt.stdStream().rdstate()) << nl
|
||||||
<< "via string-stream: " << str.str().size() << " chars" << nl
|
<< "via string-stream: " << str.str().size() << " chars" << nl
|
||||||
<< "via ocountstream: " << plain.count() << " chars" << endl;
|
<< "via ocountstream: " << plain.size() << " chars" << endl;
|
||||||
|
|
||||||
fileName outputName;
|
fileName outputName;
|
||||||
args.readIfPresent("write", outputName);
|
args.readIfPresent("write", outputName);
|
||||||
|
|||||||
3
applications/test/OListStream/Make/files
Normal file
3
applications/test/OListStream/Make/files
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
Test-OListStream.C
|
||||||
|
|
||||||
|
EXE = $(FOAM_USER_APPBIN)/Test-OListStream
|
||||||
@ -5,7 +5,7 @@
|
|||||||
\\ / A nd | www.openfoam.com
|
\\ / A nd | www.openfoam.com
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2017-2023 OpenCFD Ltd.
|
Copyright (C) 2017-2021 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -27,46 +27,13 @@ Description
|
|||||||
|
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include "SpanStream.H"
|
#include "ListStream.H"
|
||||||
#include "wordList.H"
|
#include "wordList.H"
|
||||||
#include "IOstreams.H"
|
#include "IOstreams.H"
|
||||||
#include "argList.H"
|
#include "argList.H"
|
||||||
|
|
||||||
#include <cctype>
|
|
||||||
#include <cstdio>
|
|
||||||
|
|
||||||
using namespace Foam;
|
using namespace Foam;
|
||||||
|
|
||||||
Ostream& writeList(Ostream& os, const UList<char>& list)
|
|
||||||
{
|
|
||||||
char buf[4];
|
|
||||||
os << list.size() << '(';
|
|
||||||
for (const char c : list)
|
|
||||||
{
|
|
||||||
if (isprint(c))
|
|
||||||
{
|
|
||||||
os << c;
|
|
||||||
}
|
|
||||||
else if (c == '\t')
|
|
||||||
{
|
|
||||||
os << "\\t";
|
|
||||||
}
|
|
||||||
else if (c == '\n')
|
|
||||||
{
|
|
||||||
os << "\\n";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
::snprintf(buf, 4, "%02X", c);
|
|
||||||
os << "\\x" << buf;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
os << ')';
|
|
||||||
|
|
||||||
return os;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Ostream& toString(Ostream& os, const UList<char>& list)
|
Ostream& toString(Ostream& os, const UList<char>& list)
|
||||||
{
|
{
|
||||||
os << '"';
|
os << '"';
|
||||||
@ -124,12 +91,12 @@ void outputDict(OS& os)
|
|||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
#include "setRootCase.H"
|
|
||||||
|
|
||||||
// Buffer storage
|
// Buffer storage
|
||||||
DynamicList<char> storage(16);
|
DynamicList<char> storage(16);
|
||||||
|
|
||||||
OCharStream obuf(std::move(storage));
|
OListStream obuf(std::move(storage));
|
||||||
|
|
||||||
|
obuf.setBlockSize(100);
|
||||||
|
|
||||||
printInfo(obuf);
|
printInfo(obuf);
|
||||||
|
|
||||||
@ -173,10 +140,10 @@ int main(int argc, char *argv[])
|
|||||||
Info<<"after overwrite" << nl;
|
Info<<"after overwrite" << nl;
|
||||||
printInfo(obuf);
|
printInfo(obuf);
|
||||||
|
|
||||||
Info<< "transfer contents to a List or ICharStream" << nl;
|
Info<< "transfer contents to a List or IListStream" << nl;
|
||||||
|
|
||||||
ICharStream ibuf;
|
IListStream ibuf;
|
||||||
// Reclaim data storage from OCharStream -> ICharStream
|
// Reclaim data storage from OListStream -> IListStream
|
||||||
{
|
{
|
||||||
List<char> data;
|
List<char> data;
|
||||||
obuf.swap(data);
|
obuf.swap(data);
|
||||||
@ -202,7 +169,7 @@ int main(int argc, char *argv[])
|
|||||||
Info<<"input:";
|
Info<<"input:";
|
||||||
toString(Info, list) << endl;
|
toString(Info, list) << endl;
|
||||||
|
|
||||||
OCharStream buf1(std::move(list));
|
OListStream buf1(std::move(list));
|
||||||
|
|
||||||
Info<<"orig:";
|
Info<<"orig:";
|
||||||
toString(Info, list) << endl;
|
toString(Info, list) << endl;
|
||||||
@ -237,7 +204,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
Info<< nl << "Test dictionary" << nl;
|
Info<< nl << "Test dictionary" << nl;
|
||||||
{
|
{
|
||||||
OCharStream os1;
|
OListStream os1;
|
||||||
|
|
||||||
outputDict(os1);
|
outputDict(os1);
|
||||||
|
|
||||||
@ -246,7 +213,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
OCharStream os2;
|
OListStream os2;
|
||||||
os2.indentSize(0);
|
os2.indentSize(0);
|
||||||
|
|
||||||
outputDict(os2);
|
outputDict(os2);
|
||||||
@ -1,3 +0,0 @@
|
|||||||
Test-SpanStream1.C
|
|
||||||
|
|
||||||
EXE = $(FOAM_USER_APPBIN)/Test-SpanStream1
|
|
||||||
@ -5,7 +5,7 @@
|
|||||||
\\ / A nd | www.openfoam.com
|
\\ / A nd | www.openfoam.com
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2019-2023 OpenCFD Ltd.
|
Copyright (C) 2019 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -37,7 +37,6 @@ Description
|
|||||||
#include "scalarField.H"
|
#include "scalarField.H"
|
||||||
#include "SubField.H"
|
#include "SubField.H"
|
||||||
#include "labelRange.H"
|
#include "labelRange.H"
|
||||||
#include "ListOps.H"
|
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
|
|
||||||
using namespace Foam;
|
using namespace Foam;
|
||||||
@ -58,26 +57,26 @@ int main(int argc, char *argv[])
|
|||||||
argList::noFunctionObjects();
|
argList::noFunctionObjects();
|
||||||
|
|
||||||
{
|
{
|
||||||
List<label> ident(25);
|
List<scalar> ident(25);
|
||||||
std::iota(ident.begin(), ident.end(), 0);
|
std::iota(ident.begin(), ident.end(), 0);
|
||||||
|
|
||||||
print(ident);
|
print(ident);
|
||||||
|
|
||||||
SubList<label>(ident, 10) = -10;
|
SubList<scalar>(ident, 10) = -10;
|
||||||
print(ident);
|
print(ident);
|
||||||
|
|
||||||
SubField<label>(ident, 10) = 10;
|
SubField<scalar>(ident, 10) = 10;
|
||||||
print(ident);
|
print(ident);
|
||||||
|
|
||||||
SubField<label>(ident, 10) += 10;
|
SubField<scalar>(ident, 10) += 10;
|
||||||
print(ident);
|
print(ident);
|
||||||
|
|
||||||
SubField<label>{ident, 10, 10} *= 5;
|
SubField<scalar>{ident, 10, 10} *= 5;
|
||||||
print(ident);
|
print(ident);
|
||||||
|
|
||||||
|
|
||||||
// NOTE: Need {} instead of ()
|
// NOTE: Need {} instead of ()
|
||||||
// SubList<label>(ident) = 100;
|
// SubList<scalar>(ident) = 100;
|
||||||
|
|
||||||
// GCC
|
// GCC
|
||||||
// error: conflicting declaration 'Foam::SubList<double> ident'
|
// error: conflicting declaration 'Foam::SubList<double> ident'
|
||||||
@ -86,30 +85,7 @@ int main(int argc, char *argv[])
|
|||||||
// warning: parentheses were disambiguated as redundant parentheses
|
// warning: parentheses were disambiguated as redundant parentheses
|
||||||
// around declaration of variable named 'ident' [-Wvexing-parse]
|
// around declaration of variable named 'ident' [-Wvexing-parse]
|
||||||
|
|
||||||
SubList<label>{ident} = 100;
|
SubList<scalar>{ident} = 100;
|
||||||
print(ident);
|
|
||||||
|
|
||||||
SubList<label> sub(ident);
|
|
||||||
sub = 1;
|
|
||||||
print(sub);
|
|
||||||
|
|
||||||
sub.reset(ident, labelRange(4, 5)) = 5;
|
|
||||||
print(sub);
|
|
||||||
print(ident);
|
|
||||||
|
|
||||||
sub.reset(ident, labelRange(14, 5)) = 15;
|
|
||||||
print(sub);
|
|
||||||
print(ident);
|
|
||||||
|
|
||||||
// Cryptic, probably not a great idea to write this
|
|
||||||
sub.reset(ident, {20, 3}) = -1;
|
|
||||||
print(sub);
|
|
||||||
print(ident);
|
|
||||||
|
|
||||||
// This is also possible since we hold a concrete pointer/size
|
|
||||||
// and not an intermediate
|
|
||||||
ListOps::identity(sub.reset(ident, 8, 8));
|
|
||||||
print(sub);
|
|
||||||
print(ident);
|
print(ident);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
3
applications/test/UIListStream/Make/files
Normal file
3
applications/test/UIListStream/Make/files
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
Test-UIListStream.C
|
||||||
|
|
||||||
|
EXE = $(FOAM_USER_APPBIN)/Test-UIListStream
|
||||||
@ -5,7 +5,7 @@
|
|||||||
\\ / A nd | www.openfoam.com
|
\\ / A nd | www.openfoam.com
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2017-2023 OpenCFD Ltd.
|
Copyright (C) 2017-2018 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -27,48 +27,16 @@ Description
|
|||||||
|
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include "SpanStream.H"
|
#include "UListStream.H"
|
||||||
#include "wordList.H"
|
#include "wordList.H"
|
||||||
#include "IOstreams.H"
|
#include "IOstreams.H"
|
||||||
#include "argList.H"
|
#include "argList.H"
|
||||||
|
|
||||||
#include <cctype>
|
|
||||||
#include <cstdio>
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
using namespace Foam;
|
using namespace Foam;
|
||||||
|
|
||||||
Ostream& writeList(Ostream& os, const UList<char>& list)
|
|
||||||
{
|
|
||||||
char buf[4];
|
|
||||||
os << list.size() << '(';
|
|
||||||
for (const char c : list)
|
|
||||||
{
|
|
||||||
if (isprint(c))
|
|
||||||
{
|
|
||||||
os << c;
|
|
||||||
}
|
|
||||||
else if (c == '\t')
|
|
||||||
{
|
|
||||||
os << "\\t";
|
|
||||||
}
|
|
||||||
else if (c == '\n')
|
|
||||||
{
|
|
||||||
os << "\\n";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
::snprintf(buf, 4, "%02X", c);
|
|
||||||
os << "\\x" << buf;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
os << ')';
|
|
||||||
|
|
||||||
return os;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Ostream& toString(Ostream& os, const UList<char>& list)
|
Ostream& toString(Ostream& os, const UList<char>& list)
|
||||||
{
|
{
|
||||||
os << '"';
|
os << '"';
|
||||||
@ -140,7 +108,7 @@ int main(int argc, char *argv[])
|
|||||||
// Buffer storage
|
// Buffer storage
|
||||||
DynamicList<char> storage(1000);
|
DynamicList<char> storage(1000);
|
||||||
|
|
||||||
OSpanStream obuf(storage);
|
UOListStream obuf(storage);
|
||||||
obuf << 1002 << "\n" << "abcd" << "\n" << "def" << "\n" << 3.14159 << ";\n";
|
obuf << 1002 << "\n" << "abcd" << "\n" << "def" << "\n" << 3.14159 << ";\n";
|
||||||
|
|
||||||
obuf.print(Info);
|
obuf.print(Info);
|
||||||
@ -152,7 +120,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
// Attach input buffer - could also do without previous resize
|
// Attach input buffer - could also do without previous resize
|
||||||
{
|
{
|
||||||
ISpanStream ibuf(storage);
|
UIListStream ibuf(storage);
|
||||||
|
|
||||||
printTokens(ibuf);
|
printTokens(ibuf);
|
||||||
|
|
||||||
@ -167,21 +135,13 @@ int main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
Info<< "parse as std::istream\n";
|
Info<< "parse as std::istream\n";
|
||||||
|
|
||||||
ispanstream is(storage.cdata(), storage.size());
|
uiliststream is(storage.cdata(), storage.size());
|
||||||
|
|
||||||
Info<< "input: ";
|
|
||||||
writeList(Info, is.list()) << endl;
|
|
||||||
|
|
||||||
Info<< "where: " << is.tellg() << endl;
|
|
||||||
Info<< "capacity: " << is.capacity() << endl;
|
|
||||||
Info<< "total: " << is.capacity() << endl;
|
|
||||||
|
|
||||||
string tok;
|
string tok;
|
||||||
|
|
||||||
while (std::getline(is, tok))
|
while (std::getline(is, tok))
|
||||||
{
|
{
|
||||||
std::cerr << "tok: " << tok << nl;
|
std::cerr << "tok: " << tok << nl;
|
||||||
Info<< "where: " << is.tellg() << endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Info<< nl << "Repeat..." << endl;
|
Info<< nl << "Repeat..." << endl;
|
||||||
@ -210,7 +170,7 @@ int main(int argc, char *argv[])
|
|||||||
toString(Info, chars);
|
toString(Info, chars);
|
||||||
Info<< "----" << nl;
|
Info<< "----" << nl;
|
||||||
|
|
||||||
ispanstream is(chars.data(), chars.size());
|
uiliststream is(chars.data(), chars.size());
|
||||||
string tok;
|
string tok;
|
||||||
std::cerr<< nl << "Parsed..." << nl;
|
std::cerr<< nl << "Parsed..." << nl;
|
||||||
while (std::getline(is, tok))
|
while (std::getline(is, tok))
|
||||||
@ -68,51 +68,25 @@ int main(int argc, char *argv[])
|
|||||||
labelRange::debug = 1;
|
labelRange::debug = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Info<< nl;
|
|
||||||
{
|
{
|
||||||
labelRange range(5, 10);
|
labelRange range(5, 10);
|
||||||
Info<< "identity: " << identity(range) << nl;
|
Info<< "identity: " << identity(range) << nl;
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
Info<< "test sorting" << endl;
|
Info<<"test sorting" << endl;
|
||||||
labelRanges list1(10);
|
DynamicList<labelRange> list1(10);
|
||||||
|
|
||||||
list1.emplace_back(25, 8);
|
list1.emplace_back(25, 8);
|
||||||
list1.emplace_back(8);
|
list1.emplace_back(8);
|
||||||
list1.emplace_back(15, 5);
|
list1.emplace_back(15, 5);
|
||||||
list1.emplace_back(50, -10, true);
|
list1.emplace_back(50, -10, true);
|
||||||
|
|
||||||
// Move construct
|
sort(list1);
|
||||||
labelRanges ranges(std::move(list1));
|
Info<<"sorted" << list1 << endl;
|
||||||
if (!list1.empty())
|
|
||||||
{
|
|
||||||
Info<< "Move construct failed? "
|
|
||||||
<< flatOutput(list1.ranges()) << nl;
|
|
||||||
}
|
|
||||||
|
|
||||||
Info<< "unsorted: ";
|
|
||||||
ranges.writeList(Info) << nl;
|
|
||||||
|
|
||||||
ranges.sort();
|
|
||||||
Info<< "sorted: ";
|
|
||||||
ranges.writeList(Info) << nl;
|
|
||||||
|
|
||||||
Info<< nl
|
|
||||||
<< "list linear length = " << ranges.totalSize() << nl;
|
|
||||||
|
|
||||||
Info<< "list labels = ";
|
|
||||||
ranges.labels().writeList(Info) << nl;
|
|
||||||
|
|
||||||
Info<< nl;
|
|
||||||
for (int i : { -1, 0, 5, 8, 10, 20, 26 })
|
|
||||||
{
|
|
||||||
Info<< "value at [" << i << "] = " << ranges[i] << nl;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
Info<< "test intersections" << endl;
|
Info<<"test intersections" << endl;
|
||||||
labelRange range1(-15, 25);
|
labelRange range1(-15, 25);
|
||||||
labelRange range2(7, 8);
|
labelRange range2(7, 8);
|
||||||
labelRange range3(-20, 8);
|
labelRange range3(-20, 8);
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
\\ / A nd | www.openfoam.com
|
\\ / A nd | www.openfoam.com
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2022-2023 OpenCFD Ltd.
|
Copyright (C) 2022 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -75,16 +75,6 @@ void testBroadcast(List<T>& values)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
void testBroadcast(std::vector<T>& values)
|
|
||||||
{
|
|
||||||
Info<< nl << "is_contiguous:" << is_contiguous<T>::value << endl;
|
|
||||||
Pout<< "pre-broadcast: " << flatOutput(values) << endl;
|
|
||||||
Pstream::broadcast(values);
|
|
||||||
Pout<< "post-broadcast: " << flatOutput(values) << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void testBroadcast(bitSet& values)
|
void testBroadcast(bitSet& values)
|
||||||
{
|
{
|
||||||
Pout<< "pre-broadcast: "
|
Pout<< "pre-broadcast: "
|
||||||
@ -145,20 +135,6 @@ int main(int argc, char *argv[])
|
|||||||
testBroadcast(values);
|
testBroadcast(values);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
|
||||||
std::vector<word> values;
|
|
||||||
if (Pstream::master())
|
|
||||||
{
|
|
||||||
values.resize(UPstream::nProcs());
|
|
||||||
|
|
||||||
for (decltype(values.size()) i=0; i < values.size(); ++i)
|
|
||||||
{
|
|
||||||
values[i] = "vector_" + Foam::name(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
testBroadcast(values);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
{
|
||||||
vector values(vector::uniform(-1));
|
vector values(vector::uniform(-1));
|
||||||
if (Pstream::master())
|
if (Pstream::master())
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
\\ / A nd | www.openfoam.com
|
\\ / A nd | www.openfoam.com
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2017-2023 OpenCFD Ltd.
|
Copyright (C) 2017-2022 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -33,7 +33,7 @@ Description
|
|||||||
|
|
||||||
#include "scalar.H"
|
#include "scalar.H"
|
||||||
#include "FlatOutput.H"
|
#include "FlatOutput.H"
|
||||||
#include "SpanStream.H"
|
#include "ListStream.H"
|
||||||
#include "StringStream.H"
|
#include "StringStream.H"
|
||||||
#include "NASCore.H"
|
#include "NASCore.H"
|
||||||
#include "parsing.H"
|
#include "parsing.H"
|
||||||
@ -443,22 +443,22 @@ int main(int argc, char *argv[])
|
|||||||
<< " read " << sizeof(scalar) << nl;
|
<< " read " << sizeof(scalar) << nl;
|
||||||
|
|
||||||
List<otherType> srcList(15);
|
List<otherType> srcList(15);
|
||||||
|
|
||||||
forAll(srcList, i)
|
forAll(srcList, i)
|
||||||
{
|
{
|
||||||
srcList[i] = 1 + 10*i;
|
srcList[i] = 1 + 10*i;
|
||||||
}
|
}
|
||||||
|
|
||||||
OCharStream os(IOstreamOption::BINARY);
|
DynamicList<char> buf;
|
||||||
|
|
||||||
|
OListStream os(std::move(buf), IOstreamOption::BINARY);
|
||||||
os << srcList;
|
os << srcList;
|
||||||
|
|
||||||
DynamicList<char> buf;
|
os.swap(buf); // Recover buffer
|
||||||
os.swap(buf); // Recover written contents
|
|
||||||
|
|
||||||
// Read back
|
// Read back
|
||||||
List<scalar> dstList;
|
List<scalar> dstList;
|
||||||
|
|
||||||
ISpanStream is(buf, IOstreamOption::BINARY);
|
UIListStream is(buf, IOstreamOption::BINARY);
|
||||||
is.setScalarByteSize(sizeof(otherType));
|
is.setScalarByteSize(sizeof(otherType));
|
||||||
|
|
||||||
Info<< "Stream scalar-size ("
|
Info<< "Stream scalar-size ("
|
||||||
|
|||||||
@ -1,3 +0,0 @@
|
|||||||
Test-readBroadcast1.C
|
|
||||||
|
|
||||||
EXE = $(FOAM_USER_APPBIN)/Test-readBroadcast1
|
|
||||||
@ -1,2 +0,0 @@
|
|||||||
/* EXE_INC = */
|
|
||||||
/* EXE_LIBS = */
|
|
||||||
@ -1,297 +0,0 @@
|
|||||||
/*---------------------------------------------------------------------------*\
|
|
||||||
========= |
|
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
|
||||||
\\ / O peration |
|
|
||||||
\\ / A nd | www.openfoam.com
|
|
||||||
\\/ M anipulation |
|
|
||||||
-------------------------------------------------------------------------------
|
|
||||||
Copyright (C) 2023 OpenCFD Ltd.
|
|
||||||
-------------------------------------------------------------------------------
|
|
||||||
License
|
|
||||||
This file is part of OpenFOAM.
|
|
||||||
|
|
||||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
|
||||||
under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
||||||
for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
Description
|
|
||||||
Test file reading with broadcast
|
|
||||||
|
|
||||||
\*---------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
#include "argList.H"
|
|
||||||
#include "OSspecific.H" // For fileSize()
|
|
||||||
#include "Fstream.H"
|
|
||||||
#include "Pstream.H"
|
|
||||||
#include "SpanStream.H"
|
|
||||||
#include <limits>
|
|
||||||
|
|
||||||
using namespace Foam;
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
bool optUseSeek = false;
|
|
||||||
bool optVerbose = false;
|
|
||||||
|
|
||||||
// Get file contents. Usually master-only and broadcast
|
|
||||||
static List<char> slurpFile
|
|
||||||
(
|
|
||||||
const fileName& pathname,
|
|
||||||
const bool parallel = UPstream::parRun(),
|
|
||||||
const bool masterOnly = true
|
|
||||||
)
|
|
||||||
{
|
|
||||||
Info<< "slurp master-only:" << masterOnly
|
|
||||||
<< " broadcast:" << (masterOnly && parallel)
|
|
||||||
<< " seek:" << optUseSeek
|
|
||||||
<< " file: " << pathname << nl;
|
|
||||||
|
|
||||||
if (optUseSeek)
|
|
||||||
{
|
|
||||||
Info<< "Rewinding gzstream does not work..." << nl;
|
|
||||||
}
|
|
||||||
|
|
||||||
// -------------------------
|
|
||||||
|
|
||||||
List<char> buffer;
|
|
||||||
|
|
||||||
ifstreamPointer ifp;
|
|
||||||
|
|
||||||
if (UPstream::master() || !masterOnly)
|
|
||||||
{
|
|
||||||
ifp.open(pathname);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ifp && ifp->good())
|
|
||||||
{
|
|
||||||
Info<< "compressed:"
|
|
||||||
<< (IOstreamOption::COMPRESSED == ifp.whichCompression()) << nl;
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
uint64_t inputSize = Foam::fileSize(pathname);
|
|
||||||
|
|
||||||
if (IOstreamOption::COMPRESSED == ifp.whichCompression())
|
|
||||||
{
|
|
||||||
ifp->ignore(std::numeric_limits<std::streamsize>::max());
|
|
||||||
|
|
||||||
const std::streamsize nread = ifp->gcount();
|
|
||||||
|
|
||||||
if (nread == std::numeric_limits<std::streamsize>::max())
|
|
||||||
{
|
|
||||||
FatalErrorInFunction
|
|
||||||
<< "Failed call to ignore()" << nl
|
|
||||||
<< exit(FatalError);
|
|
||||||
}
|
|
||||||
inputSize = ifp->gcount();
|
|
||||||
|
|
||||||
if (optUseSeek)
|
|
||||||
{
|
|
||||||
// Rewinding gzstream does not really work...
|
|
||||||
ifp->rdbuf()->pubseekpos(0, std::ios_base::in);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Open it again - gzstream rewinding is unreliable...
|
|
||||||
ifp.open(pathname);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
buffer.resize(label(inputSize));
|
|
||||||
ifp->read(buffer.data(), buffer.size_bytes());
|
|
||||||
|
|
||||||
const std::streamsize nread = ifp->gcount();
|
|
||||||
|
|
||||||
if (nread == std::numeric_limits<std::streamsize>::max())
|
|
||||||
{
|
|
||||||
FatalErrorInFunction
|
|
||||||
<< "Failed call to read()" << nl
|
|
||||||
<< exit(FatalError);
|
|
||||||
}
|
|
||||||
|
|
||||||
buffer.resize(label(nread)); // Extra safety (paranoid)
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
if (IOstreamOption::COMPRESSED == ifp.whichCompression())
|
|
||||||
{
|
|
||||||
// For compressed files we do not have any idea how large
|
|
||||||
// the result will be. So read chunk-wise.
|
|
||||||
// Using the compressed size for the chunk size:
|
|
||||||
// 50% compression = 2 iterations
|
|
||||||
// 66% compression = 3 iterations
|
|
||||||
// ...
|
|
||||||
|
|
||||||
const auto inputSize = Foam::fileSize(pathname + ".gz");
|
|
||||||
|
|
||||||
const uint64_t chunkSize =
|
|
||||||
(
|
|
||||||
(inputSize <= 1024)
|
|
||||||
? uint64_t(4096)
|
|
||||||
: uint64_t(2*inputSize)
|
|
||||||
);
|
|
||||||
|
|
||||||
uint64_t beg = 0;
|
|
||||||
|
|
||||||
bool normalExit = false;
|
|
||||||
|
|
||||||
for (int iter = 1; iter < 100000; ++iter)
|
|
||||||
{
|
|
||||||
if (optVerbose)
|
|
||||||
{
|
|
||||||
Info<< "iter " << iter << nl;
|
|
||||||
Info<< "chunk " << label(chunkSize) << nl;
|
|
||||||
Info<< "size " << label(iter * chunkSize) << nl;
|
|
||||||
}
|
|
||||||
|
|
||||||
buffer.resize(label(iter * chunkSize));
|
|
||||||
ifp->read(buffer.data() + beg, chunkSize);
|
|
||||||
|
|
||||||
const std::streamsize nread = ifp->gcount();
|
|
||||||
|
|
||||||
if (optVerbose)
|
|
||||||
{
|
|
||||||
Info<< "nread: " << nread << nl;
|
|
||||||
}
|
|
||||||
|
|
||||||
if
|
|
||||||
(
|
|
||||||
nread < 0
|
|
||||||
|| nread == std::numeric_limits<std::streamsize>::max()
|
|
||||||
)
|
|
||||||
{
|
|
||||||
if (iter == 0)
|
|
||||||
{
|
|
||||||
FatalErrorInFunction
|
|
||||||
<< "Failed call to read()" << nl
|
|
||||||
<< exit(FatalError);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
beg += uint64_t(nread);
|
|
||||||
if (nread >= 0 && uint64_t(nread) < chunkSize)
|
|
||||||
{
|
|
||||||
normalExit = true;
|
|
||||||
if (optVerbose)
|
|
||||||
{
|
|
||||||
Info<< "stopped after "
|
|
||||||
<< iter << " iterations" << nl;
|
|
||||||
}
|
|
||||||
buffer.resize(label(beg));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!normalExit)
|
|
||||||
{
|
|
||||||
FatalErrorInFunction
|
|
||||||
<< "Abnormal exit" << nl
|
|
||||||
<< exit(FatalError);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
const auto inputSize = Foam::fileSize(pathname);
|
|
||||||
|
|
||||||
if (inputSize >= 0)
|
|
||||||
{
|
|
||||||
buffer.resize(label(inputSize));
|
|
||||||
ifp->read(buffer.data(), buffer.size_bytes());
|
|
||||||
|
|
||||||
const std::streamsize nread = ifp->gcount();
|
|
||||||
|
|
||||||
if
|
|
||||||
(
|
|
||||||
nread < 0
|
|
||||||
|| nread == std::numeric_limits<std::streamsize>::max()
|
|
||||||
)
|
|
||||||
{
|
|
||||||
FatalErrorInFunction
|
|
||||||
<< "Failed call to read()" << nl
|
|
||||||
<< exit(FatalError);
|
|
||||||
}
|
|
||||||
|
|
||||||
buffer.resize(label(nread)); // Extra safety (paranoid)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
// Done with input file
|
|
||||||
ifp.reset(nullptr);
|
|
||||||
|
|
||||||
if (parallel && masterOnly)
|
|
||||||
{
|
|
||||||
// On the assumption of larger files,
|
|
||||||
// prefer two broadcasts instead of serialization
|
|
||||||
Pstream::broadcastList(buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
return buffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
||||||
// Main program:
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
|
||||||
{
|
|
||||||
argList::noBanner();
|
|
||||||
argList::noFunctionObjects();
|
|
||||||
argList::noCheckProcessorDirectories();
|
|
||||||
argList::addBoolOption("seek", "seek with gzstream (fails!)");
|
|
||||||
argList::addVerboseOption("addition information");
|
|
||||||
argList::addBoolOption("seek", "seek with gzstream");
|
|
||||||
argList::addBoolOption("no-broadcast", "suppress broadcast contents");
|
|
||||||
|
|
||||||
argList::addNote("Test master-only reading (with broadcast)");
|
|
||||||
|
|
||||||
argList::addArgument("srcFile");
|
|
||||||
|
|
||||||
#include "setRootCase.H"
|
|
||||||
|
|
||||||
const bool syncPar = (UPstream::parRun() && !args.found("no-broadcast"));
|
|
||||||
optUseSeek = args.found("seek");
|
|
||||||
optVerbose = args.verbose();
|
|
||||||
|
|
||||||
auto srcName = args.get<fileName>(1);
|
|
||||||
|
|
||||||
if (srcName.has_ext("gz"))
|
|
||||||
{
|
|
||||||
srcName.remove_ext();
|
|
||||||
Info<< "stripping extraneous .gz ending" << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
ICharStream is;
|
|
||||||
|
|
||||||
{
|
|
||||||
List<char> buffer(slurpFile(srcName, syncPar));
|
|
||||||
|
|
||||||
is.swap(buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
Pout<< "input:" << is.capacity() << endl;
|
|
||||||
|
|
||||||
for (string line; is.getLine(line); /*nil*/)
|
|
||||||
{
|
|
||||||
Pout<< "L:" << is.lineNumber() << ": " << line.c_str() << nl;
|
|
||||||
}
|
|
||||||
|
|
||||||
Info<< "\nEnd\n" << endl;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// ************************************************************************* //
|
|
||||||
@ -51,30 +51,13 @@ int main(int argc, char *argv[])
|
|||||||
hmm.source()[1] = vector(1.0, 4.0, 3.0);
|
hmm.source()[1] = vector(1.0, 4.0, 3.0);
|
||||||
hmm.source()[2] = vector(0.0, 5.0, 2.0);
|
hmm.source()[2] = vector(0.0, 5.0, 2.0);
|
||||||
|
|
||||||
Info<< hmm << nl;
|
Info<< hmm << endl;
|
||||||
Info<< hmm.solve() << nl;
|
Info<< hmm.solve() << endl;
|
||||||
Info<< hmm << nl;
|
Info<< hmm << endl;
|
||||||
Info<< hmm.LUsolve() << nl;
|
Info<< hmm.LUsolve() << endl;
|
||||||
Info<< hmm << nl;
|
Info<< hmm << endl;
|
||||||
|
|
||||||
{
|
Info<< "End\n" << endl;
|
||||||
scalarSquareMatrix mat0;
|
|
||||||
Info<< "empty: " << mat0 << endl;
|
|
||||||
|
|
||||||
mat0.resize_nocopy(1);
|
|
||||||
mat0 = Identity<scalar>();
|
|
||||||
Info<< "ident (1x1): " << mat0 << endl;
|
|
||||||
|
|
||||||
mat0.resize_nocopy(3);
|
|
||||||
mat0 = Identity<scalar>();
|
|
||||||
Info<< "ident (3x3): " << mat0 << endl;
|
|
||||||
|
|
||||||
mat0.resize_nocopy(5);
|
|
||||||
mat0 = Identity<scalar>();
|
|
||||||
Info<< "ident (5x5): " << mat0 << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
Info<< "\nEnd\n" << endl;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -429,7 +429,7 @@ unset cmd
|
|||||||
|
|
||||||
case "$WM_MPLIB" in
|
case "$WM_MPLIB" in
|
||||||
*OPENMPI*)
|
*OPENMPI*)
|
||||||
cmd="mpirun --oversubscribe -app $PWD/mpirun.schema </dev/null"
|
cmd="mpirun -app $PWD/mpirun.schema </dev/null"
|
||||||
;;
|
;;
|
||||||
MPICH)
|
MPICH)
|
||||||
cmd="mpiexec"
|
cmd="mpiexec"
|
||||||
|
|||||||
@ -304,21 +304,16 @@ runApplication()
|
|||||||
#
|
#
|
||||||
runParallel()
|
runParallel()
|
||||||
{
|
{
|
||||||
local appName appRun optValue logFile logMode
|
local appName appRun optValue logFile logMode nProcs
|
||||||
local mpiopts nProcs
|
|
||||||
|
|
||||||
# Any additional parsed arguments (eg, decomposeParDict)
|
# Any additional parsed arguments (eg, decomposeParDict)
|
||||||
local appArgs="-parallel"
|
local appArgs="-parallel"
|
||||||
|
|
||||||
local mpirun="mpirun"
|
local mpirun="mpirun"
|
||||||
case "$FOAM_MPI" in
|
if [ "$FOAM_MPI" = msmpi ]
|
||||||
(msmpi*)
|
then
|
||||||
mpirun="mpiexec"
|
mpirun="mpiexec"
|
||||||
;;
|
fi
|
||||||
(*openmpi*)
|
|
||||||
mpiopts="--oversubscribe"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
# Parse options until executable is encountered
|
# Parse options until executable is encountered
|
||||||
while [ "$#" -gt 0 ] && [ -z "$appRun" ]
|
while [ "$#" -gt 0 ] && [ -z "$appRun" ]
|
||||||
@ -383,11 +378,11 @@ runParallel()
|
|||||||
if [ "$logMode" = append ]
|
if [ "$logMode" = append ]
|
||||||
then
|
then
|
||||||
(
|
(
|
||||||
"$mpirun" $mpiopts -n "${nProcs:?}" $appRun $appArgs "$@" </dev/null >> $logFile 2>&1
|
$mpirun -n $nProcs $appRun $appArgs "$@" </dev/null >> $logFile 2>&1
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
(
|
(
|
||||||
"$mpirun" $mpiopts -n "${nProcs:?}" $appRun $appArgs "$@" </dev/null > $logFile 2>&1
|
$mpirun -n $nProcs $appRun $appArgs "$@" </dev/null > $logFile 2>&1
|
||||||
)
|
)
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|||||||
@ -225,8 +225,6 @@ castellatedMeshControls
|
|||||||
//cellZone sphere;
|
//cellZone sphere;
|
||||||
//cellZoneInside inside; // outside/insidePoint
|
//cellZoneInside inside; // outside/insidePoint
|
||||||
//insidePoint (1 1 1); // if (cellZoneInside == insidePoint)
|
//insidePoint (1 1 1); // if (cellZoneInside == insidePoint)
|
||||||
// or alternative multiple insidePoints:
|
|
||||||
//insidePoints ((1 1 1)); // if (cellZoneInside == insidePoint)
|
|
||||||
|
|
||||||
//- Optional specification of what to do with faceZone faces:
|
//- Optional specification of what to do with faceZone faces:
|
||||||
// internal : keep them as internal faces (default)
|
// internal : keep them as internal faces (default)
|
||||||
|
|||||||
@ -5,6 +5,7 @@ global/globals.C
|
|||||||
/* global/JobInfo/JobInfo.C in globals.C */
|
/* global/JobInfo/JobInfo.C in globals.C */
|
||||||
global/argList/argList.C
|
global/argList/argList.C
|
||||||
global/argList/argListHelp.C
|
global/argList/argListHelp.C
|
||||||
|
global/argList/argListRedirect.C
|
||||||
global/clock/clock.C
|
global/clock/clock.C
|
||||||
global/clockValue/clockValue.C
|
global/clockValue/clockValue.C
|
||||||
global/cpuTime/cpuTimeCxx.C
|
global/cpuTime/cpuTimeCxx.C
|
||||||
@ -271,7 +272,7 @@ gzstream = $(Streams)/gzstream
|
|||||||
$(gzstream)/gzstream.C
|
$(gzstream)/gzstream.C
|
||||||
|
|
||||||
memstream = $(Streams)/memory
|
memstream = $(Streams)/memory
|
||||||
$(memstream)/SpanStreams.C
|
$(memstream)/ListStream.C
|
||||||
|
|
||||||
Fstreams = $(Streams)/Fstreams
|
Fstreams = $(Streams)/Fstreams
|
||||||
$(Fstreams)/IFstream.C
|
$(Fstreams)/IFstream.C
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
\\ / A nd | www.openfoam.com
|
\\ / A nd | www.openfoam.com
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2018-2023 OpenCFD Ltd.
|
Copyright (C) 2018-2019 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -102,51 +102,48 @@ bool Foam::PackedList<Width>::uniform() const
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// The value of the first element for testing
|
// The value of the first element for testing
|
||||||
const unsigned int val = get(0);
|
const unsigned int val = get(0);
|
||||||
|
|
||||||
|
const label nblocks = num_blocks(size());
|
||||||
|
|
||||||
bool identical = true;
|
bool identical = true;
|
||||||
|
|
||||||
if (!val)
|
if (!val)
|
||||||
{
|
{
|
||||||
// No bits set: just check there are no non-zero blocks
|
// Zero value: can just check block content directly
|
||||||
// - like bitSet::none()
|
|
||||||
identical = (-1 == first_block());
|
|
||||||
}
|
|
||||||
else if (val == PackedList<Width>::max_value)
|
|
||||||
{
|
|
||||||
// All bits set: just check there are no zero blocks
|
|
||||||
// - like bitSet::all()
|
|
||||||
identical = (-1 == first_not_block());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
const label nblocks = num_blocks(size());
|
|
||||||
|
|
||||||
if (nblocks > 1)
|
for (label blocki = 0; identical && blocki < nblocks; ++blocki)
|
||||||
{
|
{
|
||||||
// Fill value for complete blocks
|
identical = !blocks_[blocki];
|
||||||
const unsigned int blockval = repeated_value(val);
|
|
||||||
|
|
||||||
// Check each complete block (nblocks-1)
|
|
||||||
for (label blocki = 0; identical && blocki < (nblocks-1); ++blocki)
|
|
||||||
{
|
|
||||||
identical = (blocks_[blocki] == blockval);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Partial block: check manually
|
return identical;
|
||||||
for
|
}
|
||||||
(
|
else if (nblocks > 1)
|
||||||
label elemi = elem_per_block*(nblocks-1);
|
{
|
||||||
identical && elemi < size();
|
// Fill value for complete blocks
|
||||||
++elemi
|
const unsigned int blockval = repeated_value(val);
|
||||||
)
|
|
||||||
|
// Check each complete block (nblocks-1)
|
||||||
|
for (label blocki = 0; identical && blocki < (nblocks-1); ++blocki)
|
||||||
{
|
{
|
||||||
identical = (val == get(elemi));
|
identical = (blocks_[blocki] == blockval);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Partial block: check manually
|
||||||
|
for
|
||||||
|
(
|
||||||
|
label elemi = elem_per_block*(nblocks-1);
|
||||||
|
identical && elemi < size();
|
||||||
|
++elemi
|
||||||
|
)
|
||||||
|
{
|
||||||
|
identical = (val == get(elemi));
|
||||||
|
}
|
||||||
|
|
||||||
return identical;
|
return identical;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,20 +194,16 @@ Foam::PackedList<Width>::unpack() const
|
|||||||
"Width of IntType is too small to hold result"
|
"Width of IntType is too small to hold result"
|
||||||
);
|
);
|
||||||
|
|
||||||
List<IntType> output(size());
|
|
||||||
|
|
||||||
if (empty())
|
if (empty())
|
||||||
{
|
{
|
||||||
return output;
|
return List<IntType>(0);
|
||||||
}
|
}
|
||||||
else if (uniform())
|
else if (uniform())
|
||||||
{
|
{
|
||||||
output = static_cast<IntType>(get(0));
|
return List<IntType>(size(), static_cast<IntType>(get(0)));
|
||||||
return output;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NON-UNIFORM and len > 0
|
List<IntType> output(size());
|
||||||
|
|
||||||
label outi = 0;
|
label outi = 0;
|
||||||
|
|
||||||
// Process n-1 complete blocks
|
// Process n-1 complete blocks
|
||||||
@ -222,7 +215,7 @@ Foam::PackedList<Width>::unpack() const
|
|||||||
|
|
||||||
for (unsigned nget = elem_per_block; nget; --nget, ++outi)
|
for (unsigned nget = elem_per_block; nget; --nget, ++outi)
|
||||||
{
|
{
|
||||||
output[outi] = IntType(blockval & PackedList<Width>::max_value);
|
output[outi] = IntType(blockval & max_value);
|
||||||
blockval >>= Width;
|
blockval >>= Width;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -221,14 +221,6 @@ protected:
|
|||||||
//- Copy assignment
|
//- Copy assignment
|
||||||
inline void copyAssign(const PackedList<Width>& rhs);
|
inline void copyAssign(const PackedList<Width>& rhs);
|
||||||
|
|
||||||
//- Find the first block with a '1' bit
|
|
||||||
// \return block number or -1 for an list or if all bits are OFF.
|
|
||||||
inline label first_block() const;
|
|
||||||
|
|
||||||
//- Find the first block with a '0' bit
|
|
||||||
// \return block number or -1 for an list or if all bits are ON.
|
|
||||||
inline label first_not_block() const;
|
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -300,7 +292,7 @@ public:
|
|||||||
//- Number of elements that can be stored without reallocating
|
//- Number of elements that can be stored without reallocating
|
||||||
inline label capacity() const noexcept;
|
inline label capacity() const noexcept;
|
||||||
|
|
||||||
//- True if all entries have identical values (and list is non-empty)
|
//- True if all entries have identical values, and list is non-empty
|
||||||
bool uniform() const;
|
bool uniform() const;
|
||||||
|
|
||||||
//- Test for equality of sizes and the bits set
|
//- Test for equality of sizes and the bits set
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
Copyright (C) 2017-2023 OpenCFD Ltd.
|
Copyright (C) 2017-2021 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -147,73 +147,6 @@ inline void Foam::PackedList<Width>::copyAssign(const PackedList<Width>& rhs)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<unsigned Width>
|
|
||||||
inline Foam::label Foam::PackedList<Width>::first_block() const
|
|
||||||
{
|
|
||||||
if (size())
|
|
||||||
{
|
|
||||||
const label nblocks = num_blocks(size());
|
|
||||||
|
|
||||||
for (label blocki=0; blocki < nblocks; ++blocki)
|
|
||||||
{
|
|
||||||
if (blocks_[blocki])
|
|
||||||
{
|
|
||||||
return blocki;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<unsigned Width>
|
|
||||||
inline Foam::label Foam::PackedList<Width>::first_not_block() const
|
|
||||||
{
|
|
||||||
if (!size())
|
|
||||||
{
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check on complement (changes 0 <-> 1).
|
|
||||||
// If any 1's now appear, there was a 0 bit before
|
|
||||||
|
|
||||||
const label nblocks = num_blocks(size());
|
|
||||||
|
|
||||||
// Extra bits in the final block?
|
|
||||||
const unsigned int off = size() % elem_per_block;
|
|
||||||
|
|
||||||
if (!off)
|
|
||||||
{
|
|
||||||
for (label blocki=0; blocki < nblocks; ++blocki)
|
|
||||||
{
|
|
||||||
if (~(blocks_[blocki]))
|
|
||||||
{
|
|
||||||
return blocki;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
for (label blocki=0; blocki < nblocks-1; ++blocki)
|
|
||||||
{
|
|
||||||
if (~(blocks_[blocki]))
|
|
||||||
{
|
|
||||||
return blocki;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// The final block needs masking
|
|
||||||
if (~(blocks_[nblocks-1]) & mask_lower(off))
|
|
||||||
{
|
|
||||||
return nblocks-1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Specializations * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Specializations * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
namespace Foam
|
namespace Foam
|
||||||
|
|||||||
@ -18,8 +18,8 @@ Description
|
|||||||
|
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#ifndef FoamCompat_PackedBoolList_H
|
#ifndef PackedBoolList_H
|
||||||
#define FoamCompat_PackedBoolList_H
|
#define PackedBoolList_H
|
||||||
|
|
||||||
#include "bitSet.H"
|
#include "bitSet.H"
|
||||||
|
|
||||||
|
|||||||
@ -65,6 +65,13 @@ class bitSet
|
|||||||
:
|
:
|
||||||
public PackedList<1>
|
public PackedList<1>
|
||||||
{
|
{
|
||||||
|
// Private Member Functions
|
||||||
|
|
||||||
|
//- Find the first block with a '0' bit
|
||||||
|
// \return block number or -1 if the set is empty or all bits are on.
|
||||||
|
inline label first_not_block() const;
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
// Logic/Set Operations
|
// Logic/Set Operations
|
||||||
@ -131,7 +138,7 @@ public:
|
|||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
//- Default construct an empty, zero-sized bitSet
|
//- Default construct an empty, zero-sized bitSet
|
||||||
inline constexpr bitSet() noexcept;
|
inline bitSet() noexcept;
|
||||||
|
|
||||||
//- Construct from Istream
|
//- Construct from Istream
|
||||||
explicit bitSet(Istream& is);
|
explicit bitSet(Istream& is);
|
||||||
@ -239,6 +246,9 @@ public:
|
|||||||
// \note Method name compatibility with boost::dynamic_bitset
|
// \note Method name compatibility with boost::dynamic_bitset
|
||||||
inline bool none() const;
|
inline bool none() const;
|
||||||
|
|
||||||
|
//- True if all entries have identical values, and the set is non-empty
|
||||||
|
inline bool uniform() const;
|
||||||
|
|
||||||
//- Count number of bits set.
|
//- Count number of bits set.
|
||||||
// \param on can be set to false to count the number of unset bits
|
// \param on can be set to false to count the number of unset bits
|
||||||
// instead.
|
// instead.
|
||||||
|
|||||||
@ -25,9 +25,56 @@ License
|
|||||||
|
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||||
|
|
||||||
|
inline Foam::label Foam::bitSet::first_not_block() const
|
||||||
|
{
|
||||||
|
if (empty())
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use complement to change 0 <-> 1 and check if any 1's now appear
|
||||||
|
|
||||||
|
const label nblocks = num_blocks(size());
|
||||||
|
|
||||||
|
// Extra bits in the final block?
|
||||||
|
const unsigned int off = size() % elem_per_block;
|
||||||
|
|
||||||
|
if (!off)
|
||||||
|
{
|
||||||
|
for (label blocki=0; blocki < nblocks; ++blocki)
|
||||||
|
{
|
||||||
|
if (~(blocks_[blocki]))
|
||||||
|
{
|
||||||
|
return blocki;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (label blocki=0; blocki < nblocks-1; ++blocki)
|
||||||
|
{
|
||||||
|
if (~(blocks_[blocki]))
|
||||||
|
{
|
||||||
|
return blocki;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// The final block needs masking
|
||||||
|
if (~(blocks_[nblocks-1]) & mask_lower(off))
|
||||||
|
{
|
||||||
|
return nblocks-1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
inline constexpr Foam::bitSet::bitSet() noexcept
|
inline Foam::bitSet::bitSet() noexcept
|
||||||
:
|
:
|
||||||
PackedList<1>()
|
PackedList<1>()
|
||||||
{}
|
{}
|
||||||
@ -266,14 +313,14 @@ inline Foam::bitSet::const_iterator Foam::bitSet::cend() const noexcept
|
|||||||
|
|
||||||
inline Foam::label Foam::bitSet::find_first() const
|
inline Foam::label Foam::bitSet::find_first() const
|
||||||
{
|
{
|
||||||
const label blocki = first_block();
|
// Process block-wise, detecting any '1' bits
|
||||||
|
|
||||||
if (blocki >= 0)
|
const label nblocks = num_blocks(size());
|
||||||
|
|
||||||
|
for (label blocki = 0; blocki < nblocks; ++blocki)
|
||||||
{
|
{
|
||||||
label pos = (blocki * elem_per_block);
|
label pos = (blocki * elem_per_block);
|
||||||
|
|
||||||
// Detect first '1' bit within the block
|
|
||||||
|
|
||||||
for
|
for
|
||||||
(
|
(
|
||||||
unsigned int blockval = blocks_[blocki];
|
unsigned int blockval = blocks_[blocki];
|
||||||
@ -301,7 +348,7 @@ inline Foam::label Foam::bitSet::find_first_not() const
|
|||||||
{
|
{
|
||||||
label pos = (blocki * elem_per_block);
|
label pos = (blocki * elem_per_block);
|
||||||
|
|
||||||
// Detect first '0' bit within the block (check the complement)
|
// Detect first '0' bit by checking the complement.
|
||||||
|
|
||||||
// No special masking for the final block, that was already checked
|
// No special masking for the final block, that was already checked
|
||||||
// in the first_not_block() call.
|
// in the first_not_block() call.
|
||||||
@ -414,19 +461,39 @@ inline const Foam::bitSet& Foam::bitSet::null()
|
|||||||
inline bool Foam::bitSet::all() const
|
inline bool Foam::bitSet::all() const
|
||||||
{
|
{
|
||||||
if (empty()) return true; // SIC. boost convention
|
if (empty()) return true; // SIC. boost convention
|
||||||
return (-1 == first_not_block());
|
|
||||||
|
return -1 == first_not_block();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline bool Foam::bitSet::any() const
|
inline bool Foam::bitSet::any() const
|
||||||
{
|
{
|
||||||
return (-1 != first_block());
|
if (size())
|
||||||
|
{
|
||||||
|
const label nblocks = num_blocks(size());
|
||||||
|
|
||||||
|
for (label blocki=0; blocki < nblocks; ++blocki)
|
||||||
|
{
|
||||||
|
if (blocks_[blocki])
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline bool Foam::bitSet::none() const
|
inline bool Foam::bitSet::none() const
|
||||||
{
|
{
|
||||||
return (-1 == first_block());
|
return !any();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline bool Foam::bitSet::uniform() const
|
||||||
|
{
|
||||||
|
return (size() == 1 || (size() > 1 && (test(0) ? all() : none())));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -108,8 +108,6 @@ const Foam::SubList<T> Foam::CircularBuffer<T>::array_two() const
|
|||||||
template<class T>
|
template<class T>
|
||||||
Foam::label Foam::CircularBuffer<T>::find(const T& val, label pos) const
|
Foam::label Foam::CircularBuffer<T>::find(const T& val, label pos) const
|
||||||
{
|
{
|
||||||
if (pos < 0) return -1; // no-op
|
|
||||||
|
|
||||||
label i = -1;
|
label i = -1;
|
||||||
|
|
||||||
const auto list1 = this->array_one();
|
const auto list1 = this->array_one();
|
||||||
|
|||||||
@ -282,21 +282,18 @@ public:
|
|||||||
|
|
||||||
// Search
|
// Search
|
||||||
|
|
||||||
//- True if the value is contained in the list.
|
|
||||||
inline bool contains(const T& val) const;
|
|
||||||
|
|
||||||
//- Is the value contained in the list?
|
|
||||||
// \param val The value to search for
|
|
||||||
// \param pos The first position to examine (no-op if -ve)
|
|
||||||
// \return true if found.
|
|
||||||
inline bool contains(const T& val, label pos) const;
|
|
||||||
|
|
||||||
//- Find index of the first occurrence of the value.
|
//- Find index of the first occurrence of the value.
|
||||||
// Any occurrences before the start pos are ignored.
|
// Any occurrences before the start pos are ignored.
|
||||||
// Linear search.
|
// Linear search.
|
||||||
// \return position in list or -1 if not found.
|
// \return position in list or -1 if not found.
|
||||||
label find(const T& val, label pos = 0) const;
|
label find(const T& val, label pos = 0) const;
|
||||||
|
|
||||||
|
//- Is the value contained in the list?
|
||||||
|
// Linear search from start pos until the end of the list.
|
||||||
|
// Any occurrences before the start pos are ignored.
|
||||||
|
// \return true if found.
|
||||||
|
inline bool contains(const T& val, label pos = 0) const;
|
||||||
|
|
||||||
|
|
||||||
// Stack-like Operations
|
// Stack-like Operations
|
||||||
|
|
||||||
|
|||||||
@ -255,13 +255,6 @@ inline void Foam::CircularBuffer<T>::reserve_nocopy(const label len)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
bool Foam::CircularBuffer<T>::contains(const T& val) const
|
|
||||||
{
|
|
||||||
return (this->array_one().contains(val) || this->array_two().contains(val));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
inline bool Foam::CircularBuffer<T>::contains(const T& val, label pos) const
|
inline bool Foam::CircularBuffer<T>::contains(const T& val, label pos) const
|
||||||
{
|
{
|
||||||
|
|||||||
@ -499,12 +499,8 @@ bool Foam::HashTable<T, Key, Hash>::erase(const iterator& iter)
|
|||||||
template<class T, class Key, class Hash>
|
template<class T, class Key, class Hash>
|
||||||
bool Foam::HashTable<T, Key, Hash>::erase(const Key& key)
|
bool Foam::HashTable<T, Key, Hash>::erase(const Key& key)
|
||||||
{
|
{
|
||||||
if (size_)
|
iterator iter(find(key));
|
||||||
{
|
return iterator_erase(iter);
|
||||||
iterator iter(find(key));
|
|
||||||
if (iter.good()) return iterator_erase(iter);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -31,21 +31,13 @@ template<class T, class Addr>
|
|||||||
Foam::label Foam::IndirectListBase<T, Addr>::find
|
Foam::label Foam::IndirectListBase<T, Addr>::find
|
||||||
(
|
(
|
||||||
const T& val,
|
const T& val,
|
||||||
label pos,
|
label pos
|
||||||
label len
|
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
if (pos >= 0 && pos < addr_.size())
|
const label len = addr_.size();
|
||||||
|
|
||||||
|
if (pos >= 0 && len)
|
||||||
{
|
{
|
||||||
// Change sub-length to (one-past) end position
|
|
||||||
// len == -1 (like std::string::npos) - search until end
|
|
||||||
|
|
||||||
if (len > 0) len += pos;
|
|
||||||
if (len < 0 || len > addr_.size())
|
|
||||||
{
|
|
||||||
len = addr_.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
const T* const vals = values_.begin();
|
const T* const vals = values_.begin();
|
||||||
|
|
||||||
while (pos < len)
|
while (pos < len)
|
||||||
@ -70,7 +62,7 @@ Foam::label Foam::IndirectListBase<T, Addr>::rfind
|
|||||||
label pos
|
label pos
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
// pos == -1 (like std::string::npos) - search from end
|
// pos == -1 has same meaning as std::string::npos - search from end
|
||||||
|
|
||||||
if (pos < 0 || pos >= addr_.size())
|
if (pos < 0 || pos >= addr_.size())
|
||||||
{
|
{
|
||||||
|
|||||||
@ -179,19 +179,11 @@ public:
|
|||||||
|
|
||||||
// Search
|
// Search
|
||||||
|
|
||||||
//- Is the value contained in the list?
|
|
||||||
// \param val The value to search for
|
|
||||||
// \param pos The first position to examine (default: 0, no-op if -ve)
|
|
||||||
// \param len The length of the search region (-ve until the end)
|
|
||||||
// \return true if found.
|
|
||||||
inline bool contains(const T& val, label pos = 0, label len = -1) const;
|
|
||||||
|
|
||||||
//- Find index of the first occurrence of the value.
|
//- Find index of the first occurrence of the value.
|
||||||
// \param val The value to search for
|
// Any occurrences before the start pos are ignored.
|
||||||
// \param pos The first position to examine (default: 0, no-op if -ve)
|
// Linear search.
|
||||||
// \param len The length of the search region (-ve until the end)
|
// \return -1 if not found.
|
||||||
// \return position in list or -1 if not found.
|
label find(const T& val, label pos = 0) const;
|
||||||
label find(const T& val, label pos = 0, label len = -1) const;
|
|
||||||
|
|
||||||
//- Find index of the last occurrence of the value.
|
//- Find index of the last occurrence of the value.
|
||||||
// Any occurrences after the end pos are ignored.
|
// Any occurrences after the end pos are ignored.
|
||||||
@ -199,6 +191,12 @@ public:
|
|||||||
// \return -1 if not found.
|
// \return -1 if not found.
|
||||||
label rfind(const T& val, label pos = -1) const;
|
label rfind(const T& val, label pos = -1) const;
|
||||||
|
|
||||||
|
//- Is the value contained in the list?
|
||||||
|
// Linear search from start pos until the end of the list.
|
||||||
|
// Any occurrences before the start pos are ignored.
|
||||||
|
// \return true if found.
|
||||||
|
inline bool contains(const T& val, label pos = 0) const;
|
||||||
|
|
||||||
|
|
||||||
// Member Operators
|
// Member Operators
|
||||||
|
|
||||||
|
|||||||
@ -102,11 +102,10 @@ template<class T, class Addr>
|
|||||||
inline bool Foam::IndirectListBase<T, Addr>::contains
|
inline bool Foam::IndirectListBase<T, Addr>::contains
|
||||||
(
|
(
|
||||||
const T& val,
|
const T& val,
|
||||||
label pos,
|
label pos
|
||||||
label len
|
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
return (this->find(val, pos, len) >= 0);
|
return (this->find(val, pos) >= 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -222,27 +222,6 @@ Foam::Istream& Foam::DynamicList<T, SizeMin>::readList(Istream& is)
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (std::is_same<char, T>::value)
|
|
||||||
{
|
|
||||||
// Special treatment for char data (always binary and contiguous)
|
|
||||||
// (see List<char>::readList)
|
|
||||||
|
|
||||||
if (len)
|
|
||||||
{
|
|
||||||
const auto oldFmt = is.format(IOstreamOption::BINARY);
|
|
||||||
|
|
||||||
// read(...) includes surrounding start/end delimiters
|
|
||||||
is.read(list.data_bytes(), list.size_bytes());
|
|
||||||
|
|
||||||
is.format(oldFmt);
|
|
||||||
|
|
||||||
is.fatalCheck
|
|
||||||
(
|
|
||||||
"DynamicList<char>::readList(Istream&) : "
|
|
||||||
"reading binary block"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Begin of contents marker
|
// Begin of contents marker
|
||||||
|
|||||||
@ -46,42 +46,24 @@ std::streamsize Foam::FixedList<T, N>::byteSize()
|
|||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
template<class T, unsigned N>
|
template<class T, unsigned N>
|
||||||
Foam::label Foam::FixedList<T, N>::find(const T& val) const
|
Foam::label Foam::FixedList<T, N>::find(const T& val, label pos) const
|
||||||
{
|
{
|
||||||
const auto iter = std::find(this->cbegin(), this->cend(), val);
|
if (pos >= 0)
|
||||||
return (iter != this->cend() ? label(iter - this->cbegin()) : label(-1));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<class T, unsigned N>
|
|
||||||
Foam::label Foam::FixedList<T, N>::find
|
|
||||||
(
|
|
||||||
const T& val,
|
|
||||||
label pos,
|
|
||||||
label len
|
|
||||||
) const
|
|
||||||
{
|
|
||||||
if (pos >= 0 && pos < label(N))
|
|
||||||
{
|
{
|
||||||
// Change sub-length to (one-past) end position
|
// auto iter = std::find(this->begin(pos), this->end(), val);
|
||||||
// len == -1 (like std::string::npos) - search until end
|
// if (iter != this->end())
|
||||||
|
// {
|
||||||
|
// return label(iter - this->begin());
|
||||||
|
// }
|
||||||
|
|
||||||
if (len > 0) len += pos;
|
while (pos < label(N))
|
||||||
if (len < 0 || len > label(N))
|
|
||||||
{
|
{
|
||||||
len = label(N);
|
if (this->v_[pos] == val)
|
||||||
}
|
{
|
||||||
|
return pos;
|
||||||
|
}
|
||||||
|
|
||||||
const auto iter = std::find
|
++pos;
|
||||||
(
|
|
||||||
(this->cbegin() + pos),
|
|
||||||
(this->cbegin() + len),
|
|
||||||
val
|
|
||||||
);
|
|
||||||
|
|
||||||
if (iter != (this->cbegin() + len))
|
|
||||||
{
|
|
||||||
return label(iter - this->cbegin());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,8 +74,7 @@ Foam::label Foam::FixedList<T, N>::find
|
|||||||
template<class T, unsigned N>
|
template<class T, unsigned N>
|
||||||
Foam::label Foam::FixedList<T, N>::rfind(const T& val, label pos) const
|
Foam::label Foam::FixedList<T, N>::rfind(const T& val, label pos) const
|
||||||
{
|
{
|
||||||
// pos == -1 (like std::string::npos) - search from end
|
// pos == -1 has same meaning as std::string::npos - search from end
|
||||||
|
|
||||||
if (pos < 0 || pos >= label(N))
|
if (pos < 0 || pos >= label(N))
|
||||||
{
|
{
|
||||||
pos = label(N)-1;
|
pos = label(N)-1;
|
||||||
|
|||||||
@ -275,27 +275,11 @@ public:
|
|||||||
|
|
||||||
// Search
|
// Search
|
||||||
|
|
||||||
//- True if the value is contained in the list.
|
|
||||||
inline bool contains(const T& val) const;
|
|
||||||
|
|
||||||
//- Is the value contained in the list?
|
|
||||||
// \param val The value to search for
|
|
||||||
// \param pos The first position to examine (no-op if -ve)
|
|
||||||
// \param len The length of the search region (-ve until the end)
|
|
||||||
// \return true if found.
|
|
||||||
inline bool contains(const T& val, label pos, label len = -1) const;
|
|
||||||
|
|
||||||
//- Find index of the first occurrence of the value.
|
//- Find index of the first occurrence of the value.
|
||||||
// \param val The value to search for
|
// Any occurrences before the start pos are ignored.
|
||||||
// \return position in list or -1 if not found.
|
// Linear search.
|
||||||
label find(const T& val) const;
|
// \return -1 if not found.
|
||||||
|
label find(const T& val, label pos = 0) const;
|
||||||
//- Find index of the first occurrence of the value.
|
|
||||||
// \param val The value to search for
|
|
||||||
// \param pos The first position to examine (no-op if -ve)
|
|
||||||
// \param len The length of the search region (-ve until the end)
|
|
||||||
// \return position in list or -1 if not found.
|
|
||||||
label find(const T& val, label pos, label len = -1) const;
|
|
||||||
|
|
||||||
//- Find index of the last occurrence of the value.
|
//- Find index of the last occurrence of the value.
|
||||||
// Any occurrences after the end pos are ignored.
|
// Any occurrences after the end pos are ignored.
|
||||||
@ -303,6 +287,12 @@ public:
|
|||||||
// \return position in list or -1 if not found.
|
// \return position in list or -1 if not found.
|
||||||
label rfind(const T& val, label pos = -1) const;
|
label rfind(const T& val, label pos = -1) const;
|
||||||
|
|
||||||
|
//- Is the value contained in the list?
|
||||||
|
// Linear search from start pos until the end of the list.
|
||||||
|
// Any occurrences before the start pos are ignored.
|
||||||
|
// \return true if found.
|
||||||
|
inline bool contains(const T& val, label pos = 0) const;
|
||||||
|
|
||||||
|
|
||||||
// Edit
|
// Edit
|
||||||
|
|
||||||
|
|||||||
@ -307,22 +307,9 @@ inline bool Foam::FixedList<T, N>::uniform() const
|
|||||||
|
|
||||||
|
|
||||||
template<class T, unsigned N>
|
template<class T, unsigned N>
|
||||||
inline bool Foam::FixedList<T, N>::contains(const T& val) const
|
inline bool Foam::FixedList<T, N>::contains(const T& val, label pos) const
|
||||||
{
|
{
|
||||||
const auto iter = std::find(this->cbegin(), this->cend(), val);
|
return (this->find(val, pos) >= 0);
|
||||||
return (iter != this->cend());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<class T, unsigned N>
|
|
||||||
inline bool Foam::FixedList<T, N>::contains
|
|
||||||
(
|
|
||||||
const T& val,
|
|
||||||
label pos,
|
|
||||||
label len
|
|
||||||
) const
|
|
||||||
{
|
|
||||||
return (this->find(val, pos, len) >= 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
Copyright (C) 2017-2023 OpenCFD Ltd.
|
Copyright (C) 2017-2021 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -89,10 +89,7 @@ public:
|
|||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
//- Construct from UList, the entire size
|
//- Construct from UList, the entire size
|
||||||
inline explicit SubList(const UList<T>& list) noexcept;
|
inline explicit SubList(const UList<T>& list);
|
||||||
|
|
||||||
//- Construct from std::vector, the entire size
|
|
||||||
inline explicit SubList(const std::vector<T>& list) noexcept;
|
|
||||||
|
|
||||||
//- Construct from FixedList, the entire size
|
//- Construct from FixedList, the entire size
|
||||||
template<unsigned N>
|
template<unsigned N>
|
||||||
@ -131,47 +128,6 @@ public:
|
|||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
// Member Functions
|
|
||||||
|
|
||||||
//- Reset to zero-sized and nullptr
|
|
||||||
inline UList<T>& reset(std::nullptr_t) noexcept;
|
|
||||||
|
|
||||||
//- Reset to use entire UList
|
|
||||||
inline UList<T>& reset(const UList<T>& list) noexcept;
|
|
||||||
|
|
||||||
//- Reset to use UList with sub-list size, start at 0
|
|
||||||
inline UList<T>& reset
|
|
||||||
(
|
|
||||||
const UList<T>& list,
|
|
||||||
const label subSize
|
|
||||||
);
|
|
||||||
|
|
||||||
//- Reset to use UList with sub-list size and start index
|
|
||||||
inline UList<T>& reset
|
|
||||||
(
|
|
||||||
const UList<T>& list,
|
|
||||||
const label subSize,
|
|
||||||
const label startIndex
|
|
||||||
);
|
|
||||||
|
|
||||||
//- Reset to use UList with a (start,size) range.
|
|
||||||
// The range is subsetted with the list size itself to ensure that the
|
|
||||||
// result always addresses a valid section of the list.
|
|
||||||
inline UList<T>& reset
|
|
||||||
(
|
|
||||||
const UList<T>& list,
|
|
||||||
const labelRange& range
|
|
||||||
);
|
|
||||||
|
|
||||||
//- Reset to use UList with a (start,size) range, but bypassing
|
|
||||||
//- run-time range checking.
|
|
||||||
inline UList<T>& reset
|
|
||||||
(
|
|
||||||
const labelRange& range,
|
|
||||||
const UList<T>& list
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
// Member Operators
|
// Member Operators
|
||||||
|
|
||||||
//- Allow cast to a const List\<T\>&
|
//- Allow cast to a const List\<T\>&
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
Copyright (C) 2017-2023 OpenCFD Ltd.
|
Copyright (C) 2017-2021 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -28,37 +28,18 @@ License
|
|||||||
|
|
||||||
#include "FixedList.H"
|
#include "FixedList.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
inline const Foam::SubList<T>& Foam::SubList<T>::null()
|
|
||||||
{
|
|
||||||
return NullObjectRef<SubList<T>>();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
inline Foam::SubList<T>::SubList
|
inline Foam::SubList<T>::SubList
|
||||||
(
|
(
|
||||||
const UList<T>& list
|
const UList<T>& list
|
||||||
) noexcept
|
)
|
||||||
:
|
:
|
||||||
UList<T>(const_cast<T*>(list.cdata()), list.size())
|
UList<T>(const_cast<T*>(list.cdata()), list.size())
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
inline Foam::SubList<T>::SubList
|
|
||||||
(
|
|
||||||
const std::vector<T>& list
|
|
||||||
) noexcept
|
|
||||||
:
|
|
||||||
UList<T>(const_cast<T*>(list.data()), label(list.size()))
|
|
||||||
{}
|
|
||||||
|
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
template<unsigned N>
|
template<unsigned N>
|
||||||
inline Foam::SubList<T>::SubList
|
inline Foam::SubList<T>::SubList
|
||||||
@ -132,102 +113,9 @@ inline Foam::SubList<T>::SubList
|
|||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
inline Foam::UList<T>& Foam::SubList<T>::reset(std::nullptr_t) noexcept
|
inline const Foam::SubList<T>& Foam::SubList<T>::null()
|
||||||
{
|
{
|
||||||
UList<T>::shallowCopy(nullptr, 0);
|
return NullObjectRef<SubList<T>>();
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
inline Foam::UList<T>& Foam::SubList<T>::reset
|
|
||||||
(
|
|
||||||
const UList<T>& list
|
|
||||||
) noexcept
|
|
||||||
{
|
|
||||||
UList<T>::shallowCopy(list);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
inline Foam::UList<T>& Foam::SubList<T>::reset
|
|
||||||
(
|
|
||||||
const UList<T>& list,
|
|
||||||
const label subSize
|
|
||||||
)
|
|
||||||
{
|
|
||||||
#ifdef FULLDEBUG
|
|
||||||
list.checkSize(subSize);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
UList<T>::shallowCopy(const_cast<T*>(list.cdata()), subSize);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
inline Foam::UList<T>& Foam::SubList<T>::reset
|
|
||||||
(
|
|
||||||
const UList<T>& list,
|
|
||||||
const label subSize,
|
|
||||||
const label startIndex
|
|
||||||
)
|
|
||||||
{
|
|
||||||
#ifdef FULLDEBUG
|
|
||||||
list.checkRange(startIndex, subSize);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
UList<T>::shallowCopy
|
|
||||||
(
|
|
||||||
const_cast<T*>(list.cdata() + startIndex),
|
|
||||||
subSize
|
|
||||||
);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
inline Foam::UList<T>& Foam::SubList<T>::reset
|
|
||||||
(
|
|
||||||
const UList<T>& list,
|
|
||||||
const labelRange& range
|
|
||||||
)
|
|
||||||
{
|
|
||||||
#ifdef FULLDEBUG
|
|
||||||
// subset0() always produces valid ranges but want to check
|
|
||||||
// that the input itself was valid
|
|
||||||
list.checkRange(range.start(), range.size());
|
|
||||||
#endif
|
|
||||||
|
|
||||||
labelRange clamped(range.subset0(list.size()));
|
|
||||||
|
|
||||||
UList<T>::shallowCopy
|
|
||||||
(
|
|
||||||
const_cast<T*>(list.cdata() + clamped.start()),
|
|
||||||
clamped.size()
|
|
||||||
);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
inline Foam::UList<T>& Foam::SubList<T>::reset
|
|
||||||
(
|
|
||||||
const labelRange& range,
|
|
||||||
const UList<T>& list
|
|
||||||
)
|
|
||||||
{
|
|
||||||
#ifdef FULLDEBUG
|
|
||||||
list.checkRange(range.start(), range.size());
|
|
||||||
#endif
|
|
||||||
|
|
||||||
UList<T>::shallowCopy
|
|
||||||
(
|
|
||||||
const_cast<T*>(list.cdata() + range.start()),
|
|
||||||
range.size()
|
|
||||||
);
|
|
||||||
return *this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -177,37 +177,26 @@ std::streamsize Foam::UList<T>::byteSize() const
|
|||||||
|
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
Foam::label Foam::UList<T>::find(const T& val) const
|
Foam::label Foam::UList<T>::find(const T& val, label pos) const
|
||||||
{
|
{
|
||||||
const auto iter = std::find(this->cbegin(), this->cend(), val);
|
const label len = this->size();
|
||||||
return (iter != this->cend() ? label(iter - this->cbegin()) : label(-1));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (pos >= 0)
|
||||||
template<class T>
|
|
||||||
Foam::label Foam::UList<T>::find(const T& val, label pos, label len) const
|
|
||||||
{
|
|
||||||
if (pos >= 0 && pos < this->size())
|
|
||||||
{
|
{
|
||||||
// Change sub-length to (one-past) end position
|
// auto iter = std::find(this->begin(pos), this->end(), val);
|
||||||
// len == -1 (like std::string::npos) - search until end
|
// if (iter != this->end())
|
||||||
|
// {
|
||||||
|
// return label(iter - this->begin());
|
||||||
|
// }
|
||||||
|
|
||||||
if (len > 0) len += pos;
|
while (pos < len)
|
||||||
if (len < 0 || len > this->size())
|
|
||||||
{
|
{
|
||||||
len = this->size();
|
if (this->v_[pos] == val)
|
||||||
}
|
{
|
||||||
|
return pos;
|
||||||
|
}
|
||||||
|
|
||||||
const auto iter = std::find
|
++pos;
|
||||||
(
|
|
||||||
(this->cbegin() + pos),
|
|
||||||
(this->cbegin() + len),
|
|
||||||
val
|
|
||||||
);
|
|
||||||
|
|
||||||
if (iter != (this->cbegin() + len))
|
|
||||||
{
|
|
||||||
return label(iter - this->cbegin());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -218,8 +207,7 @@ Foam::label Foam::UList<T>::find(const T& val, label pos, label len) const
|
|||||||
template<class T>
|
template<class T>
|
||||||
Foam::label Foam::UList<T>::rfind(const T& val, label pos) const
|
Foam::label Foam::UList<T>::rfind(const T& val, label pos) const
|
||||||
{
|
{
|
||||||
// pos == -1 (like std::string::npos) - search from end
|
// pos == -1 has same meaning as std::string::npos - search from end
|
||||||
|
|
||||||
if (pos < 0 || pos >= this->size())
|
if (pos < 0 || pos >= this->size())
|
||||||
{
|
{
|
||||||
pos = this->size()-1;
|
pos = this->size()-1;
|
||||||
|
|||||||
@ -318,27 +318,11 @@ public:
|
|||||||
|
|
||||||
// Search
|
// Search
|
||||||
|
|
||||||
//- True if the value is contained in the list.
|
|
||||||
inline bool contains(const T& val) const;
|
|
||||||
|
|
||||||
//- Is the value contained in the list?
|
|
||||||
// \param val The value to search for
|
|
||||||
// \param pos The first position to examine (no-op if -ve)
|
|
||||||
// \param len The length of the search region (-ve until the end)
|
|
||||||
// \return true if found.
|
|
||||||
inline bool contains(const T& val, label pos, label len = -1) const;
|
|
||||||
|
|
||||||
//- Find index of the first occurrence of the value.
|
//- Find index of the first occurrence of the value.
|
||||||
// \param val The value to search for
|
// Any occurrences before the start pos are ignored.
|
||||||
|
// Linear search.
|
||||||
// \return position in list or -1 if not found.
|
// \return position in list or -1 if not found.
|
||||||
label find(const T& val) const;
|
label find(const T& val, label pos = 0) const;
|
||||||
|
|
||||||
//- Find index of the first occurrence of the value.
|
|
||||||
// \param val The value to search for
|
|
||||||
// \param pos The first position to examine (no-op if -ve)
|
|
||||||
// \param len The length of the search region (-ve until the end)
|
|
||||||
// \return position in list or -1 if not found.
|
|
||||||
label find(const T& val, label pos, label len = -1) const;
|
|
||||||
|
|
||||||
//- Find index of the last occurrence of the value.
|
//- Find index of the last occurrence of the value.
|
||||||
// Any occurrences after the end pos are ignored.
|
// Any occurrences after the end pos are ignored.
|
||||||
@ -346,6 +330,12 @@ public:
|
|||||||
// \return position in list or -1 if not found.
|
// \return position in list or -1 if not found.
|
||||||
label rfind(const T& val, label pos = -1) const;
|
label rfind(const T& val, label pos = -1) const;
|
||||||
|
|
||||||
|
//- Is the value contained in the list?
|
||||||
|
// Linear search from start pos until the end of the list.
|
||||||
|
// Any occurrences before the start pos are ignored.
|
||||||
|
// \return true if found.
|
||||||
|
inline bool contains(const T& val, label pos = 0) const;
|
||||||
|
|
||||||
|
|
||||||
// Edit
|
// Edit
|
||||||
|
|
||||||
@ -364,9 +354,6 @@ public:
|
|||||||
|
|
||||||
// Copy
|
// Copy
|
||||||
|
|
||||||
//- Copy the pointer and size
|
|
||||||
inline void shallowCopy(T* __restrict__ ptr, const label len) noexcept;
|
|
||||||
|
|
||||||
//- Copy the pointer and size held by the given UList
|
//- Copy the pointer and size held by the given UList
|
||||||
inline void shallowCopy(const UList<T>& list) noexcept;
|
inline void shallowCopy(const UList<T>& list) noexcept;
|
||||||
|
|
||||||
@ -676,11 +663,7 @@ Ostream& operator<<(Ostream& os, const UList<T>& list)
|
|||||||
return list.writeList(os, Detail::ListPolicy::short_length<T>::value);
|
return list.writeList(os, Detail::ListPolicy::short_length<T>::value);
|
||||||
}
|
}
|
||||||
|
|
||||||
//- Read std::vector contents from Istream
|
//- Write std::vector to Ostream. ASCII only, no line-breaks
|
||||||
template<class T>
|
|
||||||
Istream& operator>>(Istream& is, std::vector<T>& list);
|
|
||||||
|
|
||||||
//- Write std::vector to Ostream (via UList)
|
|
||||||
template<class T>
|
template<class T>
|
||||||
Ostream& operator<<(Ostream& os, const std::vector<T>& list);
|
Ostream& operator<<(Ostream& os, const std::vector<T>& list);
|
||||||
|
|
||||||
|
|||||||
@ -304,29 +304,9 @@ inline std::streamsize Foam::UList<T>::size_bytes() const noexcept
|
|||||||
|
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
inline bool Foam::UList<T>::contains(const T& val) const
|
inline bool Foam::UList<T>::contains(const T& val, label pos) const
|
||||||
{
|
{
|
||||||
const auto iter = std::find(this->begin(), this->end(), val);
|
return (this->find(val, pos) >= 0);
|
||||||
return (iter != this->end());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
inline bool Foam::UList<T>::contains(const T& val, label pos, label len) const
|
|
||||||
{
|
|
||||||
return (this->find(val, pos, len) >= 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
inline void Foam::UList<T>::shallowCopy
|
|
||||||
(
|
|
||||||
T* __restrict__ ptr,
|
|
||||||
const label len
|
|
||||||
) noexcept
|
|
||||||
{
|
|
||||||
size_ = len;
|
|
||||||
v_ = ptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -187,7 +187,10 @@ Foam::Istream& Foam::UList<T>::readList(Istream& is)
|
|||||||
<< exit(FatalIOError);
|
<< exit(FatalIOError);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::move(elems.begin(), elems.end(), list.begin());
|
for (label i = 0; i < len; ++i)
|
||||||
|
{
|
||||||
|
list[i] = std::move(elems[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (tok.isLabel())
|
else if (tok.isLabel())
|
||||||
{
|
{
|
||||||
|
|||||||
@ -26,183 +26,35 @@ License
|
|||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include "UList.H"
|
#include "UList.H"
|
||||||
#include "Istream.H"
|
|
||||||
#include "Ostream.H"
|
#include "Ostream.H"
|
||||||
#include "contiguous.H"
|
|
||||||
#include "token.H"
|
#include "token.H"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
|
||||||
|
|
||||||
template<class T>
|
|
||||||
Foam::Istream& Foam::operator>>(Istream& is, std::vector<T>& list)
|
|
||||||
{
|
|
||||||
is.fatalCheck(FUNCTION_NAME);
|
|
||||||
|
|
||||||
token tok(is);
|
|
||||||
|
|
||||||
is.fatalCheck("Istream >> std::vector<T> : reading first token");
|
|
||||||
|
|
||||||
if (tok.isCompound())
|
|
||||||
{
|
|
||||||
// No compound handling ...
|
|
||||||
|
|
||||||
list.clear(); // Clear old contents
|
|
||||||
FatalIOErrorInFunction(is)
|
|
||||||
<< "Support for compoundToken - not implemented" << nl
|
|
||||||
<< exit(FatalIOError);
|
|
||||||
}
|
|
||||||
else if (tok.isLabel())
|
|
||||||
{
|
|
||||||
// Label: could be int(..), int{...} or just a plain '0'
|
|
||||||
|
|
||||||
const label len = tok.labelToken();
|
|
||||||
|
|
||||||
// Resize to length required
|
|
||||||
list.resize(len);
|
|
||||||
|
|
||||||
if (is.format() == IOstreamOption::BINARY && is_contiguous<T>::value)
|
|
||||||
{
|
|
||||||
// Binary and contiguous
|
|
||||||
|
|
||||||
if (len)
|
|
||||||
{
|
|
||||||
Detail::readContiguous<T>
|
|
||||||
(
|
|
||||||
is,
|
|
||||||
reinterpret_cast<char*>(list.data()), // data_bytes()
|
|
||||||
std::streamsize(list.size())*sizeof(T) // size_bytes()
|
|
||||||
);
|
|
||||||
|
|
||||||
is.fatalCheck
|
|
||||||
(
|
|
||||||
"Istream >> std::vector<T> : "
|
|
||||||
"reading binary block"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (std::is_same<char, T>::value)
|
|
||||||
{
|
|
||||||
// Special treatment for char data (binary I/O only)
|
|
||||||
const auto oldFmt = is.format(IOstreamOption::BINARY);
|
|
||||||
|
|
||||||
if (len)
|
|
||||||
{
|
|
||||||
// read(...) includes surrounding start/end delimiters
|
|
||||||
is.read
|
|
||||||
(
|
|
||||||
reinterpret_cast<char*>(list.data()), // data_bytes()
|
|
||||||
std::streamsize(list.size())*sizeof(T) // size_bytes()
|
|
||||||
);
|
|
||||||
|
|
||||||
is.fatalCheck
|
|
||||||
(
|
|
||||||
"Istream >> std::vector<char> : "
|
|
||||||
"reading binary block"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
is.format(oldFmt);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Begin of contents marker
|
|
||||||
const char delimiter = is.readBeginList("List");
|
|
||||||
|
|
||||||
if (len)
|
|
||||||
{
|
|
||||||
if (delimiter == token::BEGIN_LIST)
|
|
||||||
{
|
|
||||||
auto iter = list.begin();
|
|
||||||
const auto last = list.end();
|
|
||||||
|
|
||||||
// Contents
|
|
||||||
for (/*nil*/; (iter != last); (void)++iter)
|
|
||||||
{
|
|
||||||
is >> *iter;
|
|
||||||
|
|
||||||
is.fatalCheck
|
|
||||||
(
|
|
||||||
"Istream >> std::vector<char> : "
|
|
||||||
"reading entry"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Uniform content (delimiter == token::BEGIN_BLOCK)
|
|
||||||
|
|
||||||
T elem;
|
|
||||||
is >> elem;
|
|
||||||
|
|
||||||
is.fatalCheck
|
|
||||||
(
|
|
||||||
"Istream >> std::vector<char> : "
|
|
||||||
"reading the single entry"
|
|
||||||
);
|
|
||||||
|
|
||||||
// Fill with the value
|
|
||||||
list.assign(list.size(), elem);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// End of contents marker
|
|
||||||
is.readEndList("List");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (tok.isPunctuation(token::BEGIN_LIST))
|
|
||||||
{
|
|
||||||
// "(...)" : read as bracketed list
|
|
||||||
|
|
||||||
// Slightly sub-optimal since it has intermediate resizing,
|
|
||||||
// however don't expect this as input very often.
|
|
||||||
|
|
||||||
list.clear(); // Clear addressing, leave storage intact (probably)
|
|
||||||
|
|
||||||
is >> tok;
|
|
||||||
is.fatalCheck(FUNCTION_NAME);
|
|
||||||
|
|
||||||
while (!tok.isPunctuation(token::END_LIST))
|
|
||||||
{
|
|
||||||
is.putBack(tok);
|
|
||||||
|
|
||||||
// C++17
|
|
||||||
// is >> list.emplace_back();
|
|
||||||
|
|
||||||
// C++11
|
|
||||||
list.emplace_back();
|
|
||||||
is >> list.back();
|
|
||||||
|
|
||||||
is.fatalCheck
|
|
||||||
(
|
|
||||||
"Istream >> std::vector<char> : "
|
|
||||||
"reading entry"
|
|
||||||
);
|
|
||||||
|
|
||||||
is >> tok;
|
|
||||||
is.fatalCheck(FUNCTION_NAME);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
list.clear(); // Clear old contents
|
|
||||||
|
|
||||||
FatalIOErrorInFunction(is)
|
|
||||||
<< "incorrect first token, expected <int> or '(', found "
|
|
||||||
<< tok.info() << nl
|
|
||||||
<< exit(FatalIOError);
|
|
||||||
}
|
|
||||||
|
|
||||||
return is;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
Foam::Ostream& Foam::operator<<(Ostream& os, const std::vector<T>& list)
|
Foam::Ostream& Foam::operator<<(Ostream& os, const std::vector<T>& list)
|
||||||
{
|
{
|
||||||
// Use UList for output
|
auto iter = list.cbegin();
|
||||||
UList<T> proxy(const_cast<T*>(list.data()), label(list.size()));
|
const auto last = list.cend();
|
||||||
os << proxy;
|
|
||||||
|
// Write ascii list contents, no line breaks
|
||||||
|
|
||||||
|
os << label(list.size()) << token::BEGIN_LIST;
|
||||||
|
|
||||||
|
if (iter != last)
|
||||||
|
{
|
||||||
|
os << *iter;
|
||||||
|
|
||||||
|
while (++iter != last)
|
||||||
|
{
|
||||||
|
os << token::SPACE << *iter;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
os << token::END_LIST;
|
||||||
|
|
||||||
|
os.check(FUNCTION_NAME);
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
\\ / A nd | www.openfoam.com
|
\\ / A nd | www.openfoam.com
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2019-2023 OpenCFD Ltd.
|
Copyright (C) 2019 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -88,41 +88,6 @@ template<> struct no_linebreak<word> : std::true_type {};
|
|||||||
template<> struct no_linebreak<wordRe> : std::true_type {};
|
template<> struct no_linebreak<wordRe> : std::true_type {};
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
//- Classification of list/container uniformity.
|
|
||||||
//- The values can be used with bit-wise \c or reduction
|
|
||||||
enum uniformity : unsigned char
|
|
||||||
{
|
|
||||||
EMPTY = 0, //!< An empty container
|
|
||||||
UNIFORM = 0x1, //!< Container (non-empty) with identical values
|
|
||||||
NONUNIFORM = 0x2, //!< Container (non-empty) with different values
|
|
||||||
MIXED = 0x3 //!< Mixed uniform/non-uniform (eg, after reduction)
|
|
||||||
};
|
|
||||||
|
|
||||||
//- Algorithm to determine list/container uniformity
|
|
||||||
template<class InputIt>
|
|
||||||
enum uniformity check_uniformity(InputIt first, InputIt last)
|
|
||||||
{
|
|
||||||
if (first == last) return uniformity::EMPTY;
|
|
||||||
|
|
||||||
// Like std::all_of() with checking against element 0,
|
|
||||||
// but without using a lambda with auto type (pre C++14) etc.
|
|
||||||
|
|
||||||
const auto& elem0 = *first;
|
|
||||||
|
|
||||||
for ((void)++first; (first != last); (void)++first)
|
|
||||||
{
|
|
||||||
if (elem0 != *first)
|
|
||||||
{
|
|
||||||
return uniformity::NONUNIFORM;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return uniformity::UNIFORM;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
} // End namespace ListPolicy
|
} // End namespace ListPolicy
|
||||||
|
|||||||
@ -37,7 +37,7 @@ License
|
|||||||
#include "charList.H"
|
#include "charList.H"
|
||||||
#include "labelPair.H"
|
#include "labelPair.H"
|
||||||
#include "masterUncollatedFileOperation.H"
|
#include "masterUncollatedFileOperation.H"
|
||||||
#include "SpanStream.H"
|
#include "ListStream.H"
|
||||||
#include "StringStream.H"
|
#include "StringStream.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||||
@ -403,7 +403,7 @@ Foam::decomposedBlockData::readBlock
|
|||||||
|
|
||||||
if (blocki == 0)
|
if (blocki == 0)
|
||||||
{
|
{
|
||||||
realIsPtr.reset(new ICharStream(std::move(data)));
|
realIsPtr.reset(new IListStream(std::move(data)));
|
||||||
realIsPtr->name() = is.name();
|
realIsPtr->name() = is.name();
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -422,7 +422,7 @@ Foam::decomposedBlockData::readBlock
|
|||||||
{
|
{
|
||||||
{
|
{
|
||||||
// Read header from first block
|
// Read header from first block
|
||||||
ISpanStream headerStream(data);
|
UIListStream headerStream(data);
|
||||||
if (!headerIO.readHeader(headerStream))
|
if (!headerIO.readHeader(headerStream))
|
||||||
{
|
{
|
||||||
FatalIOErrorInFunction(headerStream)
|
FatalIOErrorInFunction(headerStream)
|
||||||
@ -440,7 +440,7 @@ Foam::decomposedBlockData::readBlock
|
|||||||
// Read and discard data, only retain the last one
|
// Read and discard data, only retain the last one
|
||||||
decomposedBlockData::readBlockEntry(is, data);
|
decomposedBlockData::readBlockEntry(is, data);
|
||||||
}
|
}
|
||||||
realIsPtr.reset(new ICharStream(std::move(data)));
|
realIsPtr.reset(new IListStream(std::move(data)));
|
||||||
realIsPtr->name() = is.name();
|
realIsPtr->name() = is.name();
|
||||||
|
|
||||||
// Apply stream settings
|
// Apply stream settings
|
||||||
@ -585,7 +585,7 @@ Foam::autoPtr<Foam::ISstream> Foam::decomposedBlockData::readBlocks
|
|||||||
// Read master data
|
// Read master data
|
||||||
decomposedBlockData::readBlockEntry(is, data);
|
decomposedBlockData::readBlockEntry(is, data);
|
||||||
|
|
||||||
realIsPtr.reset(new ICharStream(std::move(data)));
|
realIsPtr.reset(new IListStream(std::move(data)));
|
||||||
realIsPtr->name() = fName;
|
realIsPtr->name() = fName;
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -639,7 +639,7 @@ Foam::autoPtr<Foam::ISstream> Foam::decomposedBlockData::readBlocks
|
|||||||
);
|
);
|
||||||
is >> data;
|
is >> data;
|
||||||
|
|
||||||
realIsPtr.reset(new ICharStream(std::move(data)));
|
realIsPtr.reset(new IListStream(std::move(data)));
|
||||||
realIsPtr->name() = fName;
|
realIsPtr->name() = fName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -673,7 +673,7 @@ Foam::autoPtr<Foam::ISstream> Foam::decomposedBlockData::readBlocks
|
|||||||
UIPstream is(UPstream::masterNo(), pBufs);
|
UIPstream is(UPstream::masterNo(), pBufs);
|
||||||
is >> data;
|
is >> data;
|
||||||
|
|
||||||
realIsPtr.reset(new ICharStream(std::move(data)));
|
realIsPtr.reset(new IListStream(std::move(data)));
|
||||||
realIsPtr->name() = fName;
|
realIsPtr->name() = fName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1090,7 +1090,7 @@ bool Foam::decomposedBlockData::writeData(Ostream& os) const
|
|||||||
// Re-read my own data to find out the header information
|
// Re-read my own data to find out the header information
|
||||||
if (Pstream::master(comm_))
|
if (Pstream::master(comm_))
|
||||||
{
|
{
|
||||||
ISpanStream headerStream(contentData_);
|
UIListStream headerStream(contentData_);
|
||||||
io.readHeader(headerStream);
|
io.readHeader(headerStream);
|
||||||
|
|
||||||
verValue = headerStream.version().canonical();
|
verValue = headerStream.version().canonical();
|
||||||
|
|||||||
@ -29,7 +29,7 @@ License
|
|||||||
#include "dictionary.H"
|
#include "dictionary.H"
|
||||||
#include "foamVersion.H"
|
#include "foamVersion.H"
|
||||||
#include "objectRegistry.H"
|
#include "objectRegistry.H"
|
||||||
#include "SpanStream.H"
|
#include "ListStream.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
@ -125,7 +125,7 @@ bool Foam::decomposedBlockData::readHeader(IOobject& io, Istream& is)
|
|||||||
List<char> charData;
|
List<char> charData;
|
||||||
decomposedBlockData::readBlockEntry(is, charData);
|
decomposedBlockData::readBlockEntry(is, charData);
|
||||||
|
|
||||||
ISpanStream headerStream(charData);
|
UIListStream headerStream(charData);
|
||||||
headerStream.name() = is.name();
|
headerStream.name() = is.name();
|
||||||
|
|
||||||
ok = io.readHeader(headerStream);
|
ok = io.readHeader(headerStream);
|
||||||
|
|||||||
@ -27,7 +27,7 @@ License
|
|||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include "IFstream.H"
|
#include "IFstream.H"
|
||||||
#include "OSspecific.H" // For isFile(), fileSize()
|
#include "OSspecific.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||||
|
|
||||||
@ -91,45 +91,6 @@ Foam::IFstream::IFstream
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
std::streamsize Foam::IFstream::fileSize() const
|
|
||||||
{
|
|
||||||
const std::istream* ptr = ifstreamPointer::get();
|
|
||||||
|
|
||||||
if (!ptr || this->name().empty())
|
|
||||||
{
|
|
||||||
return std::streamsize(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
off_t fileLen = -1;
|
|
||||||
|
|
||||||
if (IOstreamOption::COMPRESSED == ifstreamPointer::whichCompression())
|
|
||||||
{
|
|
||||||
fileLen = Foam::fileSize(this->name() + ".gz");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// TBD: special handing for wrapped icharstream
|
|
||||||
// if
|
|
||||||
// (
|
|
||||||
// const Foam::icharstream* charstr
|
|
||||||
// = dynamic_cast<const Foam::icharstream*>(ptr)>(ptr)
|
|
||||||
// )
|
|
||||||
// {
|
|
||||||
// return charstr->capacity();
|
|
||||||
// }
|
|
||||||
|
|
||||||
fileLen = Foam::fileSize(this->name());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fileLen >= 0)
|
|
||||||
{
|
|
||||||
return std::streamsize(fileLen);
|
|
||||||
}
|
|
||||||
|
|
||||||
return std::streamsize(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
std::istream& Foam::IFstream::stdStream()
|
std::istream& Foam::IFstream::stdStream()
|
||||||
{
|
{
|
||||||
std::istream* ptr = ifstreamPointer::get();
|
std::istream* ptr = ifstreamPointer::get();
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2011 OpenFOAM Foundation
|
Copyright (C) 2011 OpenFOAM Foundation
|
||||||
Copyright (C) 2017-2023 OpenCFD Ltd.
|
Copyright (C) 2017-2021 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -94,13 +94,6 @@ public:
|
|||||||
//- Read/write access to the name of the stream
|
//- Read/write access to the name of the stream
|
||||||
using ISstream::name;
|
using ISstream::name;
|
||||||
|
|
||||||
//- Return the size of the underlying file (-1 on error).
|
|
||||||
//- This corresponds to Foam::fileSize() but with extra handling of
|
|
||||||
//- compressed files.
|
|
||||||
// The return type is \c std::streamsize instead of \c off_t.
|
|
||||||
// \note Use sparingly since it involves a file stat()!
|
|
||||||
std::streamsize fileSize() const;
|
|
||||||
|
|
||||||
|
|
||||||
// STL stream
|
// STL stream
|
||||||
|
|
||||||
|
|||||||
@ -35,6 +35,27 @@ License
|
|||||||
Foam::fileName Foam::IOstream::staticName_("stream");
|
Foam::fileName Foam::IOstream::staticName_("stream");
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
||||||
|
|
||||||
|
void Foam::IOstream::attach(const std::ios& s)
|
||||||
|
{
|
||||||
|
labelByteSize_ = sizeof(label);
|
||||||
|
scalarByteSize_ = sizeof(scalar);
|
||||||
|
lineNumber_ = 0;
|
||||||
|
|
||||||
|
if (s.good())
|
||||||
|
{
|
||||||
|
setOpened();
|
||||||
|
setGood();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
setClosed();
|
||||||
|
setState(s.rdstate());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
const Foam::fileName& Foam::IOstream::name() const
|
const Foam::fileName& Foam::IOstream::name() const
|
||||||
|
|||||||
@ -157,6 +157,9 @@ protected:
|
|||||||
ioState_ = std::ios_base::goodbit;
|
ioState_ = std::ios_base::goodbit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//- Adjustments when attaching a new stream
|
||||||
|
void attach(const std::ios& s);
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|||||||
@ -723,7 +723,7 @@ Foam::Istream& Foam::ISstream::read(token& t)
|
|||||||
// readScalar determine the validity
|
// readScalar determine the validity
|
||||||
while
|
while
|
||||||
(
|
(
|
||||||
is_.get(c)
|
is_->get(c)
|
||||||
&& (
|
&& (
|
||||||
isdigit(c)
|
isdigit(c)
|
||||||
|| c == '+'
|
|| c == '+'
|
||||||
@ -758,13 +758,13 @@ Foam::Istream& Foam::ISstream::read(token& t)
|
|||||||
|
|
||||||
syncState();
|
syncState();
|
||||||
|
|
||||||
if (is_.bad())
|
if (is_->bad())
|
||||||
{
|
{
|
||||||
t.setBad();
|
t.setBad();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
is_.putback(c);
|
is_->putback(c);
|
||||||
|
|
||||||
if (nChar == 1 && buf[0] == '-')
|
if (nChar == 1 && buf[0] == '-')
|
||||||
{
|
{
|
||||||
@ -1009,7 +1009,7 @@ Foam::Istream& Foam::ISstream::read(string& str)
|
|||||||
|
|
||||||
Foam::Istream& Foam::ISstream::read(label& val)
|
Foam::Istream& Foam::ISstream::read(label& val)
|
||||||
{
|
{
|
||||||
is_ >> val;
|
(*is_) >> val;
|
||||||
syncState();
|
syncState();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@ -1017,7 +1017,7 @@ Foam::Istream& Foam::ISstream::read(label& val)
|
|||||||
|
|
||||||
Foam::Istream& Foam::ISstream::read(float& val)
|
Foam::Istream& Foam::ISstream::read(float& val)
|
||||||
{
|
{
|
||||||
is_ >> val;
|
(*is_) >> val;
|
||||||
syncState();
|
syncState();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@ -1025,7 +1025,7 @@ Foam::Istream& Foam::ISstream::read(float& val)
|
|||||||
|
|
||||||
Foam::Istream& Foam::ISstream::read(double& val)
|
Foam::Istream& Foam::ISstream::read(double& val)
|
||||||
{
|
{
|
||||||
is_ >> val;
|
(*is_) >> val;
|
||||||
syncState();
|
syncState();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@ -1047,11 +1047,11 @@ Foam::Istream& Foam::ISstream::readRaw(char* data, std::streamsize count)
|
|||||||
{
|
{
|
||||||
if (data)
|
if (data)
|
||||||
{
|
{
|
||||||
is_.read(data, count);
|
is_->read(data, count);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
is_.ignore(count);
|
is_->ignore(count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
syncState();
|
syncState();
|
||||||
@ -1070,7 +1070,7 @@ bool Foam::ISstream::beginRawRead()
|
|||||||
|
|
||||||
readBegin("binaryBlock");
|
readBegin("binaryBlock");
|
||||||
syncState();
|
syncState();
|
||||||
return is_.good();
|
return is_->good();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1078,7 +1078,7 @@ bool Foam::ISstream::endRawRead()
|
|||||||
{
|
{
|
||||||
readEnd("binaryBlock");
|
readEnd("binaryBlock");
|
||||||
syncState();
|
syncState();
|
||||||
return is_.good();
|
return is_->good();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1089,11 +1089,8 @@ void Foam::ISstream::rewind()
|
|||||||
stdStream().clear(); // Clear the iostate error state flags
|
stdStream().clear(); // Clear the iostate error state flags
|
||||||
setGood(); // Sync local copy of iostate
|
setGood(); // Sync local copy of iostate
|
||||||
|
|
||||||
|
// pubseekpos() rather than seekg() so that it works with gzstream
|
||||||
stdStream().rdbuf()->pubseekpos(0, std::ios_base::in);
|
stdStream().rdbuf()->pubseekpos(0, std::ios_base::in);
|
||||||
|
|
||||||
// NOTE: this form of rewind does not work with igzstream.
|
|
||||||
// However, igzstream is usually wrapped as IFstream which has its
|
|
||||||
// own dedicated rewind treatment for igzstream.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -61,7 +61,7 @@ class ISstream
|
|||||||
|
|
||||||
fileName name_;
|
fileName name_;
|
||||||
|
|
||||||
std::istream& is_;
|
std::istream* is_;
|
||||||
|
|
||||||
|
|
||||||
// Private Member Functions
|
// Private Member Functions
|
||||||
@ -135,10 +135,10 @@ public:
|
|||||||
// STL stream
|
// STL stream
|
||||||
|
|
||||||
//- Const access to underlying std::istream
|
//- Const access to underlying std::istream
|
||||||
virtual const std::istream& stdStream() const { return is_; }
|
virtual const std::istream& stdStream() const { return *is_; }
|
||||||
|
|
||||||
//- Access to underlying std::istream
|
//- Access to underlying std::istream
|
||||||
virtual std::istream& stdStream() { return is_; }
|
virtual std::istream& stdStream() { return *is_; }
|
||||||
|
|
||||||
|
|
||||||
// Stream State
|
// Stream State
|
||||||
@ -146,19 +146,19 @@ public:
|
|||||||
//- Return flags of output stream
|
//- Return flags of output stream
|
||||||
virtual ios_base::fmtflags flags() const
|
virtual ios_base::fmtflags flags() const
|
||||||
{
|
{
|
||||||
return is_.flags();
|
return is_->flags();
|
||||||
}
|
}
|
||||||
|
|
||||||
//- Set stream flags
|
//- Set stream flags
|
||||||
virtual ios_base::fmtflags flags(const ios_base::fmtflags f)
|
virtual ios_base::fmtflags flags(const ios_base::fmtflags f)
|
||||||
{
|
{
|
||||||
return is_.flags(f);
|
return is_->flags(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
//- Set stream state to match that of the std::istream
|
//- Set stream state to match that of the std::istream
|
||||||
void syncState()
|
void syncState()
|
||||||
{
|
{
|
||||||
setState(is_.rdstate());
|
setState(is_->rdstate());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -180,6 +180,10 @@ public:
|
|||||||
const bool stripComments = true
|
const bool stripComments = true
|
||||||
);
|
);
|
||||||
|
|
||||||
|
//- Associate a different std::istream with the ISstream
|
||||||
|
// \return the previously attached stream
|
||||||
|
inline std::istream& attach(std::istream& is);
|
||||||
|
|
||||||
|
|
||||||
// Read Functions
|
// Read Functions
|
||||||
|
|
||||||
|
|||||||
@ -37,9 +37,9 @@ inline Foam::ISstream::ISstream
|
|||||||
:
|
:
|
||||||
Istream(streamOpt),
|
Istream(streamOpt),
|
||||||
name_(streamName),
|
name_(streamName),
|
||||||
is_(is)
|
is_(&is)
|
||||||
{
|
{
|
||||||
if (is_.good())
|
if (is_->good())
|
||||||
{
|
{
|
||||||
setOpened();
|
setOpened();
|
||||||
setGood();
|
setGood();
|
||||||
@ -53,9 +53,20 @@ inline Foam::ISstream::ISstream
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
inline std::istream& Foam::ISstream::attach(std::istream& is)
|
||||||
|
{
|
||||||
|
std::istream* old = is_;
|
||||||
|
|
||||||
|
is_ = &is;
|
||||||
|
IOstream::attach(*is_);
|
||||||
|
|
||||||
|
return *old;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
inline Foam::ISstream& Foam::ISstream::get(char& c)
|
inline Foam::ISstream& Foam::ISstream::get(char& c)
|
||||||
{
|
{
|
||||||
is_.get(c);
|
is_->get(c);
|
||||||
syncState();
|
syncState();
|
||||||
|
|
||||||
if (c == '\n' && good())
|
if (c == '\n' && good())
|
||||||
@ -69,17 +80,16 @@ inline Foam::ISstream& Foam::ISstream::get(char& c)
|
|||||||
|
|
||||||
inline int Foam::ISstream::peek()
|
inline int Foam::ISstream::peek()
|
||||||
{
|
{
|
||||||
return is_.peek();
|
return is_->peek();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline Foam::ISstream& Foam::ISstream::getLine(std::string& str, char delim)
|
inline Foam::ISstream& Foam::ISstream::getLine(std::string& str, char delim)
|
||||||
{
|
{
|
||||||
std::getline(is_, str, delim);
|
std::getline(*is_, str, delim);
|
||||||
std::streamsize count = is_.gcount();
|
|
||||||
syncState();
|
syncState();
|
||||||
|
|
||||||
if (delim == '\n' && count > 0)
|
if (delim == '\n')
|
||||||
{
|
{
|
||||||
++lineNumber_;
|
++lineNumber_;
|
||||||
}
|
}
|
||||||
@ -90,11 +100,12 @@ inline Foam::ISstream& Foam::ISstream::getLine(std::string& str, char delim)
|
|||||||
|
|
||||||
inline std::streamsize Foam::ISstream::getLine(std::nullptr_t, char delim)
|
inline std::streamsize Foam::ISstream::getLine(std::nullptr_t, char delim)
|
||||||
{
|
{
|
||||||
is_.ignore(std::numeric_limits<std::streamsize>::max(), delim);
|
is_->ignore(std::numeric_limits<std::streamsize>::max(), delim);
|
||||||
std::streamsize count = is_.gcount();
|
|
||||||
syncState();
|
syncState();
|
||||||
|
|
||||||
if (delim == '\n' && count > 0)
|
std::streamsize count = is_->gcount();
|
||||||
|
|
||||||
|
if (delim == '\n' && count)
|
||||||
{
|
{
|
||||||
++lineNumber_;
|
++lineNumber_;
|
||||||
}
|
}
|
||||||
@ -110,7 +121,7 @@ inline Foam::ISstream& Foam::ISstream::putback(const char c)
|
|||||||
--lineNumber_;
|
--lineNumber_;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_.putback(c))
|
if (!is_->putback(c))
|
||||||
{
|
{
|
||||||
setBad();
|
setBad();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -88,7 +88,7 @@ bool Foam::OSstream::write(const token& tok)
|
|||||||
|
|
||||||
Foam::Ostream& Foam::OSstream::write(const char c)
|
Foam::Ostream& Foam::OSstream::write(const char c)
|
||||||
{
|
{
|
||||||
os_ << c;
|
(*os_) << c;
|
||||||
if (c == token::NL)
|
if (c == token::NL)
|
||||||
{
|
{
|
||||||
++lineNumber_;
|
++lineNumber_;
|
||||||
@ -101,7 +101,7 @@ Foam::Ostream& Foam::OSstream::write(const char c)
|
|||||||
Foam::Ostream& Foam::OSstream::write(const char* str)
|
Foam::Ostream& Foam::OSstream::write(const char* str)
|
||||||
{
|
{
|
||||||
lineNumber_ += stringOps::count(str, token::NL);
|
lineNumber_ += stringOps::count(str, token::NL);
|
||||||
os_ << str;
|
(*os_) << str;
|
||||||
syncState();
|
syncState();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@ -109,7 +109,7 @@ Foam::Ostream& Foam::OSstream::write(const char* str)
|
|||||||
|
|
||||||
Foam::Ostream& Foam::OSstream::write(const word& str)
|
Foam::Ostream& Foam::OSstream::write(const word& str)
|
||||||
{
|
{
|
||||||
os_ << str;
|
(*os_) << str;
|
||||||
syncState();
|
syncState();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@ -125,7 +125,7 @@ Foam::Ostream& Foam::OSstream::writeQuoted
|
|||||||
{
|
{
|
||||||
// Output unquoted, only advance line number on newline
|
// Output unquoted, only advance line number on newline
|
||||||
lineNumber_ += stringOps::count(str, token::NL);
|
lineNumber_ += stringOps::count(str, token::NL);
|
||||||
os_ << str;
|
(*os_) << str;
|
||||||
|
|
||||||
syncState();
|
syncState();
|
||||||
return *this;
|
return *this;
|
||||||
@ -133,7 +133,7 @@ Foam::Ostream& Foam::OSstream::writeQuoted
|
|||||||
|
|
||||||
|
|
||||||
// Output with surrounding quotes and backslash escaping
|
// Output with surrounding quotes and backslash escaping
|
||||||
os_ << token::DQUOTE;
|
(*os_) << token::DQUOTE;
|
||||||
|
|
||||||
unsigned backslash = 0;
|
unsigned backslash = 0;
|
||||||
for (auto iter = str.cbegin(); iter != str.cend(); ++iter)
|
for (auto iter = str.cbegin(); iter != str.cend(); ++iter)
|
||||||
@ -158,16 +158,16 @@ Foam::Ostream& Foam::OSstream::writeQuoted
|
|||||||
// output all pending backslashes
|
// output all pending backslashes
|
||||||
while (backslash)
|
while (backslash)
|
||||||
{
|
{
|
||||||
os_ << '\\';
|
(*os_) << '\\';
|
||||||
--backslash;
|
--backslash;
|
||||||
}
|
}
|
||||||
|
|
||||||
os_ << c;
|
(*os_) << c;
|
||||||
}
|
}
|
||||||
|
|
||||||
// silently drop any trailing backslashes
|
// silently drop any trailing backslashes
|
||||||
// they would otherwise appear like an escaped end-quote
|
// they would otherwise appear like an escaped end-quote
|
||||||
os_ << token::DQUOTE;
|
(*os_) << token::DQUOTE;
|
||||||
|
|
||||||
syncState();
|
syncState();
|
||||||
return *this;
|
return *this;
|
||||||
@ -182,7 +182,7 @@ Foam::Ostream& Foam::OSstream::write(const string& str)
|
|||||||
|
|
||||||
Foam::Ostream& Foam::OSstream::write(const int32_t val)
|
Foam::Ostream& Foam::OSstream::write(const int32_t val)
|
||||||
{
|
{
|
||||||
os_ << val;
|
(*os_) << val;
|
||||||
syncState();
|
syncState();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@ -190,7 +190,7 @@ Foam::Ostream& Foam::OSstream::write(const int32_t val)
|
|||||||
|
|
||||||
Foam::Ostream& Foam::OSstream::write(const int64_t val)
|
Foam::Ostream& Foam::OSstream::write(const int64_t val)
|
||||||
{
|
{
|
||||||
os_ << val;
|
(*os_) << val;
|
||||||
syncState();
|
syncState();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@ -198,7 +198,7 @@ Foam::Ostream& Foam::OSstream::write(const int64_t val)
|
|||||||
|
|
||||||
Foam::Ostream& Foam::OSstream::write(const float val)
|
Foam::Ostream& Foam::OSstream::write(const float val)
|
||||||
{
|
{
|
||||||
os_ << val;
|
(*os_) << val;
|
||||||
syncState();
|
syncState();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@ -206,7 +206,7 @@ Foam::Ostream& Foam::OSstream::write(const float val)
|
|||||||
|
|
||||||
Foam::Ostream& Foam::OSstream::write(const double val)
|
Foam::Ostream& Foam::OSstream::write(const double val)
|
||||||
{
|
{
|
||||||
os_ << val;
|
(*os_) << val;
|
||||||
syncState();
|
syncState();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@ -231,17 +231,18 @@ bool Foam::OSstream::beginRawWrite(std::streamsize count)
|
|||||||
<< abort(FatalIOError);
|
<< abort(FatalIOError);
|
||||||
}
|
}
|
||||||
|
|
||||||
os_ << token::BEGIN_LIST;
|
(*os_) << token::BEGIN_LIST;
|
||||||
syncState();
|
syncState();
|
||||||
return os_.good();
|
|
||||||
|
return os_->good();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Foam::OSstream::endRawWrite()
|
bool Foam::OSstream::endRawWrite()
|
||||||
{
|
{
|
||||||
os_ << token::END_LIST;
|
(*os_) << token::END_LIST;
|
||||||
syncState();
|
syncState();
|
||||||
return os_.good();
|
return os_->good();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -254,8 +255,9 @@ Foam::Ostream& Foam::OSstream::writeRaw
|
|||||||
// No check for IOstreamOption::BINARY since this is either done in the
|
// No check for IOstreamOption::BINARY since this is either done in the
|
||||||
// beginRawWrite() method, or the caller knows what they are doing.
|
// beginRawWrite() method, or the caller knows what they are doing.
|
||||||
|
|
||||||
os_.write(data, count);
|
os_->write(data, count);
|
||||||
syncState();
|
syncState();
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -264,7 +266,7 @@ void Foam::OSstream::indent()
|
|||||||
{
|
{
|
||||||
for (unsigned short i = 0; i < indentLevel_*indentSize_; ++i)
|
for (unsigned short i = 0; i < indentLevel_*indentSize_; ++i)
|
||||||
{
|
{
|
||||||
os_ << ' ';
|
(*os_) << ' ';
|
||||||
}
|
}
|
||||||
syncState();
|
syncState();
|
||||||
}
|
}
|
||||||
@ -272,14 +274,14 @@ void Foam::OSstream::indent()
|
|||||||
|
|
||||||
void Foam::OSstream::flush()
|
void Foam::OSstream::flush()
|
||||||
{
|
{
|
||||||
os_.flush();
|
os_->flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Foam::OSstream::endl()
|
void Foam::OSstream::endl()
|
||||||
{
|
{
|
||||||
write('\n');
|
write('\n');
|
||||||
os_.flush();
|
os_->flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -287,37 +289,37 @@ void Foam::OSstream::endl()
|
|||||||
|
|
||||||
char Foam::OSstream::fill() const
|
char Foam::OSstream::fill() const
|
||||||
{
|
{
|
||||||
return os_.fill();
|
return os_->fill();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
char Foam::OSstream::fill(const char fillch)
|
char Foam::OSstream::fill(const char fillch)
|
||||||
{
|
{
|
||||||
return os_.fill(fillch);
|
return os_->fill(fillch);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int Foam::OSstream::width() const
|
int Foam::OSstream::width() const
|
||||||
{
|
{
|
||||||
return os_.width();
|
return os_->width();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int Foam::OSstream::width(const int w)
|
int Foam::OSstream::width(const int w)
|
||||||
{
|
{
|
||||||
return os_.width(w);
|
return os_->width(w);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int Foam::OSstream::precision() const
|
int Foam::OSstream::precision() const
|
||||||
{
|
{
|
||||||
return os_.precision();
|
return os_->precision();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int Foam::OSstream::precision(const int p)
|
int Foam::OSstream::precision(const int p)
|
||||||
{
|
{
|
||||||
return os_.precision(p);
|
return os_->precision(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -60,7 +60,7 @@ class OSstream
|
|||||||
|
|
||||||
fileName name_;
|
fileName name_;
|
||||||
|
|
||||||
std::ostream& os_;
|
std::ostream* os_;
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -123,10 +123,10 @@ public:
|
|||||||
// STL stream
|
// STL stream
|
||||||
|
|
||||||
//- Const access to underlying std::ostream
|
//- Const access to underlying std::ostream
|
||||||
virtual const std::ostream& stdStream() const { return os_; }
|
virtual const std::ostream& stdStream() const { return *os_; }
|
||||||
|
|
||||||
//- Access to underlying std::ostream
|
//- Access to underlying std::ostream
|
||||||
virtual std::ostream& stdStream() { return os_; }
|
virtual std::ostream& stdStream() { return *os_; }
|
||||||
|
|
||||||
|
|
||||||
// Stream State
|
// Stream State
|
||||||
@ -134,21 +134,25 @@ public:
|
|||||||
//- Get stream flags
|
//- Get stream flags
|
||||||
virtual ios_base::fmtflags flags() const
|
virtual ios_base::fmtflags flags() const
|
||||||
{
|
{
|
||||||
return os_.flags();
|
return os_->flags();
|
||||||
}
|
}
|
||||||
|
|
||||||
//- Set stream flags
|
//- Set stream flags
|
||||||
virtual ios_base::fmtflags flags(const ios_base::fmtflags f)
|
virtual ios_base::fmtflags flags(const ios_base::fmtflags f)
|
||||||
{
|
{
|
||||||
return os_.flags(f);
|
return os_->flags(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
//- Set stream state to match that of the std::ostream
|
//- Set stream state to match that of the std::ostream
|
||||||
void syncState()
|
void syncState()
|
||||||
{
|
{
|
||||||
setState(os_.rdstate());
|
setState(os_->rdstate());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//- Associate a different std::ostream with the OSstream
|
||||||
|
// \return the previously attached stream
|
||||||
|
inline std::ostream& attach(std::ostream& os);
|
||||||
|
|
||||||
|
|
||||||
// Write Functions
|
// Write Functions
|
||||||
|
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2011 OpenFOAM Foundation
|
Copyright (C) 2011 OpenFOAM Foundation
|
||||||
Copyright (C) 2020-2022 OpenCFD Ltd.
|
Copyright (C) 2020-2023 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -39,13 +39,13 @@ inline Foam::OSstream::OSstream
|
|||||||
:
|
:
|
||||||
Ostream(streamOpt),
|
Ostream(streamOpt),
|
||||||
name_(streamName),
|
name_(streamName),
|
||||||
os_(os)
|
os_(&os)
|
||||||
{
|
{
|
||||||
if (os_.good())
|
if (os_->good())
|
||||||
{
|
{
|
||||||
setOpened();
|
setOpened();
|
||||||
setGood();
|
setGood();
|
||||||
os_.precision(precision_);
|
os_->precision(precision_);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -54,4 +54,18 @@ inline Foam::OSstream::OSstream
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
inline std::ostream& Foam::OSstream::attach(std::ostream& os)
|
||||||
|
{
|
||||||
|
std::ostream* old = os_;
|
||||||
|
|
||||||
|
os_ = &os;
|
||||||
|
IOstream::attach(*os_);
|
||||||
|
// Leave precision untouched
|
||||||
|
|
||||||
|
return *old;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// ************************************************************************* //
|
// ************************************************************************* //
|
||||||
|
|||||||
@ -6,6 +6,7 @@
|
|||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2011 OpenFOAM Foundation
|
Copyright (C) 2011 OpenFOAM Foundation
|
||||||
|
Copyright (C) 2020-2023 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -38,7 +39,14 @@ void Foam::ISstream::print(Ostream& os) const
|
|||||||
os << "ISstream: " << name().c_str() << ' ';
|
os << "ISstream: " << name().c_str() << ' ';
|
||||||
|
|
||||||
IOstream::print(os);
|
IOstream::print(os);
|
||||||
IOstream::print(os, is_.rdstate());
|
if (is_)
|
||||||
|
{
|
||||||
|
IOstream::print(os, is_->rdstate());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
os << "std::stream not attached" << endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -47,7 +55,14 @@ void Foam::OSstream::print(Ostream& os) const
|
|||||||
os << "OSstream: " << name().c_str() << ' ';
|
os << "OSstream: " << name().c_str() << ' ';
|
||||||
|
|
||||||
IOstream::print(os);
|
IOstream::print(os);
|
||||||
IOstream::print(os, os_.rdstate());
|
if (os_)
|
||||||
|
{
|
||||||
|
IOstream::print(os, os_->rdstate());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
os << "std::stream not attached" << endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -4,8 +4,8 @@ Description
|
|||||||
|
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#ifndef FoamCompat_IStringStream_H
|
#ifndef IStringStream_H
|
||||||
#define FoamCompat_IStringStream_H
|
#define IStringStream_H
|
||||||
|
|
||||||
#include "StringStream.H"
|
#include "StringStream.H"
|
||||||
|
|
||||||
@ -4,8 +4,8 @@ Description
|
|||||||
|
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#ifndef FoamCompat_OStringStream_H
|
#ifndef OStringStream_H
|
||||||
#define FoamCompat_OStringStream_H
|
#define OStringStream_H
|
||||||
|
|
||||||
#include "StringStream.H"
|
#include "StringStream.H"
|
||||||
|
|
||||||
@ -259,6 +259,7 @@ public:
|
|||||||
//- Rewind the output stream
|
//- Rewind the output stream
|
||||||
virtual void rewind()
|
virtual void rewind()
|
||||||
{
|
{
|
||||||
|
// pubseekpos() instead of seekp() for symmetry with other classes
|
||||||
stream_.rdbuf()->pubseekpos(0, std::ios_base::out);
|
stream_.rdbuf()->pubseekpos(0, std::ios_base::out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -28,8 +28,8 @@ License
|
|||||||
|
|
||||||
#include "error.H"
|
#include "error.H"
|
||||||
#include "ITstream.H"
|
#include "ITstream.H"
|
||||||
#include "SpanStream.H"
|
|
||||||
#include "StringStream.H"
|
#include "StringStream.H"
|
||||||
|
#include "UIListStream.H"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||||
@ -94,7 +94,7 @@ Foam::tokenList Foam::ITstream::parse
|
|||||||
IOstreamOption streamOpt
|
IOstreamOption streamOpt
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
ISpanStream is(input, streamOpt);
|
UIListStream is(input, streamOpt);
|
||||||
|
|
||||||
tokenList tokens;
|
tokenList tokens;
|
||||||
parseStream(is, tokens);
|
parseStream(is, tokens);
|
||||||
@ -108,7 +108,7 @@ Foam::tokenList Foam::ITstream::parse
|
|||||||
IOstreamOption streamOpt
|
IOstreamOption streamOpt
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
ISpanStream is(input, streamOpt);
|
UIListStream is(input.data(), input.length(), streamOpt);
|
||||||
|
|
||||||
tokenList tokens;
|
tokenList tokens;
|
||||||
parseStream(is, tokens);
|
parseStream(is, tokens);
|
||||||
@ -122,7 +122,7 @@ Foam::tokenList Foam::ITstream::parse
|
|||||||
IOstreamOption streamOpt
|
IOstreamOption streamOpt
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
ISpanStream is(input, strlen(input), streamOpt);
|
UIListStream is(input, strlen(input), streamOpt);
|
||||||
|
|
||||||
tokenList tokens;
|
tokenList tokens;
|
||||||
parseStream(is, tokens);
|
parseStream(is, tokens);
|
||||||
@ -261,7 +261,7 @@ Foam::ITstream::ITstream
|
|||||||
:
|
:
|
||||||
ITstream(streamOpt, name)
|
ITstream(streamOpt, name)
|
||||||
{
|
{
|
||||||
ISpanStream is(input, streamOpt);
|
UIListStream is(input, streamOpt);
|
||||||
|
|
||||||
parseStream(is, static_cast<tokenList&>(*this));
|
parseStream(is, static_cast<tokenList&>(*this));
|
||||||
ITstream::seek(0); // rewind(), but bypasss virtual
|
ITstream::seek(0); // rewind(), but bypasss virtual
|
||||||
@ -277,7 +277,7 @@ Foam::ITstream::ITstream
|
|||||||
:
|
:
|
||||||
ITstream(streamOpt, name)
|
ITstream(streamOpt, name)
|
||||||
{
|
{
|
||||||
ISpanStream is(input.data(), input.length(), streamOpt);
|
UIListStream is(input.data(), input.length(), streamOpt);
|
||||||
|
|
||||||
parseStream(is, static_cast<tokenList&>(*this));
|
parseStream(is, static_cast<tokenList&>(*this));
|
||||||
ITstream::seek(0); // rewind(), but bypasss virtual
|
ITstream::seek(0); // rewind(), but bypasss virtual
|
||||||
@ -293,7 +293,7 @@ Foam::ITstream::ITstream
|
|||||||
:
|
:
|
||||||
ITstream(streamOpt, name)
|
ITstream(streamOpt, name)
|
||||||
{
|
{
|
||||||
ISpanStream is(input, strlen(input), streamOpt);
|
UIListStream is(input, strlen(input), streamOpt);
|
||||||
|
|
||||||
parseStream(is, static_cast<tokenList&>(*this));
|
parseStream(is, static_cast<tokenList&>(*this));
|
||||||
ITstream::seek(0); // rewind(), but bypasss virtual
|
ITstream::seek(0); // rewind(), but bypasss virtual
|
||||||
|
|||||||
@ -1,10 +0,0 @@
|
|||||||
// Compatibility include.
|
|
||||||
|
|
||||||
#ifndef FoamCompat_ListStream_H
|
|
||||||
#define FoamCompat_ListStream_H
|
|
||||||
|
|
||||||
#include "SpanStream.H"
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// ************************************************************************* //
|
|
||||||
@ -1,10 +0,0 @@
|
|||||||
// Compatibility include.
|
|
||||||
|
|
||||||
#ifndef FoamCompat_OListStream_H
|
|
||||||
#define FoamCompat_UListStream_H
|
|
||||||
|
|
||||||
#include "SpanStream.H"
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// ************************************************************************* //
|
|
||||||
@ -1,10 +0,0 @@
|
|||||||
// Compatibility include.
|
|
||||||
|
|
||||||
#ifndef FoamCompat_UIListStream_H
|
|
||||||
#define FoamCompat_UIListStream_H
|
|
||||||
|
|
||||||
#include "SpanStream.H"
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// ************************************************************************* //
|
|
||||||
@ -1,10 +0,0 @@
|
|||||||
// Compatibility include.
|
|
||||||
|
|
||||||
#ifndef FoamCompat_UListStream_H
|
|
||||||
#define FoamCompat_UListStream_H
|
|
||||||
|
|
||||||
#include "SpanStream.H"
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// ************************************************************************* //
|
|
||||||
@ -1,10 +0,0 @@
|
|||||||
// Compatibility include.
|
|
||||||
|
|
||||||
#ifndef FoamCompat_UOListStream_H
|
|
||||||
#define FoamCompat_UOListStream_H
|
|
||||||
|
|
||||||
#include "SpanStream.H"
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// ************************************************************************* //
|
|
||||||
@ -6,7 +6,7 @@
|
|||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2011 OpenFOAM Foundation
|
Copyright (C) 2011 OpenFOAM Foundation
|
||||||
Copyright (C) 2019-2023 OpenCFD Ltd.
|
Copyright (C) 2019-2022 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -54,21 +54,23 @@ class osha1stream
|
|||||||
public std::ostream
|
public std::ostream
|
||||||
{
|
{
|
||||||
//- A streambuf class for calculating SHA1 digests
|
//- A streambuf class for calculating SHA1 digests
|
||||||
class sha1buf : public std::streambuf
|
class sha1buf
|
||||||
|
:
|
||||||
|
public std::streambuf
|
||||||
{
|
{
|
||||||
//- This does all the work and has its own buffering
|
//- This does all the work and has its own buffering
|
||||||
SHA1 sha1_;
|
SHA1 sha1_;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
//- Output overflow handling - append to SHA1
|
//- Handle overflow
|
||||||
virtual int overflow(int_type c = traits_type::eof())
|
virtual int overflow(int c = EOF)
|
||||||
{
|
{
|
||||||
if (c != traits_type::eof()) sha1_.append(c);
|
if (c != EOF) sha1_.append(c);
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
//- Put sequence of characters - append to SHA1
|
//- Put sequence of characters
|
||||||
virtual std::streamsize xsputn(const char* s, std::streamsize n)
|
virtual std::streamsize xsputn(const char* s, std::streamsize n)
|
||||||
{
|
{
|
||||||
if (n) sha1_.append(s, n);
|
if (n) sha1_.append(s, n);
|
||||||
@ -81,7 +83,10 @@ class osha1stream
|
|||||||
sha1buf() = default;
|
sha1buf() = default;
|
||||||
|
|
||||||
//- Full access to the sha1
|
//- Full access to the sha1
|
||||||
SHA1& sha1() noexcept { return sha1_; }
|
SHA1& sha1() noexcept
|
||||||
|
{
|
||||||
|
return sha1_;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -95,22 +100,25 @@ public:
|
|||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
//- Default construct
|
//- Default construct
|
||||||
osha1stream() : std::ostream(&buf_) {}
|
osha1stream()
|
||||||
|
:
|
||||||
|
std::ostream(&buf_)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
// Member Functions
|
// Member Functions
|
||||||
|
|
||||||
//- This hides both signatures of std::basic_ios::rdbuf()
|
//- This hides both signatures of std::basic_ios::rdbuf()
|
||||||
sha1buf* rdbuf() { return &buf_; }
|
sha1buf* rdbuf()
|
||||||
|
{
|
||||||
|
return &buf_;
|
||||||
|
}
|
||||||
|
|
||||||
//- Full access to the sha1
|
//- Full access to the sha1
|
||||||
SHA1& sha1() noexcept { return buf_.sha1(); }
|
SHA1& sha1() noexcept
|
||||||
|
{
|
||||||
//- Return SHA1::Digest for the data processed until now
|
return buf_.sha1();
|
||||||
SHA1Digest digest() { return buf_.sha1().digest(); }
|
}
|
||||||
|
|
||||||
//- Clear the SHA1 calculation
|
|
||||||
void reset() { buf_.sha1().clear(); }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -121,21 +129,48 @@ namespace Detail
|
|||||||
Class Detail::OSHA1streamAllocator Declaration
|
Class Detail::OSHA1streamAllocator Declaration
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
//- An allocator for holding Foam::osha1stream
|
//- Allocator for an osha1stream
|
||||||
class OSHA1streamAllocator
|
class OSHA1streamAllocator
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
// Protected Data
|
// Protected Data
|
||||||
|
|
||||||
|
typedef osha1stream stream_type;
|
||||||
|
|
||||||
//- The output stream
|
//- The output stream
|
||||||
Foam::osha1stream stream_;
|
stream_type stream_;
|
||||||
|
|
||||||
|
|
||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
//- Default construct
|
//- Default construct
|
||||||
OSHA1streamAllocator() = default;
|
OSHA1streamAllocator() = default;
|
||||||
|
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
// Member Functions
|
||||||
|
|
||||||
|
//- Full access to the sha1
|
||||||
|
SHA1& sha1() noexcept
|
||||||
|
{
|
||||||
|
return stream_.sha1();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//- Return SHA1::Digest for the data processed until now
|
||||||
|
SHA1Digest digest()
|
||||||
|
{
|
||||||
|
return stream_.sha1().digest();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//- Clear the SHA1 calculation
|
||||||
|
void reset()
|
||||||
|
{
|
||||||
|
return stream_.sha1().clear();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
} // End namespace Detail
|
} // End namespace Detail
|
||||||
@ -153,15 +188,16 @@ class OSHA1stream
|
|||||||
{
|
{
|
||||||
typedef Detail::OSHA1streamAllocator allocator_type;
|
typedef Detail::OSHA1streamAllocator allocator_type;
|
||||||
|
|
||||||
|
// Private Member Functions
|
||||||
|
|
||||||
|
//- No copy construct
|
||||||
|
OSHA1stream(const OSHA1stream&) = delete;
|
||||||
|
|
||||||
|
//- No copy assignment
|
||||||
|
void operator=(const OSHA1stream&) = delete;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
//- No copy construct
|
|
||||||
OSHA1stream(const OSHA1stream&) = delete;
|
|
||||||
|
|
||||||
//- No copy assignment
|
|
||||||
void operator=(const OSHA1stream&) = delete;
|
|
||||||
|
|
||||||
|
|
||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
//- Construct with an empty digest
|
//- Construct with an empty digest
|
||||||
@ -175,18 +211,6 @@ public:
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
// Member Functions
|
|
||||||
|
|
||||||
//- Full access to the sha1
|
|
||||||
SHA1& sha1() noexcept { return stream_.sha1(); }
|
|
||||||
|
|
||||||
//- Return SHA1::Digest for the data processed until now
|
|
||||||
SHA1Digest digest() { return stream_.digest(); }
|
|
||||||
|
|
||||||
//- Clear the SHA1 calculation
|
|
||||||
void reset() { stream_.reset(); }
|
|
||||||
|
|
||||||
|
|
||||||
// Write Functions
|
// Write Functions
|
||||||
|
|
||||||
//- Add (unquoted) string contents.
|
//- Add (unquoted) string contents.
|
||||||
@ -203,7 +227,7 @@ public:
|
|||||||
// \deprecated(2017-07) - use reset() method
|
// \deprecated(2017-07) - use reset() method
|
||||||
void rewind()
|
void rewind()
|
||||||
{
|
{
|
||||||
stream_.sha1().clear();
|
sha1().clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,352 +0,0 @@
|
|||||||
/*---------------------------------------------------------------------------*\
|
|
||||||
========= |
|
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
|
||||||
\\ / O peration |
|
|
||||||
\\ / A nd | www.openfoam.com
|
|
||||||
\\/ M anipulation |
|
|
||||||
-------------------------------------------------------------------------------
|
|
||||||
Copyright (C) 2017-2023 OpenCFD Ltd.
|
|
||||||
-------------------------------------------------------------------------------
|
|
||||||
License
|
|
||||||
This file is part of OpenFOAM.
|
|
||||||
|
|
||||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
|
||||||
under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
||||||
for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
Class
|
|
||||||
Foam::ICharStream
|
|
||||||
|
|
||||||
Description
|
|
||||||
An input stream that reads from a List and manages the List storage.
|
|
||||||
Similar to IStringStream but with a List for its storage instead of
|
|
||||||
as string to allow reuse of List contents without copying.
|
|
||||||
|
|
||||||
See Also
|
|
||||||
Foam::OCharStream
|
|
||||||
Foam::ISpanStream
|
|
||||||
Foam::OSpanStream
|
|
||||||
|
|
||||||
\*---------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
#ifndef Foam_ICharStream_H
|
|
||||||
#define Foam_ICharStream_H
|
|
||||||
|
|
||||||
#include "ISpanStream.H"
|
|
||||||
#include "List.H"
|
|
||||||
#include "DynamicList.H"
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
namespace Foam
|
|
||||||
{
|
|
||||||
|
|
||||||
// Forward Declarations
|
|
||||||
class icharstream;
|
|
||||||
class ICharStream;
|
|
||||||
|
|
||||||
// Older names (prior to 2023-08)
|
|
||||||
typedef ICharStream IListStream;
|
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*\
|
|
||||||
Class icharstream Declaration
|
|
||||||
\*---------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
//- Similar to std::istringstream, but with the ability to swap
|
|
||||||
//- character content.
|
|
||||||
//- Has some similarity to std::ispanstream (C++23)
|
|
||||||
class icharstream
|
|
||||||
:
|
|
||||||
virtual public std::ios,
|
|
||||||
protected Foam::memorybuf::in_dynamic,
|
|
||||||
public std::istream
|
|
||||||
{
|
|
||||||
typedef Foam::memorybuf::in_dynamic buffer_type;
|
|
||||||
typedef std::istream stream_type;
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
// Constructors
|
|
||||||
|
|
||||||
//- Default construct - empty
|
|
||||||
icharstream()
|
|
||||||
:
|
|
||||||
buffer_type(),
|
|
||||||
stream_type(static_cast<buffer_type*>(this))
|
|
||||||
{}
|
|
||||||
|
|
||||||
//- Copy construct from content
|
|
||||||
icharstream(const char* buffer, size_t nbytes)
|
|
||||||
:
|
|
||||||
icharstream()
|
|
||||||
{
|
|
||||||
reset(buffer, nbytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
// //- Construct (deep copy) from span character content
|
|
||||||
// explicit icharstream(stdFoam::span<char> s)
|
|
||||||
// :
|
|
||||||
// icharstream()
|
|
||||||
// {
|
|
||||||
// reset(buffer, nbytes);
|
|
||||||
// }
|
|
||||||
|
|
||||||
//- Move construct from List
|
|
||||||
icharstream(List<char>&& buffer)
|
|
||||||
:
|
|
||||||
icharstream()
|
|
||||||
{
|
|
||||||
swap(buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Move construct from DynamicList
|
|
||||||
template<int SizeMin>
|
|
||||||
icharstream(DynamicList<char,SizeMin>&& buffer)
|
|
||||||
:
|
|
||||||
icharstream()
|
|
||||||
{
|
|
||||||
swap(buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Member Functions
|
|
||||||
|
|
||||||
//- The current get position within the buffer (tellg)
|
|
||||||
std::streampos input_pos() const
|
|
||||||
{
|
|
||||||
return buffer_type::span_tellg();
|
|
||||||
}
|
|
||||||
|
|
||||||
//- The get buffer capacity
|
|
||||||
std::streamsize capacity() const
|
|
||||||
{
|
|
||||||
return buffer_type::span_capacity();
|
|
||||||
}
|
|
||||||
|
|
||||||
//- The number of characters remaining in the get area.
|
|
||||||
//- Same as (capacity() - input_pos())
|
|
||||||
std::streamsize remaining() const
|
|
||||||
{
|
|
||||||
return buffer_type::span_remaining();
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Span of the input characters (is modifiable!)
|
|
||||||
UList<char> list() const
|
|
||||||
{
|
|
||||||
return buffer_type::span_list();
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Rewind the stream, clearing any old errors
|
|
||||||
void rewind()
|
|
||||||
{
|
|
||||||
buffer_type::pubseekpos(0, std::ios_base::in);
|
|
||||||
stream_type::clear(); // Clear old errors
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Reset content (copy)
|
|
||||||
void reset(const char* buffer, size_t nbytes)
|
|
||||||
{
|
|
||||||
buffer_type::reset(buffer, nbytes);
|
|
||||||
stream_type::clear(); // Clear old errors
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Transfer list contents to List buffer
|
|
||||||
void swap(List<char>& other)
|
|
||||||
{
|
|
||||||
buffer_type::swap(other);
|
|
||||||
stream_type::clear(); // Clear old errors
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Transfer list contents to a DynamicList buffer
|
|
||||||
template<int SizeMin>
|
|
||||||
void swap(DynamicList<char,SizeMin>& other)
|
|
||||||
{
|
|
||||||
buffer_type::swap(other);
|
|
||||||
stream_type::clear(); // Clear old errors
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Some information about the input buffer position/capacity
|
|
||||||
void debug_info(Ostream& os) const
|
|
||||||
{
|
|
||||||
os << "get="
|
|
||||||
<< input_pos() << '/' << capacity();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
namespace Detail
|
|
||||||
{
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*\
|
|
||||||
Class Detail::ICharStreamAllocator Declaration
|
|
||||||
\*---------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
//- An allocator for holding Foam::icharstream
|
|
||||||
class ICharStreamAllocator
|
|
||||||
{
|
|
||||||
protected:
|
|
||||||
|
|
||||||
// Protected Data
|
|
||||||
|
|
||||||
//- The stream
|
|
||||||
Foam::icharstream stream_;
|
|
||||||
|
|
||||||
|
|
||||||
// Constructors
|
|
||||||
|
|
||||||
//- Default construct
|
|
||||||
ICharStreamAllocator() = default;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // End namespace Detail
|
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*\
|
|
||||||
Class ICharStream Declaration
|
|
||||||
\*---------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
//- An ISstream with internal List storage. Always UNCOMPRESSED.
|
|
||||||
class ICharStream
|
|
||||||
:
|
|
||||||
public Detail::ICharStreamAllocator,
|
|
||||||
public Foam::ISstream
|
|
||||||
{
|
|
||||||
typedef Detail::ICharStreamAllocator allocator_type;
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
// Constructors
|
|
||||||
|
|
||||||
//- Default construct (empty), optionally with specified stream option
|
|
||||||
explicit ICharStream
|
|
||||||
(
|
|
||||||
IOstreamOption streamOpt = IOstreamOption()
|
|
||||||
)
|
|
||||||
:
|
|
||||||
allocator_type(),
|
|
||||||
ISstream(stream_, "input", streamOpt.format(), streamOpt.version())
|
|
||||||
{}
|
|
||||||
|
|
||||||
//- Copy construct from string content
|
|
||||||
explicit ICharStream
|
|
||||||
(
|
|
||||||
const std::string& buffer,
|
|
||||||
IOstreamOption streamOpt = IOstreamOption()
|
|
||||||
)
|
|
||||||
:
|
|
||||||
ICharStream(streamOpt)
|
|
||||||
{
|
|
||||||
stream_.reset(buffer.data(), buffer.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Move construct from List
|
|
||||||
explicit ICharStream
|
|
||||||
(
|
|
||||||
::Foam::List<char>&& buffer, // Fully qualify (issue #1521)
|
|
||||||
IOstreamOption streamOpt = IOstreamOption()
|
|
||||||
)
|
|
||||||
:
|
|
||||||
ICharStream(streamOpt)
|
|
||||||
{
|
|
||||||
stream_.swap(buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Move construct from DynamicList (uses current size)
|
|
||||||
template<int SizeMin>
|
|
||||||
explicit ICharStream
|
|
||||||
(
|
|
||||||
DynamicList<char,SizeMin>&& buffer,
|
|
||||||
IOstreamOption streamOpt = IOstreamOption()
|
|
||||||
)
|
|
||||||
:
|
|
||||||
ICharStream(streamOpt)
|
|
||||||
{
|
|
||||||
stream_.swap(buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Member Functions
|
|
||||||
|
|
||||||
//- Position of the get buffer
|
|
||||||
std::streampos tellg() const { return stream_.input_pos(); }
|
|
||||||
|
|
||||||
//- The current get position within the buffer (tellg)
|
|
||||||
std::streampos input_pos() const { return stream_.input_pos(); }
|
|
||||||
|
|
||||||
//- The input list size. Same as capacity()
|
|
||||||
label size() const { return label(stream_.capacity()); }
|
|
||||||
|
|
||||||
//- The get buffer capacity
|
|
||||||
std::streamsize capacity() const { return stream_.capacity(); }
|
|
||||||
|
|
||||||
//- The number of characters remaining in the get area.
|
|
||||||
//- Same as (capacity() - input_pos())
|
|
||||||
std::streamsize remaining() const { return stream_.remaining(); }
|
|
||||||
|
|
||||||
//- Span of the input characters (is modifiable!)
|
|
||||||
UList<char> list() const { return stream_.list(); }
|
|
||||||
|
|
||||||
//- Rewind the stream, clearing any old errors
|
|
||||||
virtual void rewind()
|
|
||||||
{
|
|
||||||
stream_.rewind();
|
|
||||||
syncState();
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Reset content (copy)
|
|
||||||
void reset(const char* buffer, size_t nbytes)
|
|
||||||
{
|
|
||||||
stream_.reset(buffer, nbytes);
|
|
||||||
syncState();
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Transfer list contents to List buffer
|
|
||||||
void swap(List<char>& other)
|
|
||||||
{
|
|
||||||
stream_.swap(other);
|
|
||||||
syncState();
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Transfer list contents to a DynamicList buffer
|
|
||||||
template<int SizeMin>
|
|
||||||
void swap(DynamicList<char,SizeMin>& other)
|
|
||||||
{
|
|
||||||
stream_.swap(other);
|
|
||||||
syncState();
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Print stream description to Ostream
|
|
||||||
virtual void print(Ostream& os) const;
|
|
||||||
|
|
||||||
|
|
||||||
// Member Operators
|
|
||||||
|
|
||||||
//- A non-const reference to const Istream
|
|
||||||
// Needed for read-constructors where the stream argument is temporary
|
|
||||||
Istream& operator()() const
|
|
||||||
{
|
|
||||||
// Could also rewind
|
|
||||||
return const_cast<ICharStream&>(*this);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
} // End namespace Foam
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// ************************************************************************* //
|
|
||||||
261
src/OpenFOAM/db/IOstreams/memory/IListStream.H
Normal file
261
src/OpenFOAM/db/IOstreams/memory/IListStream.H
Normal file
@ -0,0 +1,261 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | www.openfoam.com
|
||||||
|
\\/ M anipulation |
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
Copyright (C) 2017-2022 OpenCFD Ltd.
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
License
|
||||||
|
This file is part of OpenFOAM.
|
||||||
|
|
||||||
|
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||||
|
under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Class
|
||||||
|
Foam::IListStream
|
||||||
|
|
||||||
|
Description
|
||||||
|
An input stream that reads from a List and manages the List storage.
|
||||||
|
Similar to IStringStream but with a List for its storage instead of
|
||||||
|
as string to allow reuse of List contents without copying.
|
||||||
|
|
||||||
|
See Also
|
||||||
|
Foam::OListStream
|
||||||
|
Foam::UIListStream
|
||||||
|
Foam::UOListStream
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#ifndef Foam_IListStream_H
|
||||||
|
#define Foam_IListStream_H
|
||||||
|
|
||||||
|
#include "List.H"
|
||||||
|
#include "UIListStream.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
namespace Foam
|
||||||
|
{
|
||||||
|
namespace Detail
|
||||||
|
{
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
Class Detail::IListStreamAllocator Declaration
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
//- An stream/stream-buffer input allocator with List storage
|
||||||
|
class IListStreamAllocator
|
||||||
|
:
|
||||||
|
private List<char>,
|
||||||
|
public UIListStreamAllocator
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
|
||||||
|
// Constructors
|
||||||
|
|
||||||
|
//- Default construct
|
||||||
|
IListStreamAllocator()
|
||||||
|
:
|
||||||
|
List<char>(),
|
||||||
|
UIListStreamAllocator(List<char>::data(), List<char>::size())
|
||||||
|
{}
|
||||||
|
|
||||||
|
//- Move construct from List
|
||||||
|
IListStreamAllocator(List<char>&& buffer)
|
||||||
|
:
|
||||||
|
List<char>(std::move(buffer)),
|
||||||
|
UIListStreamAllocator(List<char>::data(), List<char>::size())
|
||||||
|
{}
|
||||||
|
|
||||||
|
//- Move construct from DynamicList
|
||||||
|
template<int SizeMin>
|
||||||
|
IListStreamAllocator(DynamicList<char,SizeMin>&& buffer)
|
||||||
|
:
|
||||||
|
List<char>(std::move(buffer)),
|
||||||
|
UIListStreamAllocator(List<char>::data(), List<char>::size())
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
// Protected Member Functions
|
||||||
|
|
||||||
|
//- Convenience method to address the underlying List storage
|
||||||
|
inline void reset_gbuffer()
|
||||||
|
{
|
||||||
|
UIListStreamAllocator::reset
|
||||||
|
(
|
||||||
|
List<char>::data(),
|
||||||
|
List<char>::size()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
// Member Functions
|
||||||
|
|
||||||
|
//- The current get position in the buffer
|
||||||
|
using UIListStreamAllocator::size;
|
||||||
|
|
||||||
|
//- Clear storage
|
||||||
|
inline void clearStorage()
|
||||||
|
{
|
||||||
|
List<char>::clear();
|
||||||
|
reset_gbuffer();
|
||||||
|
}
|
||||||
|
|
||||||
|
//- Transfer contents to other List
|
||||||
|
inline void swap(List<char>& list)
|
||||||
|
{
|
||||||
|
List<char>::swap(list);
|
||||||
|
reset_gbuffer();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // End namespace Detail
|
||||||
|
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
Class IListStream Declaration
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
//- An ISstream with internal List storage. Always UNCOMPRESSED.
|
||||||
|
class IListStream
|
||||||
|
:
|
||||||
|
public Detail::IListStreamAllocator,
|
||||||
|
public ISstream
|
||||||
|
{
|
||||||
|
typedef Detail::IListStreamAllocator allocator_type;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
// Constructors
|
||||||
|
|
||||||
|
//- Default construct with an empty list
|
||||||
|
explicit IListStream
|
||||||
|
(
|
||||||
|
IOstreamOption streamOpt = IOstreamOption()
|
||||||
|
)
|
||||||
|
:
|
||||||
|
allocator_type(),
|
||||||
|
ISstream(stream_, "input", streamOpt.format(), streamOpt.version())
|
||||||
|
{}
|
||||||
|
|
||||||
|
//- Move construct from List
|
||||||
|
explicit IListStream
|
||||||
|
(
|
||||||
|
::Foam::List<char>&& buffer, // Fully qualify (issue #1521)
|
||||||
|
IOstreamOption streamOpt = IOstreamOption()
|
||||||
|
)
|
||||||
|
:
|
||||||
|
allocator_type(std::move(buffer)),
|
||||||
|
ISstream(stream_, "input", streamOpt.format(), streamOpt.version())
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
//- Move construct from DynamicList
|
||||||
|
template<int SizeMin>
|
||||||
|
explicit IListStream
|
||||||
|
(
|
||||||
|
DynamicList<char,SizeMin>&& buffer,
|
||||||
|
IOstreamOption streamOpt = IOstreamOption()
|
||||||
|
)
|
||||||
|
:
|
||||||
|
allocator_type(std::move(buffer)),
|
||||||
|
ISstream(stream_, "input", streamOpt.format(), streamOpt.version())
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
// Member Functions
|
||||||
|
|
||||||
|
//- The current get position in the buffer
|
||||||
|
using allocator_type::size;
|
||||||
|
|
||||||
|
|
||||||
|
//- Return the current get position in the buffer
|
||||||
|
std::streampos pos() const
|
||||||
|
{
|
||||||
|
return allocator_type::tellg();
|
||||||
|
}
|
||||||
|
|
||||||
|
//- Rewind the stream, clearing any old errors
|
||||||
|
virtual void rewind()
|
||||||
|
{
|
||||||
|
allocator_type::rewind();
|
||||||
|
setGood(); // resynchronize with internal state
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//- Print stream description to Ostream
|
||||||
|
virtual void print(Ostream& os) const;
|
||||||
|
|
||||||
|
|
||||||
|
// Member Operators
|
||||||
|
|
||||||
|
//- A non-const reference to const Istream
|
||||||
|
// Needed for read-constructors where the stream argument is temporary
|
||||||
|
Istream& operator()() const
|
||||||
|
{
|
||||||
|
// Could also rewind
|
||||||
|
return const_cast<IListStream&>(*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Additional constructors and methods (as per v2012 and earlier)
|
||||||
|
#ifdef Foam_IOstream_extras
|
||||||
|
|
||||||
|
//- Construct with an empty list
|
||||||
|
explicit IListStream
|
||||||
|
(
|
||||||
|
IOstreamOption::streamFormat fmt
|
||||||
|
)
|
||||||
|
:
|
||||||
|
IListStream(IOstreamOption(fmt))
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
//- Move construct from List
|
||||||
|
IListStream
|
||||||
|
(
|
||||||
|
::Foam::List<char>&& buffer, // Fully qualify (issue #1521)
|
||||||
|
IOstreamOption::streamFormat fmt
|
||||||
|
)
|
||||||
|
:
|
||||||
|
IListStream(std::move(buffer), IOstreamOption(fmt))
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
//- Move construct from DynamicList
|
||||||
|
template<int SizeMin>
|
||||||
|
explicit IListStream
|
||||||
|
(
|
||||||
|
DynamicList<char,SizeMin>&& buffer,
|
||||||
|
IOstreamOption::streamFormat fmt
|
||||||
|
)
|
||||||
|
:
|
||||||
|
IListStream(std::move(buffer), IOstreamOption(fmt))
|
||||||
|
{}
|
||||||
|
|
||||||
|
#endif /* Foam_IOstream_extras */
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
} // End namespace Foam
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
@ -1,352 +0,0 @@
|
|||||||
/*---------------------------------------------------------------------------*\
|
|
||||||
========= |
|
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
|
||||||
\\ / O peration |
|
|
||||||
\\ / A nd | www.openfoam.com
|
|
||||||
\\/ M anipulation |
|
|
||||||
-------------------------------------------------------------------------------
|
|
||||||
Copyright (C) 2016-2023 OpenCFD Ltd.
|
|
||||||
-------------------------------------------------------------------------------
|
|
||||||
License
|
|
||||||
This file is part of OpenFOAM.
|
|
||||||
|
|
||||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
|
||||||
under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
||||||
for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
Class
|
|
||||||
Foam::ISpanStream
|
|
||||||
|
|
||||||
Description
|
|
||||||
Similar to IStringStream but using an externally managed buffer for its
|
|
||||||
input. This allows the input buffer to be filled (and refilled) from
|
|
||||||
various sources.
|
|
||||||
|
|
||||||
Note that this stream will normally be used as a "one-shot" reader.
|
|
||||||
Caution must be exercised that the referenced buffer remains valid and
|
|
||||||
without any intermediate resizing for the duration of the stream's use.
|
|
||||||
|
|
||||||
An example of possible use:
|
|
||||||
\code
|
|
||||||
DynamicList<char> buffer(4096); // allocate some large buffer
|
|
||||||
|
|
||||||
nread = something.read(buffer.data(),1024); // fill with content
|
|
||||||
buffer.resize(nread); // content size
|
|
||||||
|
|
||||||
// Construct dictionary, or something else
|
|
||||||
ISpanStream is(buffer)
|
|
||||||
dictionary dict1(is);
|
|
||||||
|
|
||||||
// Sometime later
|
|
||||||
nread = something.read(buffer.data(),2048); // fill with content
|
|
||||||
buffer.resize(nread); // content size
|
|
||||||
|
|
||||||
// Without intermediate variable
|
|
||||||
dictionary dict2(ISpanStream(buffer)());
|
|
||||||
\endcode
|
|
||||||
|
|
||||||
See Also
|
|
||||||
Foam::ICharStream
|
|
||||||
Foam::OCharStream
|
|
||||||
Foam::OSpanStream
|
|
||||||
|
|
||||||
\*---------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
#ifndef Foam_ISpanStream_H
|
|
||||||
#define Foam_ISpanStream_H
|
|
||||||
|
|
||||||
#include "UList.H"
|
|
||||||
#include "ISstream.H"
|
|
||||||
#include "memoryStreamBuffer.H"
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
namespace Foam
|
|
||||||
{
|
|
||||||
|
|
||||||
// Forward Declarations
|
|
||||||
class ispanstream;
|
|
||||||
class ISpanStream;
|
|
||||||
|
|
||||||
// Older names (prior to 2023-08)
|
|
||||||
typedef ispanstream uiliststream;
|
|
||||||
typedef ISpanStream UIListStream;
|
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*\
|
|
||||||
Class ispanstream Declaration
|
|
||||||
\*---------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
//- Similar to std::istringstream, but with an externally managed input buffer
|
|
||||||
//- which makes it most similar to std::ispanstream (C++23)
|
|
||||||
// This allows the input buffer to be filled or refilled from various sources
|
|
||||||
// without copying.
|
|
||||||
class ispanstream
|
|
||||||
:
|
|
||||||
virtual public std::ios,
|
|
||||||
protected Foam::memorybuf::in_base,
|
|
||||||
public std::istream
|
|
||||||
{
|
|
||||||
typedef Foam::memorybuf::in_base buffer_type;
|
|
||||||
typedef std::istream stream_type;
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
// Constructors
|
|
||||||
|
|
||||||
//- Default construct - empty
|
|
||||||
ispanstream()
|
|
||||||
:
|
|
||||||
buffer_type(),
|
|
||||||
stream_type(static_cast<buffer_type*>(this))
|
|
||||||
{}
|
|
||||||
|
|
||||||
//- Construct (shallow copy) for character array and number of bytes
|
|
||||||
ispanstream(const char* buffer, size_t nbytes)
|
|
||||||
:
|
|
||||||
buffer_type(const_cast<char*>(buffer), nbytes),
|
|
||||||
stream_type(static_cast<buffer_type*>(this))
|
|
||||||
{}
|
|
||||||
|
|
||||||
// //- Construct (shallow copy) from span character content
|
|
||||||
// ispanstream(stdFoam::span<char> s)
|
|
||||||
// :
|
|
||||||
// buffer_type(const_cast<char*>(s.data()), s.size()),
|
|
||||||
// stream_type(static_cast<buffer_type*>(this))
|
|
||||||
// {}
|
|
||||||
|
|
||||||
|
|
||||||
// Member Functions
|
|
||||||
|
|
||||||
//- The current get position within the buffer (tellg)
|
|
||||||
std::streampos input_pos() const
|
|
||||||
{
|
|
||||||
return buffer_type::span_tellg();
|
|
||||||
}
|
|
||||||
|
|
||||||
//- The get buffer capacity
|
|
||||||
std::streamsize capacity() const
|
|
||||||
{
|
|
||||||
return buffer_type::span_capacity();
|
|
||||||
}
|
|
||||||
|
|
||||||
//- The number of characters remaining in the get area.
|
|
||||||
//- Same as (capacity() - input_pos())
|
|
||||||
std::streamsize remaining() const
|
|
||||||
{
|
|
||||||
return buffer_type::span_remaining();
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Span of the input characters (is modifiable!)
|
|
||||||
UList<char> list() const
|
|
||||||
{
|
|
||||||
return buffer_type::span_list();
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Rewind the stream, clearing any old errors
|
|
||||||
void rewind()
|
|
||||||
{
|
|
||||||
buffer_type::pubseekpos(0, std::ios_base::in);
|
|
||||||
stream_type::clear(); // Clear old errors
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Reset the get buffer area
|
|
||||||
void reset(const char* buffer, size_t nbytes)
|
|
||||||
{
|
|
||||||
buffer_type::resetg(const_cast<char*>(buffer), nbytes);
|
|
||||||
stream_type::clear(); // Clear old errors
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Reset the get buffer area to use the data from a string
|
|
||||||
void reset(const std::string& s)
|
|
||||||
{
|
|
||||||
buffer_type::resetg(const_cast<char*>(&s[0]), s.size());
|
|
||||||
stream_type::clear(); // Clear old errors
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Some information about the input buffer position/capacity
|
|
||||||
void debug_info(Ostream& os) const
|
|
||||||
{
|
|
||||||
os << "get="
|
|
||||||
<< input_pos() << '/' << capacity();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
namespace Detail
|
|
||||||
{
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*\
|
|
||||||
Class Detail::ISpanStreamAllocator Declaration
|
|
||||||
\*---------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
//- An allocator for holding Foam::ispanstream
|
|
||||||
class ISpanStreamAllocator
|
|
||||||
{
|
|
||||||
protected:
|
|
||||||
|
|
||||||
// Protected Data
|
|
||||||
|
|
||||||
//- The stream
|
|
||||||
Foam::ispanstream stream_;
|
|
||||||
|
|
||||||
|
|
||||||
// Constructors
|
|
||||||
|
|
||||||
//- Default construct (empty)
|
|
||||||
ISpanStreamAllocator() = default;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // End namespace Detail
|
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*\
|
|
||||||
Class ISpanStream Declaration
|
|
||||||
\*---------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
class ISpanStream
|
|
||||||
:
|
|
||||||
public Detail::ISpanStreamAllocator,
|
|
||||||
public Foam::ISstream
|
|
||||||
{
|
|
||||||
typedef Detail::ISpanStreamAllocator allocator_type;
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
// Constructors
|
|
||||||
|
|
||||||
//- Default construct (empty), optionally with specified stream option
|
|
||||||
explicit ISpanStream
|
|
||||||
(
|
|
||||||
IOstreamOption streamOpt = IOstreamOption()
|
|
||||||
)
|
|
||||||
:
|
|
||||||
allocator_type(),
|
|
||||||
ISstream(stream_, "input", streamOpt.format(), streamOpt.version())
|
|
||||||
{}
|
|
||||||
|
|
||||||
//- Construct using specified buffer and number of bytes
|
|
||||||
ISpanStream
|
|
||||||
(
|
|
||||||
const char* buffer,
|
|
||||||
size_t nbytes,
|
|
||||||
IOstreamOption streamOpt = IOstreamOption()
|
|
||||||
)
|
|
||||||
:
|
|
||||||
ISpanStream(streamOpt)
|
|
||||||
{
|
|
||||||
reset(buffer, nbytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Use data area from string content
|
|
||||||
explicit ISpanStream
|
|
||||||
(
|
|
||||||
const std::string& buffer,
|
|
||||||
IOstreamOption streamOpt = IOstreamOption()
|
|
||||||
)
|
|
||||||
:
|
|
||||||
ISpanStream(streamOpt)
|
|
||||||
{
|
|
||||||
reset(buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Construct using data area from a List and number of bytes
|
|
||||||
ISpanStream
|
|
||||||
(
|
|
||||||
const ::Foam::UList<char>& buffer,
|
|
||||||
size_t nbytes,
|
|
||||||
IOstreamOption streamOpt = IOstreamOption()
|
|
||||||
)
|
|
||||||
:
|
|
||||||
ISpanStream(buffer.cdata(), nbytes, streamOpt)
|
|
||||||
{}
|
|
||||||
|
|
||||||
//- Construct using data area from a List and its inherent storage size
|
|
||||||
// Uses addressed size, thus no special treatment for a DynamicList
|
|
||||||
explicit ISpanStream
|
|
||||||
(
|
|
||||||
const ::Foam::UList<char>& buffer,
|
|
||||||
IOstreamOption streamOpt = IOstreamOption()
|
|
||||||
)
|
|
||||||
:
|
|
||||||
ISpanStream(buffer.cdata(), buffer.size(), streamOpt)
|
|
||||||
{}
|
|
||||||
|
|
||||||
|
|
||||||
// Member Functions
|
|
||||||
|
|
||||||
//- Position of the get buffer
|
|
||||||
std::streampos tellg() const { return stream_.input_pos(); }
|
|
||||||
|
|
||||||
//- The current get position within the buffer (tellg)
|
|
||||||
std::streampos input_pos() const { return stream_.input_pos(); }
|
|
||||||
|
|
||||||
//- The input list size. Same as capacity()
|
|
||||||
label size() const { return label(stream_.capacity()); }
|
|
||||||
|
|
||||||
//- The get buffer capacity
|
|
||||||
std::streamsize capacity() const { return stream_.capacity(); }
|
|
||||||
|
|
||||||
//- The number of characters remaining in the get area.
|
|
||||||
//- Same as (capacity() - input_pos())
|
|
||||||
std::streamsize remaining() const { return stream_.remaining(); }
|
|
||||||
|
|
||||||
|
|
||||||
//- Span of the current input characters (is modifiable!)
|
|
||||||
UList<char> list() const { return stream_.list(); }
|
|
||||||
|
|
||||||
//- Reset input area, position to buffer start and clear errors
|
|
||||||
void reset(const char* buffer, size_t nbytes)
|
|
||||||
{
|
|
||||||
stream_.reset(buffer, nbytes);
|
|
||||||
syncState();
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Reset input area to use data from a string
|
|
||||||
void reset(const std::string& s)
|
|
||||||
{
|
|
||||||
stream_.reset(s);
|
|
||||||
syncState();
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Rewind the stream, clearing any old errors
|
|
||||||
virtual void rewind()
|
|
||||||
{
|
|
||||||
stream_.rewind();
|
|
||||||
syncState();
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Print stream description to Ostream
|
|
||||||
virtual void print(Ostream& os) const;
|
|
||||||
|
|
||||||
|
|
||||||
// Member Operators
|
|
||||||
|
|
||||||
//- A non-const reference to const Istream
|
|
||||||
// Needed for read-constructors where the stream argument is temporary
|
|
||||||
Istream& operator()() const
|
|
||||||
{
|
|
||||||
// Could also rewind
|
|
||||||
return const_cast<ISpanStream&>(*this);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
} // End namespace Foam
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// ************************************************************************* //
|
|
||||||
@ -5,7 +5,7 @@
|
|||||||
\\ / A nd | www.openfoam.com
|
\\ / A nd | www.openfoam.com
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2017-2023 OpenCFD Ltd.
|
Copyright (C) 2017 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -25,39 +25,40 @@ License
|
|||||||
|
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include "SpanStream.H"
|
#include "UListStream.H"
|
||||||
|
#include "ListStream.H"
|
||||||
#include "OCountStream.H"
|
#include "OCountStream.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
void Foam::ISpanStream::print(Ostream& os) const
|
void Foam::IListStream::print(Ostream& os) const
|
||||||
{
|
{
|
||||||
os << "ISpanStream: ";
|
os << "IListStream: ";
|
||||||
stream_.debug_info(os);
|
printBufInfo(os);
|
||||||
os << Foam::endl;
|
os << Foam::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Foam::OSpanStream::print(Ostream& os) const
|
void Foam::UIListStream::print(Ostream& os) const
|
||||||
{
|
{
|
||||||
os << "OSpanStream: ";
|
os << "UIListStream: ";
|
||||||
stream_.debug_info(os);
|
printBufInfo(os);
|
||||||
os << Foam::endl;
|
os << Foam::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Foam::ICharStream::print(Ostream& os) const
|
void Foam::OListStream::print(Ostream& os) const
|
||||||
{
|
{
|
||||||
os << "ICharStream: ";
|
os << "OListStream: ";
|
||||||
stream_.debug_info(os);
|
printBufInfo(os);
|
||||||
os << Foam::endl;
|
os << Foam::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Foam::OCharStream::print(Ostream& os) const
|
void Foam::UOListStream::print(Ostream& os) const
|
||||||
{
|
{
|
||||||
os << "OCharStream: ";
|
os << "UOListStream: ";
|
||||||
stream_.debug_info(os);
|
printBufInfo(os);
|
||||||
os << Foam::endl;
|
os << Foam::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,8 +66,7 @@ void Foam::OCharStream::print(Ostream& os) const
|
|||||||
void Foam::OCountStream::print(Ostream& os) const
|
void Foam::OCountStream::print(Ostream& os) const
|
||||||
{
|
{
|
||||||
os << "OCountStream: ";
|
os << "OCountStream: ";
|
||||||
// os << "count=" << stream_.count();
|
printBufInfo(os);
|
||||||
stream_.debug_info(os);
|
|
||||||
os << Foam::endl;
|
os << Foam::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -5,7 +5,7 @@
|
|||||||
\\ / A nd | www.openfoam.com
|
\\ / A nd | www.openfoam.com
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2017-2023 OpenCFD Ltd.
|
Copyright (C) 2017 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -24,17 +24,15 @@ License
|
|||||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
Description
|
Description
|
||||||
Input/output streams with (internal or external) character storage.
|
Input/output streams with managed List storage.
|
||||||
|
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#ifndef Foam_SpanStream_H
|
#ifndef ListStream_H
|
||||||
#define Foam_SpanStream_H
|
#define ListStream_H
|
||||||
|
|
||||||
#include "ISpanStream.H"
|
#include "IListStream.H"
|
||||||
#include "ICharStream.H"
|
#include "OListStream.H"
|
||||||
#include "OSpanStream.H"
|
|
||||||
#include "OCharStream.H"
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -1,316 +0,0 @@
|
|||||||
/*---------------------------------------------------------------------------*\
|
|
||||||
========= |
|
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
|
||||||
\\ / O peration |
|
|
||||||
\\ / A nd | www.openfoam.com
|
|
||||||
\\/ M anipulation |
|
|
||||||
-------------------------------------------------------------------------------
|
|
||||||
Copyright (C) 2017-2023 OpenCFD Ltd.
|
|
||||||
-------------------------------------------------------------------------------
|
|
||||||
License
|
|
||||||
This file is part of OpenFOAM.
|
|
||||||
|
|
||||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
|
||||||
under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
||||||
for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
Class
|
|
||||||
Foam::OCharStream
|
|
||||||
|
|
||||||
Description
|
|
||||||
An output stream that writes to a List and manages the List storage.
|
|
||||||
Similar to OStringStream but with a List for its storage instead of
|
|
||||||
as string to allow reuse of List contents without copying.
|
|
||||||
|
|
||||||
The default initial size is 512-bytes and uses size doubling.
|
|
||||||
After construction can use the reserve() method to adjust this.
|
|
||||||
|
|
||||||
See Also
|
|
||||||
Foam::ICharStream
|
|
||||||
Foam::OSpanStream
|
|
||||||
Foam::ISpanStream
|
|
||||||
|
|
||||||
\*---------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
#ifndef Foam_OCharStream_H
|
|
||||||
#define Foam_OCharStream_H
|
|
||||||
|
|
||||||
#include "OSpanStream.H"
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
namespace Foam
|
|
||||||
{
|
|
||||||
|
|
||||||
// Forward Declarations
|
|
||||||
class ocharstream;
|
|
||||||
class OCharStream;
|
|
||||||
|
|
||||||
// Older names (prior to 2023-08)
|
|
||||||
typedef OCharStream OListStream;
|
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*\
|
|
||||||
Class ocharstream Declaration
|
|
||||||
\*---------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
//- Similar to std::ostringstream, but with the ability to swap
|
|
||||||
//- character content.
|
|
||||||
//- Has some similarity to std::ospanstream (C++23)
|
|
||||||
class ocharstream
|
|
||||||
:
|
|
||||||
virtual public std::ios,
|
|
||||||
protected Foam::memorybuf::out_dynamic,
|
|
||||||
public std::ostream
|
|
||||||
{
|
|
||||||
typedef Foam::memorybuf::out_dynamic buffer_type;
|
|
||||||
typedef std::ostream stream_type;
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
// Constructors
|
|
||||||
|
|
||||||
//- Default construct - empty
|
|
||||||
ocharstream()
|
|
||||||
:
|
|
||||||
buffer_type(),
|
|
||||||
stream_type(static_cast<buffer_type*>(this))
|
|
||||||
{}
|
|
||||||
|
|
||||||
//- Move construct from List
|
|
||||||
ocharstream(List<char>&& buffer)
|
|
||||||
:
|
|
||||||
ocharstream()
|
|
||||||
{
|
|
||||||
swap(buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Move construct from DynamicList
|
|
||||||
template<int SizeMin>
|
|
||||||
ocharstream(DynamicList<char,SizeMin>&& buffer)
|
|
||||||
:
|
|
||||||
ocharstream()
|
|
||||||
{
|
|
||||||
swap(buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Member Functions
|
|
||||||
|
|
||||||
//- The current output position within the buffer (tellp)
|
|
||||||
std::streampos output_pos() const
|
|
||||||
{
|
|
||||||
return (buffer_type::span_tellp());
|
|
||||||
}
|
|
||||||
|
|
||||||
//- The put buffer capacity
|
|
||||||
std::streamsize capacity() const
|
|
||||||
{
|
|
||||||
return buffer_type::span_capacity();
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Reserve output space for at least this amount
|
|
||||||
void reserve(const std::streamsize n)
|
|
||||||
{
|
|
||||||
buffer_type::reserve(n);
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Span of the current output characters (is modifiable!)
|
|
||||||
UList<char> list() const
|
|
||||||
{
|
|
||||||
return buffer_type::span_list();
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Rewind the stream, clearing any old errors
|
|
||||||
void rewind()
|
|
||||||
{
|
|
||||||
buffer_type::pubseekpos(0, std::ios_base::out);
|
|
||||||
stream_type::clear(); // Clear old errors
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Transfer list contents to List buffer
|
|
||||||
void swap(List<char>& other)
|
|
||||||
{
|
|
||||||
buffer_type::swap(other);
|
|
||||||
stream_type::clear(); // Clear old errors
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Transfer list contents to a DynamicList buffer
|
|
||||||
template<int SizeMin>
|
|
||||||
void swap(DynamicList<char,SizeMin>& other)
|
|
||||||
{
|
|
||||||
buffer_type::swap(other);
|
|
||||||
stream_type::clear(); // Clear old errors
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Some information about the output buffer position/capacity
|
|
||||||
void debug_info(Ostream& os) const
|
|
||||||
{
|
|
||||||
os << "put="
|
|
||||||
<< output_pos() << '/' << capacity();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
namespace Detail
|
|
||||||
{
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*\
|
|
||||||
Class Detail::OCharStreamAllocator Declaration
|
|
||||||
\*---------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
//- An allocator for holding Foam::ocharstream
|
|
||||||
class OCharStreamAllocator
|
|
||||||
{
|
|
||||||
protected:
|
|
||||||
|
|
||||||
// Protected Data
|
|
||||||
|
|
||||||
//- The stream
|
|
||||||
Foam::ocharstream stream_;
|
|
||||||
|
|
||||||
|
|
||||||
// Constructors
|
|
||||||
|
|
||||||
//- Default construct - empty
|
|
||||||
OCharStreamAllocator() = default;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // End namespace Detail
|
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*\
|
|
||||||
Class OCharStream Declaration
|
|
||||||
\*---------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
//- An OSstream with internal List storage
|
|
||||||
class OCharStream
|
|
||||||
:
|
|
||||||
public Detail::OCharStreamAllocator,
|
|
||||||
public Foam::OSstream
|
|
||||||
{
|
|
||||||
typedef Detail::OCharStreamAllocator allocator_type;
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
// Constructors
|
|
||||||
|
|
||||||
//- Default construct (empty output)
|
|
||||||
explicit OCharStream
|
|
||||||
(
|
|
||||||
IOstreamOption streamOpt = IOstreamOption()
|
|
||||||
)
|
|
||||||
:
|
|
||||||
allocator_type(),
|
|
||||||
OSstream(stream_, "output", streamOpt.format(), streamOpt.version())
|
|
||||||
{}
|
|
||||||
|
|
||||||
//- Construct with initial reserved number of bytes
|
|
||||||
explicit OCharStream
|
|
||||||
(
|
|
||||||
size_t nbytes,
|
|
||||||
IOstreamOption streamOpt = IOstreamOption()
|
|
||||||
)
|
|
||||||
:
|
|
||||||
OCharStream(streamOpt)
|
|
||||||
{
|
|
||||||
stream_.reserve(nbytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Move construct from a List
|
|
||||||
explicit OCharStream
|
|
||||||
(
|
|
||||||
::Foam::List<char>&& buffer,
|
|
||||||
IOstreamOption streamOpt = IOstreamOption()
|
|
||||||
)
|
|
||||||
:
|
|
||||||
OCharStream(streamOpt)
|
|
||||||
{
|
|
||||||
stream_.swap(buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Move construct from a DynamicList (uses entire capacity)
|
|
||||||
template<int SizeMin>
|
|
||||||
explicit OCharStream
|
|
||||||
(
|
|
||||||
::Foam::DynamicList<char,SizeMin>&& buffer,
|
|
||||||
IOstreamOption streamOpt = IOstreamOption()
|
|
||||||
)
|
|
||||||
:
|
|
||||||
OCharStream(streamOpt)
|
|
||||||
{
|
|
||||||
stream_.swap(buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Member Functions
|
|
||||||
|
|
||||||
//- Position of the put buffer
|
|
||||||
std::streampos tellp() const { return stream_.output_pos(); }
|
|
||||||
|
|
||||||
//- The current output position within the buffer (tellp)
|
|
||||||
std::streampos output_pos() const { return stream_.output_pos(); }
|
|
||||||
|
|
||||||
//- The current output size. Same as tellp(), output_pos()
|
|
||||||
label size() const { return label(stream_.output_pos()); }
|
|
||||||
|
|
||||||
//- The put buffer capacity
|
|
||||||
std::streamsize capacity() const { return stream_.capacity(); }
|
|
||||||
|
|
||||||
//- Reserve output space for at least this amount
|
|
||||||
void reserve(const std::streamsize n) { stream_.reserve(n); }
|
|
||||||
|
|
||||||
//- Span of the current output characters (is modifiable!)
|
|
||||||
UList<char> list() const { return stream_.list(); }
|
|
||||||
|
|
||||||
//- Rewind the stream, clearing any old errors
|
|
||||||
virtual void rewind()
|
|
||||||
{
|
|
||||||
stream_.rewind();
|
|
||||||
syncState();
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Transfer list contents to List buffer
|
|
||||||
void swap(List<char>& other)
|
|
||||||
{
|
|
||||||
stream_.swap(other);
|
|
||||||
syncState();
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Transfer list contents to a DynamicList buffer
|
|
||||||
template<int SizeMin>
|
|
||||||
void swap(DynamicList<char,SizeMin>& other)
|
|
||||||
{
|
|
||||||
stream_.swap(other);
|
|
||||||
syncState();
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Print stream description to Ostream
|
|
||||||
virtual void print(Ostream& os) const;
|
|
||||||
|
|
||||||
|
|
||||||
// Houskeeping
|
|
||||||
|
|
||||||
//- Block size was used in OpenFOAM-v2306 and earlier
|
|
||||||
void setBlockSize(int n) {}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
} // End namespace Foam
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// ************************************************************************* //
|
|
||||||
@ -5,7 +5,7 @@
|
|||||||
\\ / A nd | www.openfoam.com
|
\\ / A nd | www.openfoam.com
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2016-2023 OpenCFD Ltd.
|
Copyright (C) 2016-2021 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -42,6 +42,103 @@ Description
|
|||||||
namespace Foam
|
namespace Foam
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
Class countstreambuf Declaration
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
//- A streambuf class for determining byte counts
|
||||||
|
class countstreambuf
|
||||||
|
:
|
||||||
|
public std::streambuf
|
||||||
|
{
|
||||||
|
//- The number of bytes counted
|
||||||
|
std::streamsize size_;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
//- Set position pointer to relative position
|
||||||
|
virtual std::streampos seekoff
|
||||||
|
(
|
||||||
|
std::streamoff off,
|
||||||
|
std::ios_base::seekdir way,
|
||||||
|
std::ios_base::openmode which = std::ios_base::in|std::ios_base::out
|
||||||
|
)
|
||||||
|
{
|
||||||
|
if (which & std::ios_base::out)
|
||||||
|
{
|
||||||
|
if (way == std::ios_base::beg)
|
||||||
|
{
|
||||||
|
size_ = off;
|
||||||
|
}
|
||||||
|
else if (way == std::ios_base::cur)
|
||||||
|
{
|
||||||
|
size_ += off;
|
||||||
|
}
|
||||||
|
else if (way == std::ios_base::end)
|
||||||
|
{
|
||||||
|
// not really possible
|
||||||
|
}
|
||||||
|
|
||||||
|
return size_; // tellp()
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//- Set position pointer to absolute position
|
||||||
|
// For the counter, adjust the count accordingly.
|
||||||
|
virtual std::streampos seekpos
|
||||||
|
(
|
||||||
|
std::streampos pos,
|
||||||
|
std::ios_base::openmode which = std::ios_base::in|std::ios_base::out
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return seekoff(pos, std::ios_base::beg, which);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//- Handle output counting via overflow
|
||||||
|
virtual int overflow(int c = EOF)
|
||||||
|
{
|
||||||
|
if (c != EOF)
|
||||||
|
{
|
||||||
|
++size_;
|
||||||
|
}
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//- Put sequence of characters
|
||||||
|
virtual std::streamsize xsputn(const char* s, std::streamsize n)
|
||||||
|
{
|
||||||
|
size_ += n;
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
//- Default construct, or with precount size
|
||||||
|
explicit countstreambuf(std::streamsize precount=0)
|
||||||
|
:
|
||||||
|
size_(precount)
|
||||||
|
{}
|
||||||
|
|
||||||
|
//- \return The buffer put position == number of bytes counted.
|
||||||
|
std::streamsize tellp() const
|
||||||
|
{
|
||||||
|
return size_;
|
||||||
|
}
|
||||||
|
|
||||||
|
//- Some information about the number of bytes counted
|
||||||
|
void printBufInfo(Ostream& os) const
|
||||||
|
{
|
||||||
|
os << "count=" << size_;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*\
|
/*---------------------------------------------------------------------------*\
|
||||||
Class ocountstream Declaration
|
Class ocountstream Declaration
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
@ -52,124 +149,34 @@ namespace Foam
|
|||||||
class ocountstream
|
class ocountstream
|
||||||
:
|
:
|
||||||
virtual public std::ios,
|
virtual public std::ios,
|
||||||
|
protected countstreambuf,
|
||||||
public std::ostream
|
public std::ostream
|
||||||
{
|
{
|
||||||
//- A streambuf class for determining byte counts
|
|
||||||
class countbuf : public std::streambuf
|
|
||||||
{
|
|
||||||
//- The number of bytes counted
|
|
||||||
std::streamsize size_;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
//- Set position pointer to relative position
|
|
||||||
virtual std::streampos seekoff
|
|
||||||
(
|
|
||||||
std::streamoff off,
|
|
||||||
std::ios_base::seekdir way,
|
|
||||||
std::ios_base::openmode which = std::ios_base::in|std::ios_base::out
|
|
||||||
)
|
|
||||||
{
|
|
||||||
if (which & std::ios_base::out)
|
|
||||||
{
|
|
||||||
if (way == std::ios_base::beg)
|
|
||||||
{
|
|
||||||
size_ = off;
|
|
||||||
}
|
|
||||||
else if (way == std::ios_base::cur)
|
|
||||||
{
|
|
||||||
size_ += off;
|
|
||||||
}
|
|
||||||
else if (way == std::ios_base::end)
|
|
||||||
{
|
|
||||||
// not really possible
|
|
||||||
}
|
|
||||||
|
|
||||||
return size_; // Like span_tellp()
|
|
||||||
}
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Set position pointer to absolute position
|
|
||||||
// For the counter, adjust the count accordingly.
|
|
||||||
virtual std::streampos seekpos
|
|
||||||
(
|
|
||||||
std::streampos pos,
|
|
||||||
std::ios_base::openmode which = std::ios_base::in|std::ios_base::out
|
|
||||||
)
|
|
||||||
{
|
|
||||||
return seekoff(pos, std::ios_base::beg, which);
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Output overflow handling - increment counter
|
|
||||||
virtual int overflow(int_type c = traits_type::eof())
|
|
||||||
{
|
|
||||||
if (c != traits_type::eof()) ++size_;
|
|
||||||
return c;
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Put sequence of characters - increment counter
|
|
||||||
virtual std::streamsize xsputn(const char* s, std::streamsize n)
|
|
||||||
{
|
|
||||||
size_ += n;
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
// Constructors
|
|
||||||
|
|
||||||
//- Default construct, count = 0
|
|
||||||
countbuf() : size_(0) {}
|
|
||||||
|
|
||||||
|
|
||||||
// Member Functions
|
|
||||||
|
|
||||||
//- The number of bytes counted.
|
|
||||||
std::streamsize count() const noexcept { return size_; }
|
|
||||||
|
|
||||||
//- Reset the count
|
|
||||||
void reset(std::streamsize n = 0) noexcept { size_ = n; }
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// Private Data
|
|
||||||
|
|
||||||
typedef countbuf buffer_type;
|
|
||||||
typedef std::ostream stream_type;
|
|
||||||
|
|
||||||
//- Reference to the underlying buffer
|
|
||||||
buffer_type buf_;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// Constructors
|
//- Default construct
|
||||||
|
ocountstream()
|
||||||
//- Default construct
|
:
|
||||||
ocountstream() : stream_type(&buf_) {}
|
countstreambuf(),
|
||||||
|
std::ostream(static_cast<countstreambuf*>(this))
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
// Member Functions
|
//- \return The buffer put position == number of bytes counted.
|
||||||
|
using countstreambuf::tellp;
|
||||||
|
|
||||||
//- This hides both signatures of std::basic_ios::rdbuf()
|
//- \return The number of bytes counted
|
||||||
countbuf* rdbuf() { return &buf_; }
|
std::streamsize size() const
|
||||||
|
{
|
||||||
|
return countstreambuf::tellp();
|
||||||
|
}
|
||||||
|
|
||||||
//- \return The number of bytes counted
|
//- Rewind the stream, reset the count
|
||||||
std::streamsize count() const noexcept { return buf_.count(); }
|
void rewind()
|
||||||
|
{
|
||||||
//- Reset the count
|
this->pubseekpos(0, std::ios_base::out);
|
||||||
void reset(std::streamsize n = 0) noexcept
|
clear(); // for safety, clear any old errors
|
||||||
{
|
}
|
||||||
buf_.reset(n);
|
|
||||||
stream_type::clear(); // Clear old errors
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Some information about the output buffer position/capacity
|
|
||||||
void debug_info(Ostream& os) const
|
|
||||||
{
|
|
||||||
os << "count=" << buf_.count();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -180,21 +187,55 @@ namespace Detail
|
|||||||
Class Detail::OCountStreamAllocator Declaration
|
Class Detail::OCountStreamAllocator Declaration
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
//- An allocator for holding Foam::ocountstream
|
//- An stream/stream-buffer allocator for counting
|
||||||
class OCountStreamAllocator
|
class OCountStreamAllocator
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
// Protected Data
|
// Protected Data
|
||||||
|
|
||||||
|
typedef std::ostream stream_type;
|
||||||
|
|
||||||
|
//- The stream buffer
|
||||||
|
countstreambuf buf_;
|
||||||
|
|
||||||
//- The output stream
|
//- The output stream
|
||||||
Foam::ocountstream stream_;
|
stream_type stream_;
|
||||||
|
|
||||||
|
|
||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
//- Default construct
|
//- Default construct, or with precount size
|
||||||
OCountStreamAllocator() = default;
|
OCountStreamAllocator(std::streamsize precount=0)
|
||||||
|
:
|
||||||
|
buf_(precount),
|
||||||
|
stream_(&buf_)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
// Protected Member Functions
|
||||||
|
|
||||||
|
void printBufInfo(Ostream& os) const
|
||||||
|
{
|
||||||
|
buf_.printBufInfo(os);
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
// Member Functions
|
||||||
|
|
||||||
|
//- The number of bytes counted
|
||||||
|
std::streamsize size() const
|
||||||
|
{
|
||||||
|
return buf_.tellp();
|
||||||
|
}
|
||||||
|
|
||||||
|
//- Rewind the stream, reset the count
|
||||||
|
void rewind()
|
||||||
|
{
|
||||||
|
buf_.pubseekpos(0);
|
||||||
|
stream_.clear(); // for safety, clear any old errors
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
} // End namespace Detail
|
} // End namespace Detail
|
||||||
@ -229,33 +270,35 @@ public:
|
|||||||
//- Copy construct
|
//- Copy construct
|
||||||
OCountStream(const OCountStream& str)
|
OCountStream(const OCountStream& str)
|
||||||
:
|
:
|
||||||
allocator_type(),
|
allocator_type(str.size()),
|
||||||
OSstream(stream_, str.name(), static_cast<IOstreamOption>(str))
|
OSstream(stream_, str.name(), static_cast<IOstreamOption>(str))
|
||||||
{
|
{}
|
||||||
stream_.reset(str.count());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Member Functions
|
// Member Functions
|
||||||
|
|
||||||
//- \return The number of bytes counted
|
|
||||||
std::streamsize count() const noexcept { return stream_.count(); }
|
|
||||||
|
|
||||||
//- \return The number of bytes counted
|
|
||||||
std::streamsize size() const noexcept { return stream_.count(); }
|
|
||||||
|
|
||||||
//- Reset the count
|
|
||||||
void reset(std::streamsize n = 0) noexcept { stream_.reset(n); }
|
|
||||||
|
|
||||||
//- Rewind the stream, reset the count, clearing any old errors
|
//- Rewind the stream, reset the count, clearing any old errors
|
||||||
virtual void rewind()
|
virtual void rewind()
|
||||||
{
|
{
|
||||||
stream_.reset();
|
allocator_type::rewind();
|
||||||
syncState();
|
setGood(); // resynchronize with internal state
|
||||||
}
|
}
|
||||||
|
|
||||||
//- Print stream description to Ostream
|
//- Print stream description to Ostream
|
||||||
virtual void print(Ostream& os) const;
|
virtual void print(Ostream& os) const;
|
||||||
|
|
||||||
|
|
||||||
|
// Additional constructors and methods (as per v2012 and earlier)
|
||||||
|
#ifdef Foam_IOstream_extras
|
||||||
|
|
||||||
|
//- Construct empty with format
|
||||||
|
explicit OCountStream(IOstreamOption::streamFormat fmt)
|
||||||
|
:
|
||||||
|
OCountStream(IOstreamOption(fmt))
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* Foam_IOstream_extras */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
522
src/OpenFOAM/db/IOstreams/memory/OListStream.H
Normal file
522
src/OpenFOAM/db/IOstreams/memory/OListStream.H
Normal file
@ -0,0 +1,522 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | www.openfoam.com
|
||||||
|
\\/ M anipulation |
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
Copyright (C) 2017-2022 OpenCFD Ltd.
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
License
|
||||||
|
This file is part of OpenFOAM.
|
||||||
|
|
||||||
|
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||||
|
under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Class
|
||||||
|
Foam::OListStream
|
||||||
|
|
||||||
|
Description
|
||||||
|
An output stream that writes to a List and manages the List storage.
|
||||||
|
Similar to OStringStream but with a List for its storage instead of
|
||||||
|
as string to allow reuse of List contents without copying.
|
||||||
|
|
||||||
|
The default list size is 512-bytes with a 256-byte block increment.
|
||||||
|
These values can be changed after construction using the reserve() and
|
||||||
|
the setBlockSize() methods.
|
||||||
|
|
||||||
|
See Also
|
||||||
|
Foam::IListStream
|
||||||
|
Foam::UOListStream
|
||||||
|
Foam::UIListStream
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#ifndef Foam_OListStream_H
|
||||||
|
#define Foam_OListStream_H
|
||||||
|
|
||||||
|
#include "DynamicList.H"
|
||||||
|
#include "OSstream.H"
|
||||||
|
#include "memoryStreamBuffer.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
namespace Foam
|
||||||
|
{
|
||||||
|
|
||||||
|
namespace Detail
|
||||||
|
{
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
Class Detail::OListStreamAllocator Declaration
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
//- An stream/stream-buffer output allocator with DynamicList-like storage
|
||||||
|
class OListStreamAllocator
|
||||||
|
{
|
||||||
|
//- A streambuf adapter with resizing similar to DynamicList
|
||||||
|
class dynbuf
|
||||||
|
:
|
||||||
|
public memorybuf::out
|
||||||
|
{
|
||||||
|
friend class OListStreamAllocator;
|
||||||
|
|
||||||
|
//- Helper for block size - small list minimum of 64 bytes.
|
||||||
|
constexpr static int min_size(int n)
|
||||||
|
{
|
||||||
|
return stdFoam::max(64, n);
|
||||||
|
}
|
||||||
|
|
||||||
|
//- Block size when resizing the list
|
||||||
|
int block_ = 256;
|
||||||
|
|
||||||
|
//- Underlying list storage.
|
||||||
|
// Internally manage like a DynamicList, with its capacity known
|
||||||
|
// from the list size and the addressable size known through the
|
||||||
|
// stream pointers.
|
||||||
|
List<char> storage_;
|
||||||
|
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
//- Increment capacity directly and adjust buffer pointers to
|
||||||
|
//- correspond with the storage size.
|
||||||
|
inline void minCapacity
|
||||||
|
(
|
||||||
|
const std::streamsize n,
|
||||||
|
const std::streamsize cur = 0
|
||||||
|
)
|
||||||
|
{
|
||||||
|
const auto newEnd = n + cur;
|
||||||
|
if (newEnd > storage_.size())
|
||||||
|
{
|
||||||
|
auto newCapacity =
|
||||||
|
(
|
||||||
|
(storage_.size() + block_)
|
||||||
|
- (storage_.size() % block_)
|
||||||
|
);
|
||||||
|
|
||||||
|
while (newCapacity < newEnd)
|
||||||
|
{
|
||||||
|
newCapacity += block_;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Info<<"request:" << newEnd
|
||||||
|
// << " cur cap:" << storage_.size()
|
||||||
|
// << " new cap:" << newCapacity
|
||||||
|
// << " pos:" << cur
|
||||||
|
// << " incr:" << incr << endl;
|
||||||
|
|
||||||
|
storage_.resize(newCapacity);
|
||||||
|
sync_pbuffer();
|
||||||
|
pbump(cur);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//- Define new increment
|
||||||
|
inline void setBlockSize(const int i)
|
||||||
|
{
|
||||||
|
const auto prev = block_;
|
||||||
|
block_ = min_size(i);
|
||||||
|
|
||||||
|
if (block_ > prev)
|
||||||
|
{
|
||||||
|
minCapacity(0, tellp());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//- Handle overflow
|
||||||
|
virtual int overflow(int c = EOF)
|
||||||
|
{
|
||||||
|
if (c != EOF)
|
||||||
|
{
|
||||||
|
// Need another output block
|
||||||
|
minCapacity(block_, tellp());
|
||||||
|
|
||||||
|
*(pptr()) = c;
|
||||||
|
pbump(1);
|
||||||
|
}
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//- Put sequence of characters
|
||||||
|
virtual std::streamsize xsputn(const char* s, std::streamsize n)
|
||||||
|
{
|
||||||
|
// Enough space so that appends work without problem
|
||||||
|
minCapacity(n, tellp());
|
||||||
|
|
||||||
|
std::streamsize count = 0;
|
||||||
|
while (count < n && pptr() < epptr())
|
||||||
|
{
|
||||||
|
*(pptr()) = *(s + count++);
|
||||||
|
pbump(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
//- Initialize put buffer
|
||||||
|
void init_pbuffer(const std::streamsize n)
|
||||||
|
{
|
||||||
|
sync_pbuffer();
|
||||||
|
minCapacity(n);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
// Constructors
|
||||||
|
|
||||||
|
//- Default construct, with initial reserved number of bytes
|
||||||
|
dynbuf(size_t nbytes = 512)
|
||||||
|
:
|
||||||
|
storage_()
|
||||||
|
{
|
||||||
|
init_pbuffer(min_size(nbytes));
|
||||||
|
}
|
||||||
|
|
||||||
|
//- Move construct from List
|
||||||
|
dynbuf(List<char>&& buffer)
|
||||||
|
:
|
||||||
|
storage_(std::move(buffer))
|
||||||
|
{
|
||||||
|
init_pbuffer(block_);
|
||||||
|
}
|
||||||
|
|
||||||
|
//- Move construct from DynamicList.
|
||||||
|
template<int SizeMin>
|
||||||
|
dynbuf(DynamicList<char,SizeMin>&& buffer)
|
||||||
|
:
|
||||||
|
storage_(std::move(buffer))
|
||||||
|
{
|
||||||
|
init_pbuffer(block_);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Member Functions
|
||||||
|
|
||||||
|
//- Return the current list output capacity
|
||||||
|
inline label capacity() const
|
||||||
|
{
|
||||||
|
return storage_.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
//- Sync put buffer pointers to agree with list dimensions
|
||||||
|
// Sets put pointer to the begin (rewind).
|
||||||
|
inline void sync_pbuffer()
|
||||||
|
{
|
||||||
|
resetp(storage_.data(), storage_.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
//- Clear storage
|
||||||
|
inline void clearStorage()
|
||||||
|
{
|
||||||
|
storage_.clear();
|
||||||
|
sync_pbuffer();
|
||||||
|
}
|
||||||
|
|
||||||
|
//- Shrink storage to addressed storage
|
||||||
|
inline void shrink()
|
||||||
|
{
|
||||||
|
const auto cur = tellp(); // Addressed area
|
||||||
|
|
||||||
|
storage_.resize(cur);
|
||||||
|
sync_pbuffer();
|
||||||
|
pbump(cur);
|
||||||
|
}
|
||||||
|
|
||||||
|
//- Transfer list contents to other List
|
||||||
|
inline void swap(List<char>& other)
|
||||||
|
{
|
||||||
|
const auto cur = tellp(); // Addressed area
|
||||||
|
|
||||||
|
storage_.swap(other);
|
||||||
|
storage_.resize(cur);
|
||||||
|
sync_pbuffer();
|
||||||
|
}
|
||||||
|
|
||||||
|
//- Transfer list contents to a DynamicList
|
||||||
|
template<int SizeMin>
|
||||||
|
inline void swap(DynamicList<char,SizeMin>& other)
|
||||||
|
{
|
||||||
|
const auto cur = tellp(); // Addressed area
|
||||||
|
|
||||||
|
storage_.swap(other); // Swap full list
|
||||||
|
other.setCapacity(other.size());
|
||||||
|
other.resize(cur);
|
||||||
|
sync_pbuffer();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
// Protected Data
|
||||||
|
|
||||||
|
typedef std::ostream stream_type;
|
||||||
|
|
||||||
|
//- The stream buffer
|
||||||
|
dynbuf buf_;
|
||||||
|
|
||||||
|
//- The stream
|
||||||
|
stream_type stream_;
|
||||||
|
|
||||||
|
|
||||||
|
// Constructors
|
||||||
|
|
||||||
|
//- Default construct, with initial reserved number of bytes
|
||||||
|
OListStreamAllocator(size_t nbytes = 512)
|
||||||
|
:
|
||||||
|
buf_(nbytes),
|
||||||
|
stream_(&buf_)
|
||||||
|
{}
|
||||||
|
|
||||||
|
//- Move construct from List
|
||||||
|
OListStreamAllocator(List<char>&& buffer)
|
||||||
|
:
|
||||||
|
buf_(std::move(buffer)),
|
||||||
|
stream_(&buf_)
|
||||||
|
{}
|
||||||
|
|
||||||
|
//- Move construct from DynamicList
|
||||||
|
template<int SizeMin>
|
||||||
|
OListStreamAllocator(DynamicList<char,SizeMin>&& buffer)
|
||||||
|
:
|
||||||
|
buf_(std::move(buffer)),
|
||||||
|
stream_(&buf_)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
// Protected Member Functions
|
||||||
|
|
||||||
|
void printBufInfo(Ostream& os) const
|
||||||
|
{
|
||||||
|
os << "put=" << buf_.tellp()
|
||||||
|
<< "/" << buf_.capacity()
|
||||||
|
<< " block=" << buf_.block_;
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
// Member Functions
|
||||||
|
|
||||||
|
//- Const UList access to the characters written (shallow copy).
|
||||||
|
inline const UList<char> list() const
|
||||||
|
{
|
||||||
|
return buf_.list();
|
||||||
|
}
|
||||||
|
|
||||||
|
//- Non-const UList access to the characters written (shallow copy).
|
||||||
|
inline UList<char> list()
|
||||||
|
{
|
||||||
|
return buf_.list();
|
||||||
|
}
|
||||||
|
|
||||||
|
//- The current list output capacity
|
||||||
|
inline label capacity() const
|
||||||
|
{
|
||||||
|
return buf_.capacity();
|
||||||
|
}
|
||||||
|
|
||||||
|
//- The current output position in the buffer,
|
||||||
|
//- which is also the addressed list size
|
||||||
|
inline label size() const
|
||||||
|
{
|
||||||
|
return buf_.tellp();
|
||||||
|
}
|
||||||
|
|
||||||
|
//- Reserve output space for at least this amount.
|
||||||
|
inline void reserve(const std::streamsize n)
|
||||||
|
{
|
||||||
|
// Also maintain current position when resizing
|
||||||
|
const auto cur = buf_.tellp();
|
||||||
|
if (n > cur)
|
||||||
|
{
|
||||||
|
buf_.minCapacity(n - cur, cur);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//- Adjust block size for output
|
||||||
|
inline void setBlockSize(int n)
|
||||||
|
{
|
||||||
|
return buf_.setBlockSize(n);
|
||||||
|
}
|
||||||
|
|
||||||
|
//- Transfer list contents to other List
|
||||||
|
inline void swap(List<char>& other)
|
||||||
|
{
|
||||||
|
buf_.swap(other);
|
||||||
|
}
|
||||||
|
|
||||||
|
//- Transfer list contents to a DynamicList
|
||||||
|
template<int SizeMin>
|
||||||
|
inline void swap(DynamicList<char,SizeMin>& other)
|
||||||
|
{
|
||||||
|
buf_.swap(other);
|
||||||
|
}
|
||||||
|
|
||||||
|
//- Shrink to addressed space, should not affect stream.
|
||||||
|
inline void shrink()
|
||||||
|
{
|
||||||
|
buf_.shrink();
|
||||||
|
}
|
||||||
|
|
||||||
|
//- Clear storage
|
||||||
|
void clearStorage()
|
||||||
|
{
|
||||||
|
buf_.clearStorage();
|
||||||
|
stream_.clear(); // for safety, clear any old errors
|
||||||
|
}
|
||||||
|
|
||||||
|
//- Move to buffer start, clear errors
|
||||||
|
void rewind()
|
||||||
|
{
|
||||||
|
buf_.pubseekpos(0, std::ios_base::out);
|
||||||
|
stream_.clear(); // for safety, clear any old errors
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // End namespace Detail
|
||||||
|
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
Class OListStream Declaration
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
//- An OSstream attached to a List
|
||||||
|
class OListStream
|
||||||
|
:
|
||||||
|
public Detail::OListStreamAllocator,
|
||||||
|
public OSstream
|
||||||
|
{
|
||||||
|
typedef Detail::OListStreamAllocator allocator_type;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
// Constructors
|
||||||
|
|
||||||
|
//- Default construct (empty output)
|
||||||
|
explicit OListStream
|
||||||
|
(
|
||||||
|
IOstreamOption streamOpt = IOstreamOption()
|
||||||
|
)
|
||||||
|
:
|
||||||
|
allocator_type(),
|
||||||
|
OSstream(stream_, "output", streamOpt.format(), streamOpt.version())
|
||||||
|
{}
|
||||||
|
|
||||||
|
//- Construct with initial reserved number of bytes
|
||||||
|
explicit OListStream
|
||||||
|
(
|
||||||
|
size_t nbytes,
|
||||||
|
IOstreamOption streamOpt = IOstreamOption()
|
||||||
|
)
|
||||||
|
:
|
||||||
|
allocator_type(nbytes),
|
||||||
|
OSstream(stream_, "output", streamOpt.format(), streamOpt.version())
|
||||||
|
{}
|
||||||
|
|
||||||
|
//- Move construct from an existing List
|
||||||
|
explicit OListStream
|
||||||
|
(
|
||||||
|
List<char>&& buffer,
|
||||||
|
IOstreamOption streamOpt = IOstreamOption()
|
||||||
|
)
|
||||||
|
:
|
||||||
|
allocator_type(std::move(buffer)),
|
||||||
|
OSstream(stream_, "output", streamOpt.format(), streamOpt.version())
|
||||||
|
{}
|
||||||
|
|
||||||
|
//- Move construct from an existing DynamicList
|
||||||
|
template<int SizeMin>
|
||||||
|
explicit OListStream
|
||||||
|
(
|
||||||
|
DynamicList<char,SizeMin>&& buffer,
|
||||||
|
IOstreamOption streamOpt = IOstreamOption()
|
||||||
|
)
|
||||||
|
:
|
||||||
|
allocator_type(std::move(buffer)),
|
||||||
|
OSstream(stream_, "output", streamOpt.format(), streamOpt.version())
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
// Member Functions
|
||||||
|
|
||||||
|
//- Rewind the stream, clearing any old errors
|
||||||
|
virtual void rewind()
|
||||||
|
{
|
||||||
|
allocator_type::rewind();
|
||||||
|
setGood(); // resynchronize with internal state
|
||||||
|
}
|
||||||
|
|
||||||
|
//- Print stream description to Ostream
|
||||||
|
virtual void print(Ostream& os) const;
|
||||||
|
|
||||||
|
|
||||||
|
// Additional constructors and methods (as per v2012 and earlier)
|
||||||
|
#ifdef Foam_IOstream_extras
|
||||||
|
|
||||||
|
//- Default construct (empty output)
|
||||||
|
explicit OListStream
|
||||||
|
(
|
||||||
|
IOstreamOption::streamFormat fmt
|
||||||
|
)
|
||||||
|
:
|
||||||
|
OListStream(IOstreamOption(fmt))
|
||||||
|
{}
|
||||||
|
|
||||||
|
//- Construct with initial reserved number of bytes
|
||||||
|
explicit OListStream
|
||||||
|
(
|
||||||
|
size_t nbytes,
|
||||||
|
IOstreamOption::streamFormat fmt
|
||||||
|
)
|
||||||
|
:
|
||||||
|
OListStream(nbytes, IOstreamOption(fmt))
|
||||||
|
{}
|
||||||
|
|
||||||
|
//- Move construct from an existing List
|
||||||
|
OListStream
|
||||||
|
(
|
||||||
|
List<char>&& buffer,
|
||||||
|
IOstreamOption::streamFormat fmt
|
||||||
|
)
|
||||||
|
:
|
||||||
|
OListStream(std::move(buffer), IOstreamOption(fmt))
|
||||||
|
{}
|
||||||
|
|
||||||
|
//- Move construct from an existing DynamicList
|
||||||
|
template<int SizeMin>
|
||||||
|
OListStream
|
||||||
|
(
|
||||||
|
DynamicList<char,SizeMin>&& buffer,
|
||||||
|
IOstreamOption::streamFormat fmt
|
||||||
|
)
|
||||||
|
:
|
||||||
|
OListStream(std::move(buffer), IOstreamOption(fmt))
|
||||||
|
{}
|
||||||
|
|
||||||
|
#endif /* Foam_IOstream_extras */
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
} // End namespace Foam
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
@ -1,358 +0,0 @@
|
|||||||
/*---------------------------------------------------------------------------*\
|
|
||||||
========= |
|
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
|
||||||
\\ / O peration |
|
|
||||||
\\ / A nd | www.openfoam.com
|
|
||||||
\\/ M anipulation |
|
|
||||||
-------------------------------------------------------------------------------
|
|
||||||
Copyright (C) 2016-2023 OpenCFD Ltd.
|
|
||||||
-------------------------------------------------------------------------------
|
|
||||||
License
|
|
||||||
This file is part of OpenFOAM.
|
|
||||||
|
|
||||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
|
||||||
under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
||||||
for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
Class
|
|
||||||
Foam::OSpanStream
|
|
||||||
|
|
||||||
Description
|
|
||||||
Similar to OStringStream but using an externally managed buffer for
|
|
||||||
its output.
|
|
||||||
|
|
||||||
This allows the output buffer to be reused and can make it easier when
|
|
||||||
writing out data. It is the user's responsibility to ensure proper
|
|
||||||
synchronization in the sizes. Provided that the external buffer is large
|
|
||||||
enough that overflow does not occur, the following usage pattern
|
|
||||||
works.
|
|
||||||
|
|
||||||
\code
|
|
||||||
DynamicList<char> buffer(4096); // allocate some large buffer
|
|
||||||
|
|
||||||
{
|
|
||||||
OSpanStream os(buffer);
|
|
||||||
os << "content1" << " and more content";
|
|
||||||
buffer.resize(os.size()); // synchronize sizes
|
|
||||||
}
|
|
||||||
|
|
||||||
something.write(buffer, buffer.size());
|
|
||||||
\endcode
|
|
||||||
|
|
||||||
Although the OSpanStream is quite lightweight, there may be cases
|
|
||||||
where it is preferable to reuse the stream as well.
|
|
||||||
\code
|
|
||||||
DynamicList<char> buffer(4096); // allocate some large buffer
|
|
||||||
|
|
||||||
OSpanStream os(buffer);
|
|
||||||
os << "content1" << " and more content";
|
|
||||||
buffer.resize(os.size()); // synchronize sizes
|
|
||||||
|
|
||||||
something.write(buffer, buffer.size());
|
|
||||||
|
|
||||||
os.rewind();
|
|
||||||
os << "content2";
|
|
||||||
buffer.resize(os.size()); // synchronize sizes
|
|
||||||
|
|
||||||
something.write(buffer, buffer.size());
|
|
||||||
|
|
||||||
// or simply using the output size directly (without sync)
|
|
||||||
os.rewind();
|
|
||||||
os << "content3";
|
|
||||||
|
|
||||||
something.write(buffer, os.size());
|
|
||||||
\endcode
|
|
||||||
|
|
||||||
See Also
|
|
||||||
Foam::ICharStream
|
|
||||||
Foam::ISpanStream
|
|
||||||
Foam::OCharStream
|
|
||||||
|
|
||||||
\*---------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
#ifndef Foam_OSpanStream_H
|
|
||||||
#define Foam_OSpanStream_H
|
|
||||||
|
|
||||||
#include "memoryStreamBuffer.H"
|
|
||||||
#include "DynamicList.H"
|
|
||||||
#include "OSstream.H"
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
namespace Foam
|
|
||||||
{
|
|
||||||
|
|
||||||
// Forward Declarations
|
|
||||||
class ospanstream;
|
|
||||||
class OSpanStream;
|
|
||||||
|
|
||||||
// Older names (prior to 2023-08)
|
|
||||||
typedef OSpanStream UOListStream;
|
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*\
|
|
||||||
Class ospanstream Declaration
|
|
||||||
\*---------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
//- Similar to std::ostringstream, but with an externally managed output buffer
|
|
||||||
//- which makes it most similar to std::ospanstream (C++23)
|
|
||||||
class ospanstream
|
|
||||||
:
|
|
||||||
virtual public std::ios,
|
|
||||||
protected Foam::memorybuf::out_base,
|
|
||||||
public std::ostream
|
|
||||||
{
|
|
||||||
typedef Foam::memorybuf::out_base buffer_type;
|
|
||||||
typedef std::ostream stream_type;
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
// Constructors
|
|
||||||
|
|
||||||
//- Default construct - empty
|
|
||||||
ospanstream()
|
|
||||||
:
|
|
||||||
buffer_type(),
|
|
||||||
stream_type(static_cast<buffer_type*>(this))
|
|
||||||
{}
|
|
||||||
|
|
||||||
//- Construct for character array and number of bytes
|
|
||||||
ospanstream(char* buffer, size_t nbytes)
|
|
||||||
:
|
|
||||||
buffer_type(buffer, nbytes),
|
|
||||||
stream_type(static_cast<buffer_type*>(this))
|
|
||||||
{}
|
|
||||||
|
|
||||||
// //- Construct (shallow copy) from span character content
|
|
||||||
// ospanstream(stdFoam::span<char> s)
|
|
||||||
// :
|
|
||||||
// buffer_type(const_cast<char*>(s.data()), s.size()),
|
|
||||||
// stream_type(static_cast<buffer_type*>(this))
|
|
||||||
// {}
|
|
||||||
|
|
||||||
|
|
||||||
// Member Functions
|
|
||||||
|
|
||||||
//- The current output position within the buffer (tellp)
|
|
||||||
std::streampos output_pos() const
|
|
||||||
{
|
|
||||||
return buffer_type::span_tellp();
|
|
||||||
}
|
|
||||||
|
|
||||||
//- The put buffer capacity
|
|
||||||
std::streamsize capacity() const
|
|
||||||
{
|
|
||||||
return buffer_type::span_capacity();
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Span of the current output characters (is modifiable!)
|
|
||||||
UList<char> list() const
|
|
||||||
{
|
|
||||||
return buffer_type::span_list();
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Rewind the stream, clearing any old errors
|
|
||||||
void rewind()
|
|
||||||
{
|
|
||||||
buffer_type::pubseekpos(0, std::ios_base::out);
|
|
||||||
stream_type::clear(); // Clear any old errors
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Reset the put buffer area
|
|
||||||
void reset(char* buffer, size_t nbytes)
|
|
||||||
{
|
|
||||||
buffer_type::resetp(buffer, nbytes);
|
|
||||||
stream_type::clear(); // Clear any old errors
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Reset the put buffer area to use the data area from a string
|
|
||||||
void reset(std::string& s)
|
|
||||||
{
|
|
||||||
s.resize(s.capacity());
|
|
||||||
buffer_type::resetp(&s[0], s.size());
|
|
||||||
stream_type::clear(); // Clear any old errors
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Some information about the output buffer position/capacity
|
|
||||||
void debug_info(Ostream& os) const
|
|
||||||
{
|
|
||||||
os << "put="
|
|
||||||
<< output_pos() << '/' << capacity();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
namespace Detail
|
|
||||||
{
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*\
|
|
||||||
Class Detail::OSpanStreamAllocator Declaration
|
|
||||||
\*---------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
//- An allocator for holding Foam::ospanstream
|
|
||||||
class OSpanStreamAllocator
|
|
||||||
{
|
|
||||||
protected:
|
|
||||||
|
|
||||||
// Protected Data
|
|
||||||
|
|
||||||
//- The stream
|
|
||||||
Foam::ospanstream stream_;
|
|
||||||
|
|
||||||
|
|
||||||
// Constructors
|
|
||||||
|
|
||||||
//- Default construct (empty)
|
|
||||||
OSpanStreamAllocator() = default;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // End namespace Detail
|
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*\
|
|
||||||
Class OSpanStream Declaration
|
|
||||||
\*---------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
//- An OSstream attached to an unallocated external buffer
|
|
||||||
class OSpanStream
|
|
||||||
:
|
|
||||||
public Detail::OSpanStreamAllocator,
|
|
||||||
public Foam::OSstream
|
|
||||||
{
|
|
||||||
typedef Detail::OSpanStreamAllocator allocator_type;
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
// Constructors
|
|
||||||
|
|
||||||
//- Default construct (empty output)
|
|
||||||
explicit OSpanStream
|
|
||||||
(
|
|
||||||
IOstreamOption streamOpt = IOstreamOption()
|
|
||||||
)
|
|
||||||
:
|
|
||||||
allocator_type(),
|
|
||||||
OSstream(stream_, "output", streamOpt.format(), streamOpt.version())
|
|
||||||
{}
|
|
||||||
|
|
||||||
//- Use data area from string content
|
|
||||||
explicit OSpanStream
|
|
||||||
(
|
|
||||||
std::string& buffer,
|
|
||||||
IOstreamOption streamOpt = IOstreamOption()
|
|
||||||
)
|
|
||||||
:
|
|
||||||
OSpanStream(streamOpt)
|
|
||||||
{
|
|
||||||
stream_.reset(buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Construct using specified buffer and number of bytes
|
|
||||||
OSpanStream
|
|
||||||
(
|
|
||||||
char* buffer,
|
|
||||||
size_t nbytes,
|
|
||||||
IOstreamOption streamOpt = IOstreamOption()
|
|
||||||
)
|
|
||||||
:
|
|
||||||
OSpanStream(streamOpt)
|
|
||||||
{
|
|
||||||
stream_.reset(buffer, nbytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Construct using data area from a List and number of bytes
|
|
||||||
OSpanStream
|
|
||||||
(
|
|
||||||
::Foam::UList<char>& buffer,
|
|
||||||
size_t nbytes,
|
|
||||||
IOstreamOption streamOpt = IOstreamOption()
|
|
||||||
)
|
|
||||||
:
|
|
||||||
OSpanStream(buffer.data(), nbytes, streamOpt)
|
|
||||||
{}
|
|
||||||
|
|
||||||
//- Construct using data area from a List and its inherent storage size
|
|
||||||
explicit OSpanStream
|
|
||||||
(
|
|
||||||
::Foam::UList<char>& buffer,
|
|
||||||
IOstreamOption streamOpt = IOstreamOption()
|
|
||||||
)
|
|
||||||
:
|
|
||||||
OSpanStream(buffer.data(), buffer.size(), streamOpt)
|
|
||||||
{}
|
|
||||||
|
|
||||||
//- Construct using full data area from DynamicList
|
|
||||||
template<int SizeMin>
|
|
||||||
explicit OSpanStream
|
|
||||||
(
|
|
||||||
::Foam::DynamicList<char,SizeMin>& buffer,
|
|
||||||
IOstreamOption streamOpt = IOstreamOption()
|
|
||||||
)
|
|
||||||
:
|
|
||||||
OSpanStream(buffer.data(), buffer.capacity(), streamOpt)
|
|
||||||
{
|
|
||||||
buffer.resize(buffer.capacity()); // Uses entire space
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Member Functions
|
|
||||||
|
|
||||||
//- Position of the put buffer
|
|
||||||
std::streampos tellp() const { return stream_.output_pos(); }
|
|
||||||
|
|
||||||
//- The current output position within the buffer (tellp)
|
|
||||||
std::streampos output_pos() const { return stream_.output_pos(); }
|
|
||||||
|
|
||||||
//- The current output size. Same as tellp(), output_pos()
|
|
||||||
label size() const { return label(stream_.output_pos()); }
|
|
||||||
|
|
||||||
//- The put buffer capacity
|
|
||||||
std::streamsize capacity() const { return stream_.capacity(); }
|
|
||||||
|
|
||||||
//- Span of the current output characters (is modifiable!)
|
|
||||||
UList<char> list() const { return stream_.list(); }
|
|
||||||
|
|
||||||
//- Reset the put area
|
|
||||||
void reset(char* buffer, size_t nbytes)
|
|
||||||
{
|
|
||||||
stream_.reset(buffer, nbytes);
|
|
||||||
syncState();
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Reset the put buffer area to use the data area from a string
|
|
||||||
void reset(std::string& s)
|
|
||||||
{
|
|
||||||
stream_.reset(s);
|
|
||||||
syncState();
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Rewind the stream, clearing any old errors
|
|
||||||
virtual void rewind()
|
|
||||||
{
|
|
||||||
stream_.rewind();
|
|
||||||
syncState();
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Print stream description to Ostream
|
|
||||||
virtual void print(Ostream& os) const;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
} // End namespace Foam
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// ************************************************************************* //
|
|
||||||
326
src/OpenFOAM/db/IOstreams/memory/UIListStream.H
Normal file
326
src/OpenFOAM/db/IOstreams/memory/UIListStream.H
Normal file
@ -0,0 +1,326 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | www.openfoam.com
|
||||||
|
\\/ M anipulation |
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
Copyright (C) 2016-2022 OpenCFD Ltd.
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
License
|
||||||
|
This file is part of OpenFOAM.
|
||||||
|
|
||||||
|
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||||
|
under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Class
|
||||||
|
Foam::UIListStream
|
||||||
|
|
||||||
|
Description
|
||||||
|
Similar to IStringStream but using an externally managed buffer for its
|
||||||
|
input. This allows the input buffer to be filled (and refilled) from
|
||||||
|
various sources.
|
||||||
|
|
||||||
|
Note that this stream will normally be used as a "one-shot" reader.
|
||||||
|
Caution must be exercised that the referenced buffer remains valid and
|
||||||
|
without any intermediate resizing for the duration of the stream's use.
|
||||||
|
|
||||||
|
An example of possible use:
|
||||||
|
\code
|
||||||
|
DynamicList<char> buffer(4096); // allocate some large buffer
|
||||||
|
|
||||||
|
nread = something.read(buffer.data(),1024); // fill with content
|
||||||
|
buffer.resize(nread); // content size
|
||||||
|
|
||||||
|
// Construct dictionary, or something else
|
||||||
|
UIListStream is(buffer)
|
||||||
|
dictionary dict1(is);
|
||||||
|
|
||||||
|
// Sometime later
|
||||||
|
nread = something.read(buffer.data(),2048); // fill with content
|
||||||
|
buffer.resize(nread); // content size
|
||||||
|
|
||||||
|
// Without intermediate variable
|
||||||
|
dictionary dict2(UIListStream(buffer)());
|
||||||
|
\endcode
|
||||||
|
|
||||||
|
See Also
|
||||||
|
Foam::IListStream
|
||||||
|
Foam::OListStream
|
||||||
|
Foam::UOListStream
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#ifndef Foam_UIListStream_H
|
||||||
|
#define Foam_UIListStream_H
|
||||||
|
|
||||||
|
#include "UList.H"
|
||||||
|
#include "ISstream.H"
|
||||||
|
#include "memoryStreamBuffer.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
namespace Foam
|
||||||
|
{
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
Class uiliststream Declaration
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
//- Similar to std::istringstream, but with an externally managed input buffer.
|
||||||
|
// This allows the input buffer to be filled or refilled from various sources
|
||||||
|
// without copying.
|
||||||
|
class uiliststream
|
||||||
|
:
|
||||||
|
virtual public std::ios,
|
||||||
|
protected memorybuf::in,
|
||||||
|
public std::istream
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
//- Construct for character array and number of bytes
|
||||||
|
uiliststream(const char* buffer, size_t nbytes)
|
||||||
|
:
|
||||||
|
memorybuf::in(const_cast<char*>(buffer), nbytes),
|
||||||
|
std::istream(static_cast<memorybuf::in*>(this))
|
||||||
|
{}
|
||||||
|
|
||||||
|
//- Reset buffer pointers
|
||||||
|
inline void reset(char *buffer, size_t nbytes)
|
||||||
|
{
|
||||||
|
resetg(buffer, nbytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
//- Rewind the stream, clearing any old errors
|
||||||
|
void rewind()
|
||||||
|
{
|
||||||
|
this->pubseekpos(0, std::ios_base::in);
|
||||||
|
clear(); // for safety, clear any old errors
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
namespace Detail
|
||||||
|
{
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
Class Detail::UIListStreamAllocator Declaration
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
//- An stream/stream-buffer input allocator for a externally allocated list
|
||||||
|
class UIListStreamAllocator
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
|
||||||
|
// Protected Data
|
||||||
|
|
||||||
|
typedef std::istream stream_type;
|
||||||
|
|
||||||
|
//- The stream buffer
|
||||||
|
memorybuf::in buf_;
|
||||||
|
|
||||||
|
//- The stream
|
||||||
|
stream_type stream_;
|
||||||
|
|
||||||
|
|
||||||
|
// Constructors
|
||||||
|
|
||||||
|
//- Construct for character array and number of bytes
|
||||||
|
UIListStreamAllocator(char* buffer, size_t nbytes)
|
||||||
|
:
|
||||||
|
buf_(buffer, nbytes),
|
||||||
|
stream_(&buf_)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
// Protected Member Functions
|
||||||
|
|
||||||
|
//- Reset buffer pointers
|
||||||
|
inline void reset(char* buffer, size_t nbytes)
|
||||||
|
{
|
||||||
|
buf_.resetg(buffer, nbytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
void printBufInfo(Ostream& os) const
|
||||||
|
{
|
||||||
|
buf_.printBufInfo(os);
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
// Member Functions
|
||||||
|
|
||||||
|
//- Const UList access to the input characters (shallow copy).
|
||||||
|
inline const UList<char> list() const
|
||||||
|
{
|
||||||
|
return buf_.list();
|
||||||
|
}
|
||||||
|
|
||||||
|
//- Non-const UList access to the input characters (shallow copy).
|
||||||
|
inline UList<char> list()
|
||||||
|
{
|
||||||
|
return buf_.list();
|
||||||
|
}
|
||||||
|
|
||||||
|
//- The list size
|
||||||
|
inline label size() const
|
||||||
|
{
|
||||||
|
return buf_.capacity();
|
||||||
|
}
|
||||||
|
|
||||||
|
//- Position of the get buffer
|
||||||
|
std::streampos tellg() const
|
||||||
|
{
|
||||||
|
return buf_.tellg();
|
||||||
|
}
|
||||||
|
|
||||||
|
//- Move to buffer start, clear errors
|
||||||
|
void rewind()
|
||||||
|
{
|
||||||
|
buf_.pubseekpos(0, std::ios_base::in);
|
||||||
|
stream_.clear(); // for safety, clear any old errors
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // End namespace Detail
|
||||||
|
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
Class UIListStream Declaration
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
class UIListStream
|
||||||
|
:
|
||||||
|
public Detail::UIListStreamAllocator,
|
||||||
|
public ISstream
|
||||||
|
{
|
||||||
|
typedef Detail::UIListStreamAllocator allocator_type;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
// Constructors
|
||||||
|
|
||||||
|
//- Construct using specified buffer and number of bytes
|
||||||
|
UIListStream
|
||||||
|
(
|
||||||
|
const char* buffer,
|
||||||
|
size_t nbytes,
|
||||||
|
IOstreamOption streamOpt = IOstreamOption()
|
||||||
|
)
|
||||||
|
:
|
||||||
|
allocator_type(const_cast<char*>(buffer), nbytes),
|
||||||
|
ISstream(stream_, "input", streamOpt.format(), streamOpt.version())
|
||||||
|
{}
|
||||||
|
|
||||||
|
//- Construct using data area from a List and number of bytes
|
||||||
|
UIListStream
|
||||||
|
(
|
||||||
|
const UList<char>& buffer,
|
||||||
|
size_t nbytes,
|
||||||
|
IOstreamOption streamOpt = IOstreamOption()
|
||||||
|
)
|
||||||
|
:
|
||||||
|
UIListStream(buffer.cdata(), nbytes, streamOpt)
|
||||||
|
{}
|
||||||
|
|
||||||
|
//- Construct using data area from a List and its inherent storage size
|
||||||
|
// Uses addressed size, thus no special treatment for a DynamicList
|
||||||
|
explicit UIListStream
|
||||||
|
(
|
||||||
|
const UList<char>& buffer,
|
||||||
|
IOstreamOption streamOpt = IOstreamOption()
|
||||||
|
)
|
||||||
|
:
|
||||||
|
UIListStream(buffer.cdata(), buffer.size(), streamOpt)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
// Member Functions
|
||||||
|
|
||||||
|
//- Return the current get position in the buffer
|
||||||
|
std::streampos pos() const
|
||||||
|
{
|
||||||
|
return allocator_type::tellg();
|
||||||
|
}
|
||||||
|
|
||||||
|
//- Rewind the stream, clearing any old errors
|
||||||
|
virtual void rewind()
|
||||||
|
{
|
||||||
|
allocator_type::rewind();
|
||||||
|
setGood(); // resynchronize with internal state
|
||||||
|
}
|
||||||
|
|
||||||
|
//- Print stream description to Ostream
|
||||||
|
virtual void print(Ostream& os) const;
|
||||||
|
|
||||||
|
|
||||||
|
// Member Operators
|
||||||
|
|
||||||
|
//- A non-const reference to const Istream
|
||||||
|
// Needed for read-constructors where the stream argument is temporary
|
||||||
|
Istream& operator()() const
|
||||||
|
{
|
||||||
|
// Could also rewind
|
||||||
|
return const_cast<UIListStream&>(*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Additional constructors and methods (as per v2012 and earlier)
|
||||||
|
#ifdef Foam_IOstream_extras
|
||||||
|
|
||||||
|
//- Construct using specified buffer and number of bytes
|
||||||
|
UIListStream
|
||||||
|
(
|
||||||
|
const char* buffer,
|
||||||
|
size_t nbytes,
|
||||||
|
IOstreamOption::streamFormat fmt
|
||||||
|
)
|
||||||
|
:
|
||||||
|
UIListStream(buffer, nbytes, IOstreamOption(fmt))
|
||||||
|
{}
|
||||||
|
|
||||||
|
//- Construct using data area from a List and number of bytes
|
||||||
|
UIListStream
|
||||||
|
(
|
||||||
|
const UList<char>& buffer,
|
||||||
|
size_t nbytes,
|
||||||
|
IOstreamOption::streamFormat fmt
|
||||||
|
)
|
||||||
|
:
|
||||||
|
UIListStream(buffer.cdata(), nbytes, IOstreamOption(fmt))
|
||||||
|
{}
|
||||||
|
|
||||||
|
//- Construct using data area from a List and its inherent storage size
|
||||||
|
// Uses addressed size, thus no special treatment for a DynamicList
|
||||||
|
UIListStream
|
||||||
|
(
|
||||||
|
const UList<char>& buf,
|
||||||
|
IOstreamOption::streamFormat fmt
|
||||||
|
)
|
||||||
|
:
|
||||||
|
UIListStream(buf.cdata(), buf.size(), IOstreamOption(fmt))
|
||||||
|
{}
|
||||||
|
|
||||||
|
#endif /* Foam_IOstream_extras */
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
} // End namespace Foam
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
39
src/OpenFOAM/db/IOstreams/memory/UListStream.H
Normal file
39
src/OpenFOAM/db/IOstreams/memory/UListStream.H
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | www.openfoam.com
|
||||||
|
\\/ M anipulation |
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
Copyright (C) 2017 OpenCFD Ltd.
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
License
|
||||||
|
This file is part of OpenFOAM.
|
||||||
|
|
||||||
|
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||||
|
under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Description
|
||||||
|
Input/output streams with externally managed storage.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#ifndef UListStream_H
|
||||||
|
#define UListStream_H
|
||||||
|
|
||||||
|
#include "UIListStream.H"
|
||||||
|
#include "UOListStream.H"
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
326
src/OpenFOAM/db/IOstreams/memory/UOListStream.H
Normal file
326
src/OpenFOAM/db/IOstreams/memory/UOListStream.H
Normal file
@ -0,0 +1,326 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | www.openfoam.com
|
||||||
|
\\/ M anipulation |
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
Copyright (C) 2016-2022 OpenCFD Ltd.
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
License
|
||||||
|
This file is part of OpenFOAM.
|
||||||
|
|
||||||
|
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||||
|
under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Class
|
||||||
|
Foam::UOListStream
|
||||||
|
|
||||||
|
Description
|
||||||
|
Similar to OStringStream but using an externally managed buffer for
|
||||||
|
its output.
|
||||||
|
|
||||||
|
This allows the output buffer to be reused and can make it easier when
|
||||||
|
writing out data. It is the user's responsibility to ensure proper
|
||||||
|
synchronization in the sizes. Provided that the external buffer is large
|
||||||
|
enough that overflow does not occur, the following usage pattern
|
||||||
|
works.
|
||||||
|
|
||||||
|
\code
|
||||||
|
DynamicList<char> buffer(4096); // allocate some large buffer
|
||||||
|
|
||||||
|
{
|
||||||
|
UOListStream os(buffer);
|
||||||
|
os << "content1" << " and more content";
|
||||||
|
buffer.resize(os.size()); // synchronize sizes
|
||||||
|
}
|
||||||
|
|
||||||
|
something.write(buffer, buffer.size());
|
||||||
|
\endcode
|
||||||
|
|
||||||
|
Although the UOListStream is quite lightweight, there may be cases
|
||||||
|
where it is preferable to reuse the stream as well.
|
||||||
|
\code
|
||||||
|
DynamicList<char> buffer(4096); // allocate some large buffer
|
||||||
|
|
||||||
|
UOListStream os(buffer);
|
||||||
|
os << "content1" << " and more content";
|
||||||
|
buffer.resize(os.size()); // synchronize sizes
|
||||||
|
|
||||||
|
something.write(buffer, buffer.size());
|
||||||
|
|
||||||
|
os.rewind();
|
||||||
|
os << "content2";
|
||||||
|
buffer.resize(os.size()); // synchronize sizes
|
||||||
|
|
||||||
|
something.write(buffer, buffer.size());
|
||||||
|
|
||||||
|
// or simply using the output size directly (without sync)
|
||||||
|
os.rewind();
|
||||||
|
os << "content3";
|
||||||
|
|
||||||
|
something.write(buffer, os.size());
|
||||||
|
\endcode
|
||||||
|
|
||||||
|
See Also
|
||||||
|
Foam::IListStream
|
||||||
|
Foam::OListStream
|
||||||
|
Foam::UIListStream
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#ifndef Foam_UOListStream_H
|
||||||
|
#define Foam_UOListStream_H
|
||||||
|
|
||||||
|
#include "DynamicList.H"
|
||||||
|
#include "FixedList.H"
|
||||||
|
#include "OSstream.H"
|
||||||
|
#include "memoryStreamBuffer.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
namespace Foam
|
||||||
|
{
|
||||||
|
|
||||||
|
namespace Detail
|
||||||
|
{
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
Class Detail::UOListStreamAllocator Declaration
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
//- An stream/stream-buffer allocator for external buffers
|
||||||
|
class UOListStreamAllocator
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
|
||||||
|
// Protected Data
|
||||||
|
|
||||||
|
typedef std::ostream stream_type;
|
||||||
|
|
||||||
|
//- The stream buffer
|
||||||
|
memorybuf::out buf_;
|
||||||
|
|
||||||
|
//- The stream
|
||||||
|
stream_type stream_;
|
||||||
|
|
||||||
|
|
||||||
|
// Constructors
|
||||||
|
|
||||||
|
//- Construct for character array and number of bytes
|
||||||
|
UOListStreamAllocator(char* buffer, size_t nbytes)
|
||||||
|
:
|
||||||
|
buf_(buffer, nbytes),
|
||||||
|
stream_(&buf_)
|
||||||
|
{}
|
||||||
|
|
||||||
|
void printBufInfo(Ostream& os) const
|
||||||
|
{
|
||||||
|
buf_.printBufInfo(os);
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
// Member Functions
|
||||||
|
|
||||||
|
//- Const UList access to the characters written (shallow copy).
|
||||||
|
inline const UList<char> list() const
|
||||||
|
{
|
||||||
|
return buf_.list();
|
||||||
|
}
|
||||||
|
|
||||||
|
//- Non-const UList access to the characters written (shallow copy).
|
||||||
|
inline UList<char> list()
|
||||||
|
{
|
||||||
|
return buf_.list();
|
||||||
|
}
|
||||||
|
|
||||||
|
//- The current list output capacity
|
||||||
|
inline label capacity() const
|
||||||
|
{
|
||||||
|
return buf_.capacity();
|
||||||
|
}
|
||||||
|
|
||||||
|
//- The current output position in the buffer,
|
||||||
|
//- which is also the addressed list size
|
||||||
|
inline label size() const
|
||||||
|
{
|
||||||
|
return buf_.tellp();
|
||||||
|
}
|
||||||
|
|
||||||
|
//- Move to buffer start, clear errors
|
||||||
|
void rewind()
|
||||||
|
{
|
||||||
|
buf_.pubseekpos(0, std::ios_base::out);
|
||||||
|
stream_.clear(); // for safety, clear any old errors
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // End namespace Detail
|
||||||
|
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
Class UOListStream Declaration
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
//- An OSstream attached to an unallocated external buffer
|
||||||
|
class UOListStream
|
||||||
|
:
|
||||||
|
public Detail::UOListStreamAllocator,
|
||||||
|
public OSstream
|
||||||
|
{
|
||||||
|
typedef Detail::UOListStreamAllocator allocator_type;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
// Constructors
|
||||||
|
|
||||||
|
//- Construct using specified buffer and number of bytes
|
||||||
|
UOListStream
|
||||||
|
(
|
||||||
|
char* buffer,
|
||||||
|
size_t nbytes,
|
||||||
|
IOstreamOption streamOpt = IOstreamOption()
|
||||||
|
)
|
||||||
|
:
|
||||||
|
allocator_type(buffer, nbytes),
|
||||||
|
OSstream(stream_, "output", streamOpt.format(), streamOpt.version())
|
||||||
|
{}
|
||||||
|
|
||||||
|
//- Construct using data area from a List and number of bytes
|
||||||
|
UOListStream
|
||||||
|
(
|
||||||
|
UList<char>& buffer,
|
||||||
|
size_t nbytes,
|
||||||
|
IOstreamOption streamOpt = IOstreamOption()
|
||||||
|
)
|
||||||
|
:
|
||||||
|
UOListStream(buffer.data(), nbytes, streamOpt)
|
||||||
|
{}
|
||||||
|
|
||||||
|
//- Construct using data area from a List and its inherent storage size
|
||||||
|
explicit UOListStream
|
||||||
|
(
|
||||||
|
UList<char>& buffer,
|
||||||
|
IOstreamOption streamOpt = IOstreamOption()
|
||||||
|
)
|
||||||
|
:
|
||||||
|
UOListStream(buffer.data(), buffer.size(), streamOpt)
|
||||||
|
{}
|
||||||
|
|
||||||
|
//- Construct using data area from a FixedList
|
||||||
|
template<unsigned N>
|
||||||
|
explicit UOListStream
|
||||||
|
(
|
||||||
|
FixedList<char, N>& buffer,
|
||||||
|
IOstreamOption streamOpt = IOstreamOption()
|
||||||
|
)
|
||||||
|
:
|
||||||
|
UOListStream(buffer.data(), N, streamOpt)
|
||||||
|
{}
|
||||||
|
|
||||||
|
//- Construct using data area from a DynamicList and its capacity
|
||||||
|
template<int SizeMin>
|
||||||
|
explicit UOListStream
|
||||||
|
(
|
||||||
|
DynamicList<char,SizeMin>& buffer,
|
||||||
|
IOstreamOption streamOpt = IOstreamOption()
|
||||||
|
)
|
||||||
|
:
|
||||||
|
UOListStream(buffer.data(), buffer.capacity(), streamOpt)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
// Member Functions
|
||||||
|
|
||||||
|
//- Rewind the stream, clearing any old errors
|
||||||
|
virtual void rewind()
|
||||||
|
{
|
||||||
|
allocator_type::rewind();
|
||||||
|
setGood(); // resynchronize with internal state
|
||||||
|
}
|
||||||
|
|
||||||
|
//- Print stream description to Ostream
|
||||||
|
virtual void print(Ostream& os) const;
|
||||||
|
|
||||||
|
|
||||||
|
// Additional constructors and methods (as per v2012 and earlier)
|
||||||
|
#ifdef Foam_IOstream_extras
|
||||||
|
|
||||||
|
//- Construct using specified buffer and number of bytes
|
||||||
|
UOListStream
|
||||||
|
(
|
||||||
|
char* buffer,
|
||||||
|
size_t nbytes,
|
||||||
|
IOstreamOption::streamFormat fmt
|
||||||
|
)
|
||||||
|
:
|
||||||
|
UOListStream(buffer, nbytes, IOstreamOption(fmt))
|
||||||
|
{}
|
||||||
|
|
||||||
|
//- Construct using data area from a List and number of bytes
|
||||||
|
UOListStream
|
||||||
|
(
|
||||||
|
UList<char>& buffer,
|
||||||
|
size_t nbytes,
|
||||||
|
IOstreamOption::streamFormat fmt
|
||||||
|
)
|
||||||
|
:
|
||||||
|
UOListStream(buffer.data(), nbytes, IOstreamOption(fmt))
|
||||||
|
{}
|
||||||
|
|
||||||
|
//- Construct using data area from a List and its inherent storage size
|
||||||
|
UOListStream
|
||||||
|
(
|
||||||
|
UList<char>& buffer,
|
||||||
|
IOstreamOption::streamFormat fmt
|
||||||
|
)
|
||||||
|
:
|
||||||
|
UOListStream(buffer.data(), buffer.size(), IOstreamOption(fmt))
|
||||||
|
{}
|
||||||
|
|
||||||
|
//- Construct using data area from a FixedList
|
||||||
|
template<unsigned N>
|
||||||
|
UOListStream
|
||||||
|
(
|
||||||
|
FixedList<char, N>& buffer,
|
||||||
|
IOstreamOption::streamFormat fmt
|
||||||
|
)
|
||||||
|
:
|
||||||
|
UOListStream(buffer.data(), N, IOstreamOption(fmt))
|
||||||
|
{}
|
||||||
|
|
||||||
|
//- Construct using data area from a DynamicList and its capacity
|
||||||
|
template<int SizeMin>
|
||||||
|
UOListStream
|
||||||
|
(
|
||||||
|
DynamicList<char,SizeMin>& buf,
|
||||||
|
IOstreamOption::streamFormat fmt
|
||||||
|
)
|
||||||
|
:
|
||||||
|
UOListStream(buf.data(), buf.capacity(), IOstreamOption(fmt))
|
||||||
|
{}
|
||||||
|
|
||||||
|
#endif /* Foam_IOstream_extras */
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
} // End namespace Foam
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
@ -5,7 +5,7 @@
|
|||||||
\\ / A nd | www.openfoam.com
|
\\ / A nd | www.openfoam.com
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2016-2023 OpenCFD Ltd.
|
Copyright (C) 2016-2020 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -28,19 +28,16 @@ Class
|
|||||||
|
|
||||||
Description
|
Description
|
||||||
A std::streambuf used for memory buffer streams such as
|
A std::streambuf used for memory buffer streams such as
|
||||||
ispanstream, ocharstream, etc.
|
UIListStream, UOListStream, etc.
|
||||||
|
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#ifndef Foam_memoryStreamBuffer_H
|
#ifndef Foam_memoryStreamBuffer_H
|
||||||
#define Foam_memoryStreamBuffer_H
|
#define Foam_memoryStreamBuffer_H
|
||||||
|
|
||||||
#include "stdFoam.H" // For span
|
|
||||||
#include "UList.H"
|
#include "UList.H"
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
#include <sstream> // Possibly want stringstream too...
|
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
@ -51,7 +48,7 @@ namespace Foam
|
|||||||
Class memorybuf Declaration
|
Class memorybuf Declaration
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
//- A streambuf for memory similar to std::spanbuf (C++23)
|
//- A streambuf for memory
|
||||||
class memorybuf
|
class memorybuf
|
||||||
:
|
:
|
||||||
public std::streambuf
|
public std::streambuf
|
||||||
@ -109,11 +106,11 @@ protected:
|
|||||||
|
|
||||||
if (testin)
|
if (testin)
|
||||||
{
|
{
|
||||||
return (gptr() - eback()); // span_tellg()
|
return (gptr() - eback()); // tellg()
|
||||||
}
|
}
|
||||||
if (testout)
|
if (testout)
|
||||||
{
|
{
|
||||||
return (pptr() - pbase()); // span_tellp()
|
return (pptr() - pbase()); // tellp()
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
@ -130,322 +127,126 @@ protected:
|
|||||||
return seekoff(pos, std::ios_base::beg, which);
|
return seekoff(pos, std::ios_base::beg, which);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//- \return the current buffer get position
|
||||||
|
inline std::streamsize tellg() const
|
||||||
|
{
|
||||||
|
return (gptr() - eback());
|
||||||
|
}
|
||||||
|
|
||||||
|
//- \return the current buffer put position
|
||||||
|
inline std::streamsize tellp() const
|
||||||
|
{
|
||||||
|
return (pptr() - pbase());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// Forward Declarations
|
// Forward Declarations
|
||||||
class in_base;
|
class in;
|
||||||
class in_dynamic;
|
class out;
|
||||||
class out_base;
|
|
||||||
class out_dynamic;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*\
|
/*---------------------------------------------------------------------------*\
|
||||||
Class memorybuf::in_base Declaration
|
Class memorybuf::in Declaration
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
//- The base input streambuf with memory access
|
//- An input streambuf for memory access
|
||||||
class memorybuf::in_base
|
class memorybuf::in
|
||||||
:
|
:
|
||||||
public memorybuf
|
public memorybuf
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
//- Get sequence of characters from a fixed region
|
//- Default construct
|
||||||
|
in() = default;
|
||||||
|
|
||||||
|
//- Get sequence of characters
|
||||||
virtual std::streamsize xsgetn(char* s, std::streamsize n)
|
virtual std::streamsize xsgetn(char* s, std::streamsize n)
|
||||||
{
|
{
|
||||||
std::streamsize count = 0;
|
std::streamsize count = 0;
|
||||||
|
|
||||||
while (count < n && gptr() < egptr())
|
while (count < n && gptr() < egptr())
|
||||||
{
|
{
|
||||||
*(s + count++) = *(gptr());
|
*(s + count++) = *(gptr());
|
||||||
gbump(1);
|
gbump(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// Constructors
|
//- Construct for character array (can be nullptr) and number of bytes
|
||||||
|
in(char* s, std::streamsize n)
|
||||||
|
{
|
||||||
|
resetg(s, n);
|
||||||
|
}
|
||||||
|
|
||||||
//- Default construct
|
//- Reset for character array (can be nullptr) and number of bytes
|
||||||
in_base() = default;
|
// Sets get pointer to the begin.
|
||||||
|
inline void resetg(char* s, std::streamsize n)
|
||||||
//- Construct for character array (can be nullptr) and number of bytes
|
{
|
||||||
in_base(char* s, std::streamsize n)
|
if (s)
|
||||||
{
|
{
|
||||||
resetg(s, n);
|
setg(s, s, s + n);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
|
||||||
// Member Functions
|
|
||||||
|
|
||||||
// //- Reset get buffer pointer to the beginning of existing span
|
|
||||||
// void rewind() { setg(eback(), eback(), egptr()); }
|
|
||||||
|
|
||||||
//- Reset get buffer with character data (can be nullptr) and count
|
|
||||||
// Sets get pointer to the begin.
|
|
||||||
void resetg(char* s, std::streamsize n)
|
|
||||||
{
|
{
|
||||||
if (s)
|
setg(nullptr, nullptr, nullptr);
|
||||||
{
|
|
||||||
setg(s, s, s + n);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
setg(nullptr, nullptr, nullptr);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//- The current buffer get position
|
//- The buffer get position
|
||||||
std::streamsize span_tellg() const { return (gptr() - eback()); }
|
using memorybuf::tellg;
|
||||||
|
|
||||||
//- The get buffer capacity
|
//- The buffer capacity
|
||||||
std::streamsize span_capacity() const { return (egptr() - eback()); }
|
inline std::streamsize capacity() const
|
||||||
|
{
|
||||||
|
return (egptr() - eback());
|
||||||
|
}
|
||||||
|
|
||||||
//- The number of characters remaining in the get area
|
//- Const UList access to the input characters (shallow copy).
|
||||||
std::streamsize span_remaining() const
|
inline const UList<char> list() const
|
||||||
{
|
{
|
||||||
return (gptr() < egptr()) ? (egptr() - gptr()) : 0;
|
return UList<char>(eback(), (egptr() - eback()));
|
||||||
}
|
}
|
||||||
|
|
||||||
//- Span of the input characters (is modifiable!)
|
//- Non-const UList access to the input characters (shallow copy).
|
||||||
UList<char> span_list() const
|
inline UList<char> list()
|
||||||
{
|
{
|
||||||
return UList<char>(eback(), (egptr() - eback()));
|
return UList<char>(eback(), (egptr() - eback()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// //- The span of input characters (is modifiable!)
|
//- Some information about the input buffer position/capacity
|
||||||
// stdFoam::span<char> span() const
|
inline void printBufInfo(Ostream& os) const
|
||||||
// {
|
{
|
||||||
// return stdFoam::span<char>(eback(), (egptr() - eback()));
|
os << "get=" << (gptr() - eback()) // tellp()
|
||||||
// }
|
<< "/" << (egptr() - eback()); // capacity
|
||||||
|
}
|
||||||
//- Some information about the input buffer position/capacity
|
|
||||||
void info(Ostream& os) const
|
|
||||||
{
|
|
||||||
os << "get=" << span_tellg() << '/' << span_capacity();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*\
|
/*---------------------------------------------------------------------------*\
|
||||||
Class memorybuf::in_dynamic Declaration
|
Class memorybuf::out Declaration
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
//- An output streambuf for memory access
|
//- An output streambuf for memory access
|
||||||
class memorybuf::in_dynamic
|
class memorybuf::out
|
||||||
:
|
|
||||||
public memorybuf::in_base
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
|
|
||||||
//- Character storage
|
|
||||||
List<char> storage_;
|
|
||||||
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
// Constructors
|
|
||||||
|
|
||||||
//- Default construct - empty
|
|
||||||
in_dynamic() = default;
|
|
||||||
|
|
||||||
//- Copy construct from content
|
|
||||||
in_dynamic(const char* s, std::streamsize n)
|
|
||||||
{
|
|
||||||
if (s && n)
|
|
||||||
{
|
|
||||||
storage_.resize_nocopy(n);
|
|
||||||
std::copy(s, (s + n), storage_.data());
|
|
||||||
}
|
|
||||||
sync_gbuffer();
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Move construct from List
|
|
||||||
in_dynamic(::Foam::List<char>&& buffer)
|
|
||||||
:
|
|
||||||
storage_(std::move(buffer))
|
|
||||||
{
|
|
||||||
sync_gbuffer();
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Move construct from DynamicList (added length only)
|
|
||||||
template<int SizeMin>
|
|
||||||
in_dynamic(::Foam::DynamicList<char,SizeMin>&& buffer)
|
|
||||||
{
|
|
||||||
storage_.transfer(buffer);
|
|
||||||
sync_gbuffer();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Member Functions
|
|
||||||
|
|
||||||
//- Sync get buffer pointers to agree with list dimensions
|
|
||||||
// Sets get pointer to the begin (rewind).
|
|
||||||
void sync_gbuffer()
|
|
||||||
{
|
|
||||||
resetg(storage_.data(), storage_.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Reset content (copy)
|
|
||||||
void reset(const char* s, std::streamsize n)
|
|
||||||
{
|
|
||||||
if (s && n)
|
|
||||||
{
|
|
||||||
storage_.resize_nocopy(n);
|
|
||||||
std::copy(s, (s + n), storage_.data());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
storage_.clear();
|
|
||||||
}
|
|
||||||
sync_gbuffer();
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Transfer list contents to List buffer
|
|
||||||
void swap(::Foam::List<char>& other)
|
|
||||||
{
|
|
||||||
storage_.swap(other); // Swap contents
|
|
||||||
sync_gbuffer();
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Transfer list contents to a DynamicList buffer
|
|
||||||
template<int SizeMin>
|
|
||||||
void swap(DynamicList<char,SizeMin>& other)
|
|
||||||
{
|
|
||||||
List<char> tmp(std::move(storage_));
|
|
||||||
|
|
||||||
other.shrink(); // Use addressed length only
|
|
||||||
storage_.transfer(other);
|
|
||||||
other.transfer(tmp);
|
|
||||||
sync_gbuffer();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*\
|
|
||||||
Class memorybuf::out_base Declaration
|
|
||||||
\*---------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
//- An output streambuf for memory access
|
|
||||||
class memorybuf::out_base
|
|
||||||
:
|
:
|
||||||
public memorybuf
|
public memorybuf
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
//- Put sequence of characters to a fixed region
|
//- Default construct
|
||||||
virtual std::streamsize xsputn(const char* s, std::streamsize n)
|
out() = default;
|
||||||
{
|
|
||||||
std::streamsize count = 0;
|
|
||||||
while (count < n && pptr() < epptr())
|
|
||||||
{
|
|
||||||
*(pptr()) = *(s + count++);
|
|
||||||
pbump(1);
|
|
||||||
}
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
// Constructors
|
|
||||||
|
|
||||||
//- Default construct
|
|
||||||
out_base() = default;
|
|
||||||
|
|
||||||
//- Construct for character array (can be nullptr) and number of bytes
|
|
||||||
out_base(char* s, std::streamsize n)
|
|
||||||
{
|
|
||||||
resetp(s, n);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Member Functions
|
|
||||||
|
|
||||||
// //- Reset put buffer pointer to the beginning of existing span
|
|
||||||
// void rewind() { setp(pbase(), epptr()); }
|
|
||||||
|
|
||||||
//- Reset put buffer with character data (can be nullptr) and count
|
|
||||||
// Sets put pointer to the begin.
|
|
||||||
inline void resetp(char* s, std::streamsize n)
|
|
||||||
{
|
|
||||||
if (s)
|
|
||||||
{
|
|
||||||
// As per (std::ios_base::out && !std::ios_base::ate)
|
|
||||||
setp(s, s + n);
|
|
||||||
// No treatment for (std::ios_base::out && std::ios_base::ate)
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
setp(nullptr, nullptr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//- The current buffer put position
|
|
||||||
std::streamsize span_tellp() const { return (pptr() - pbase()); }
|
|
||||||
|
|
||||||
//- The put buffer capacity
|
|
||||||
std::streamsize span_capacity() const { return (epptr() - pbase()); }
|
|
||||||
|
|
||||||
//- Span of the output characters (is modifiable!)
|
|
||||||
UList<char> span_list() const
|
|
||||||
{
|
|
||||||
return UList<char>(pbase(), (pptr() - pbase()));
|
|
||||||
}
|
|
||||||
|
|
||||||
//- The span of output characters (is modifiable!)
|
|
||||||
// stdFoam::span<char> span() const
|
|
||||||
// {
|
|
||||||
// return stdFoam::span<char>(pbase(), (pptr() - pbase()));
|
|
||||||
// }
|
|
||||||
|
|
||||||
//- Some information about the output buffer position/capacity
|
|
||||||
void info(Ostream& os) const
|
|
||||||
{
|
|
||||||
os << "put=" << span_tellp() << '/' << span_capacity();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*\
|
|
||||||
Class memorybuf::out_dynamic Declaration
|
|
||||||
\*---------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
//- An output streambuf for memory access
|
|
||||||
class memorybuf::out_dynamic
|
|
||||||
:
|
|
||||||
public memorybuf::out_base
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
|
|
||||||
//- Character storage.
|
|
||||||
// Internally manage like a DynamicList, with its capacity known
|
|
||||||
// from the list size and the addressable size known through the
|
|
||||||
// stream pointers.
|
|
||||||
List<char> storage_;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
//- Handle overflow
|
|
||||||
virtual int overflow(int_type c = traits_type::eof())
|
|
||||||
{
|
|
||||||
if (c != traits_type::eof())
|
|
||||||
{
|
|
||||||
// Need more space?
|
|
||||||
reserve(1 + span_tellp());
|
|
||||||
|
|
||||||
*(pptr()) = c;
|
|
||||||
pbump(1);
|
|
||||||
}
|
|
||||||
return c;
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Put sequence of characters
|
//- Put sequence of characters
|
||||||
virtual std::streamsize xsputn(const char* s, std::streamsize n)
|
virtual std::streamsize xsputn(const char* s, std::streamsize n)
|
||||||
{
|
{
|
||||||
// Enough space so that appends work without problem
|
|
||||||
reserve(n + span_tellp());
|
|
||||||
|
|
||||||
std::streamsize count = 0;
|
std::streamsize count = 0;
|
||||||
while (count < n && pptr() < epptr())
|
while (count < n && pptr() < epptr())
|
||||||
{
|
{
|
||||||
@ -459,111 +260,53 @@ protected:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// Constructors
|
//- Construct for character array (can be nullptr) and number of bytes
|
||||||
|
out(char* s, std::streamsize n)
|
||||||
|
{
|
||||||
|
resetp(s, n);
|
||||||
|
}
|
||||||
|
|
||||||
//- Default construct with initial reserved number of bytes.
|
//- Reset for character array (can be nullptr) and number of bytes.
|
||||||
// The value of 512 is a bit arbitrary, but consistent with
|
// Sets put pointer to the begin.
|
||||||
// std::stringstream
|
inline void resetp(char* s, std::streamsize n)
|
||||||
out_dynamic(size_t nbytes = 512)
|
{
|
||||||
:
|
if (s)
|
||||||
storage_(label(nbytes))
|
|
||||||
{
|
{
|
||||||
sync_pbuffer();
|
setp(s, s + n);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
//- Move construct from List
|
|
||||||
out_dynamic(::Foam::List<char>&& buffer)
|
|
||||||
:
|
|
||||||
storage_(std::move(buffer))
|
|
||||||
{
|
{
|
||||||
sync_pbuffer();
|
setp(nullptr, nullptr);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//- Move construct from DynamicList (uses entire capacity)
|
//- The buffer put position
|
||||||
template<int SizeMin>
|
using memorybuf::tellp;
|
||||||
out_dynamic(::Foam::DynamicList<char,SizeMin>&& buffer)
|
|
||||||
{
|
|
||||||
buffer.resize(buffer.capacity()); // Use entire space
|
|
||||||
storage_.transfer(buffer);
|
|
||||||
sync_pbuffer();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
//- The buffer capacity
|
||||||
|
inline std::streamsize capacity() const
|
||||||
|
{
|
||||||
|
return (epptr() - pbase());
|
||||||
|
}
|
||||||
|
|
||||||
// Member Functions
|
//- Const UList access to the characters written (shallow copy).
|
||||||
|
inline const UList<char> list() const
|
||||||
|
{
|
||||||
|
return UList<char>(pbase(), (pptr() - pbase()));
|
||||||
|
}
|
||||||
|
|
||||||
//- Increment capacity (if needed) and adjust buffer pointers
|
//- Non-const UList access to the characters written (shallow copy).
|
||||||
void reserve(const std::streamsize len)
|
inline UList<char> list()
|
||||||
{
|
{
|
||||||
if (storage_.size() < len)
|
return UList<char>(pbase(), (pptr() - pbase()));
|
||||||
{
|
}
|
||||||
const auto cur = span_tellp(); // Current location
|
|
||||||
|
|
||||||
label newCapacity = 512;
|
//- Some information about the output buffer position/capacity
|
||||||
|
inline void printBufInfo(Ostream& os) const
|
||||||
if (newCapacity < len)
|
{
|
||||||
{
|
os << "put=" << (pptr() - pbase()) // tellp()
|
||||||
// Increase capacity (doubling)
|
<< "/" << (epptr() - pbase()); // capacity
|
||||||
newCapacity = max(len, label(2*storage_.size()));
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Info<<"request:" << len
|
|
||||||
// << " cur cap:" << storage_.size()
|
|
||||||
// << " new cap:" << newCapacity
|
|
||||||
// << " pos:" << cur << endl;
|
|
||||||
|
|
||||||
storage_.resize(newCapacity);
|
|
||||||
sync_pbuffer();
|
|
||||||
pbump(cur);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Sync put buffer pointers to agree with list dimensions
|
|
||||||
// Sets put pointer to the begin (rewind).
|
|
||||||
void sync_pbuffer()
|
|
||||||
{
|
|
||||||
resetp(storage_.data(), storage_.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Clear storage
|
|
||||||
void clearStorage()
|
|
||||||
{
|
|
||||||
storage_.clear();
|
|
||||||
sync_pbuffer();
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Shrink storage to addressed storage
|
|
||||||
inline void shrink()
|
|
||||||
{
|
|
||||||
const auto cur = span_tellp(); // Addressed length
|
|
||||||
|
|
||||||
storage_.resize(cur);
|
|
||||||
sync_pbuffer();
|
|
||||||
pbump(cur);
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Transfer list contents to List buffer
|
|
||||||
inline void swap(List<char>& other)
|
|
||||||
{
|
|
||||||
const auto cur = span_tellp(); // Addressed length
|
|
||||||
|
|
||||||
storage_.swap(other); // Swap contents
|
|
||||||
other.resize(cur); // Adjust to addressed length
|
|
||||||
sync_pbuffer();
|
|
||||||
}
|
|
||||||
|
|
||||||
//- Transfer list contents to a DynamicList buffer
|
|
||||||
template<int SizeMin>
|
|
||||||
inline void swap(DynamicList<char,SizeMin>& other)
|
|
||||||
{
|
|
||||||
const auto cur = span_tellp(); // Addressed length
|
|
||||||
List<char> tmp(std::move(storage_));
|
|
||||||
|
|
||||||
other.resize(other.capacity()); // Use entire space
|
|
||||||
storage_.transfer(other);
|
|
||||||
other.transfer(tmp);
|
|
||||||
other.resize(cur); // Adjust to addressed length
|
|
||||||
sync_pbuffer();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -28,6 +28,7 @@ License
|
|||||||
|
|
||||||
#include "dynamicCodeContext.H"
|
#include "dynamicCodeContext.H"
|
||||||
#include "stringOps.H"
|
#include "stringOps.H"
|
||||||
|
#include "OSHA1stream.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2011-2014 OpenFOAM Foundation
|
Copyright (C) 2011-2014 OpenFOAM Foundation
|
||||||
Copyright (C) 2015-2023 OpenCFD Ltd.
|
Copyright (C) 2015-2021 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -37,24 +37,8 @@ Note
|
|||||||
#include "StringStream.H"
|
#include "StringStream.H"
|
||||||
#include "foamVersion.H"
|
#include "foamVersion.H"
|
||||||
#include "OSspecific.H"
|
#include "OSspecific.H"
|
||||||
#include "Enum.H"
|
|
||||||
#include "Switch.H"
|
#include "Switch.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
const Foam::Enum
|
|
||||||
<
|
|
||||||
Foam::error::handlerTypes
|
|
||||||
>
|
|
||||||
Foam::error::handlerNames
|
|
||||||
({
|
|
||||||
{ handlerTypes::DEFAULT, "default" },
|
|
||||||
{ handlerTypes::IGNORE, "ignore" },
|
|
||||||
{ handlerTypes::WARN, "warn" },
|
|
||||||
{ handlerTypes::STRICT, "strict" },
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||||
|
|
||||||
bool Foam::error::master(const label communicator)
|
bool Foam::error::master(const label communicator)
|
||||||
|
|||||||
@ -53,8 +53,8 @@ SeeAlso
|
|||||||
|
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#ifndef Foam_error_H
|
#ifndef error_H
|
||||||
#define Foam_error_H
|
#define error_H
|
||||||
|
|
||||||
#include "messageStream.H"
|
#include "messageStream.H"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
@ -66,7 +66,6 @@ namespace Foam
|
|||||||
|
|
||||||
// Forward Declarations
|
// Forward Declarations
|
||||||
class OStringStream;
|
class OStringStream;
|
||||||
template<class EnumType> class Enum;
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*\
|
/*---------------------------------------------------------------------------*\
|
||||||
Class error Declaration
|
Class error Declaration
|
||||||
@ -102,21 +101,6 @@ protected:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// Data Types
|
|
||||||
|
|
||||||
//- Handling of errors. The exact handling depends on the local context.
|
|
||||||
enum class handlerTypes : char
|
|
||||||
{
|
|
||||||
DEFAULT = 0, //!< Default behaviour (local meaning)
|
|
||||||
IGNORE, //!< Ignore on errors/problems
|
|
||||||
WARN, //!< Warn on errors/problems
|
|
||||||
STRICT //!< Fatal on errors/problems
|
|
||||||
};
|
|
||||||
|
|
||||||
//- Names of the error handler types
|
|
||||||
static const Enum<handlerTypes> handlerNames;
|
|
||||||
|
|
||||||
|
|
||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
//- Construct from title string
|
//- Construct from title string
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2011-2017 OpenFOAM Foundation
|
Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||||
Copyright (C) 2015-2023 OpenCFD Ltd.
|
Copyright (C) 2015-2022 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -44,7 +44,7 @@ License
|
|||||||
/* * * * * * * * * * * * * * * Static Member Data * * * * * * * * * * * * * */
|
/* * * * * * * * * * * * * * * Static Member Data * * * * * * * * * * * * * */
|
||||||
|
|
||||||
//- Max number of warnings (per functionObject)
|
//- Max number of warnings (per functionObject)
|
||||||
static constexpr const unsigned maxWarnings = 10u;
|
static constexpr const uint32_t maxWarnings = 10u;
|
||||||
|
|
||||||
Foam::fileName Foam::functionObjectList::functionObjectDictPath
|
Foam::fileName Foam::functionObjectList::functionObjectDictPath
|
||||||
(
|
(
|
||||||
@ -52,6 +52,19 @@ Foam::fileName Foam::functionObjectList::functionObjectDictPath
|
|||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
const Foam::Enum
|
||||||
|
<
|
||||||
|
Foam::functionObjectList::errorHandlingType
|
||||||
|
>
|
||||||
|
Foam::functionObjectList::errorHandlingNames_
|
||||||
|
({
|
||||||
|
{ errorHandlingType::DEFAULT, "default" },
|
||||||
|
{ errorHandlingType::WARN, "warn" },
|
||||||
|
{ errorHandlingType::IGNORE, "ignore" },
|
||||||
|
{ errorHandlingType::STRICT, "strict" },
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
namespace Foam
|
namespace Foam
|
||||||
@ -337,12 +350,12 @@ bool Foam::functionObjectList::readFunctionObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Foam::error::handlerTypes
|
Foam::functionObjectList::errorHandlingType
|
||||||
Foam::functionObjectList::getOrDefaultErrorHandling
|
Foam::functionObjectList::getOrDefaultErrorHandling
|
||||||
(
|
(
|
||||||
const word& key,
|
const word& key,
|
||||||
const dictionary& dict,
|
const dictionary& dict,
|
||||||
const error::handlerTypes deflt
|
const errorHandlingType deflt
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
const entry* eptr = dict.findEntry(key, keyType::LITERAL);
|
const entry* eptr = dict.findEntry(key, keyType::LITERAL);
|
||||||
@ -359,16 +372,16 @@ Foam::functionObjectList::getOrDefaultErrorHandling
|
|||||||
{
|
{
|
||||||
const word enumName(eptr->get<word>());
|
const word enumName(eptr->get<word>());
|
||||||
|
|
||||||
if (!error::handlerNames.found(enumName))
|
if (!errorHandlingNames_.found(enumName))
|
||||||
{
|
{
|
||||||
// Failed the name lookup
|
// Failed the name lookup
|
||||||
FatalIOErrorInFunction(dict)
|
FatalIOErrorInFunction(dict)
|
||||||
<< enumName << " is not in enumeration: "
|
<< enumName << " is not in enumeration: "
|
||||||
<< error::handlerNames << nl
|
<< errorHandlingNames_ << nl
|
||||||
<< exit(FatalIOError);
|
<< exit(FatalIOError);
|
||||||
}
|
}
|
||||||
|
|
||||||
return error::handlerNames.get(enumName);
|
return errorHandlingNames_.get(enumName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -399,7 +412,7 @@ Foam::functionObjectList::functionObjectList
|
|||||||
errorHandling_(),
|
errorHandling_(),
|
||||||
digests_(),
|
digests_(),
|
||||||
indices_(),
|
indices_(),
|
||||||
warnings_(0),
|
warnings_(),
|
||||||
time_(runTime),
|
time_(runTime),
|
||||||
parentDict_(parentDict),
|
parentDict_(parentDict),
|
||||||
propsDictPtr_(nullptr),
|
propsDictPtr_(nullptr),
|
||||||
@ -627,15 +640,15 @@ bool Foam::functionObjectList::execute()
|
|||||||
|
|
||||||
for (functionObject& funcObj : functions())
|
for (functionObject& funcObj : functions())
|
||||||
{
|
{
|
||||||
const auto errorHandling = *errIter;
|
const errorHandlingType errorHandling = *errIter;
|
||||||
++errIter;
|
++errIter;
|
||||||
|
|
||||||
const word& objName = funcObj.name();
|
const word& objName = funcObj.name();
|
||||||
|
|
||||||
if
|
if
|
||||||
(
|
(
|
||||||
errorHandling == error::handlerTypes::WARN
|
errorHandling == errorHandlingType::WARN
|
||||||
|| errorHandling == error::handlerTypes::IGNORE
|
|| errorHandling == errorHandlingType::IGNORE
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
// Throw FatalError, FatalIOError as exceptions
|
// Throw FatalError, FatalIOError as exceptions
|
||||||
@ -659,12 +672,12 @@ bool Foam::functionObjectList::execute()
|
|||||||
catch (const Foam::error& err)
|
catch (const Foam::error& err)
|
||||||
{
|
{
|
||||||
// Treat IOerror and error identically
|
// Treat IOerror and error identically
|
||||||
unsigned nWarnings;
|
uint32_t nWarnings;
|
||||||
hadError = true;
|
hadError = true;
|
||||||
|
|
||||||
if
|
if
|
||||||
(
|
(
|
||||||
(errorHandling == error::handlerTypes::WARN)
|
errorHandling != errorHandlingType::IGNORE
|
||||||
&& (nWarnings = ++warnings_(objName)) <= maxWarnings
|
&& (nWarnings = ++warnings_(objName)) <= maxWarnings
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
@ -705,12 +718,11 @@ bool Foam::functionObjectList::execute()
|
|||||||
catch (const Foam::error& err)
|
catch (const Foam::error& err)
|
||||||
{
|
{
|
||||||
// Treat IOerror and error identically
|
// Treat IOerror and error identically
|
||||||
unsigned nWarnings;
|
uint32_t nWarnings;
|
||||||
hadError = true;
|
|
||||||
|
|
||||||
if
|
if
|
||||||
(
|
(
|
||||||
(errorHandling == error::handlerTypes::WARN)
|
errorHandling != errorHandlingType::IGNORE
|
||||||
&& (nWarnings = ++warnings_(objName)) <= maxWarnings
|
&& (nWarnings = ++warnings_(objName)) <= maxWarnings
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
@ -732,17 +744,6 @@ bool Foam::functionObjectList::execute()
|
|||||||
// Restore previous state
|
// Restore previous state
|
||||||
FatalError.throwing(oldThrowingError);
|
FatalError.throwing(oldThrowingError);
|
||||||
FatalIOError.throwing(oldThrowingIOerr);
|
FatalIOError.throwing(oldThrowingIOerr);
|
||||||
|
|
||||||
// Reset the warning counter (if any)
|
|
||||||
// if no errors were encountered
|
|
||||||
if
|
|
||||||
(
|
|
||||||
(errorHandling == error::handlerTypes::WARN)
|
|
||||||
&& !hadError && !warnings_.empty()
|
|
||||||
)
|
|
||||||
{
|
|
||||||
warnings_.erase(objName);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -850,7 +851,7 @@ bool Foam::functionObjectList::end()
|
|||||||
|
|
||||||
for (functionObject& funcObj : functions())
|
for (functionObject& funcObj : functions())
|
||||||
{
|
{
|
||||||
const auto errorHandling = *errIter;
|
const errorHandlingType errorHandling = *errIter;
|
||||||
++errIter;
|
++errIter;
|
||||||
|
|
||||||
const word& objName = funcObj.name();
|
const word& objName = funcObj.name();
|
||||||
@ -869,35 +870,32 @@ bool Foam::functionObjectList::end()
|
|||||||
catch (const Foam::error& err)
|
catch (const Foam::error& err)
|
||||||
{
|
{
|
||||||
// Treat IOerror and error identically
|
// Treat IOerror and error identically
|
||||||
// If it somehow failed, emit a warning (unless IGNORE).
|
uint32_t nWarnings;
|
||||||
// Unlike execute(), do not suppress further warning messages
|
|
||||||
// (we want to know about rare issues)
|
|
||||||
// but do reset the warnings counter for the next cycle.
|
|
||||||
|
|
||||||
if (errorHandling != error::handlerTypes::IGNORE)
|
if
|
||||||
|
(
|
||||||
|
errorHandling != errorHandlingType::IGNORE
|
||||||
|
&& (nWarnings = ++warnings_(objName)) <= maxWarnings
|
||||||
|
)
|
||||||
{
|
{
|
||||||
// Trickery to get original message
|
// Trickery to get original message
|
||||||
err.write(Warning, false);
|
err.write(Warning, false);
|
||||||
Info<< nl
|
Info<< nl
|
||||||
<< "--> end() function object '"
|
<< "--> end() function object '"
|
||||||
<< objName << "'"
|
<< objName << "'";
|
||||||
<< nl << endl;
|
|
||||||
|
if (nWarnings == maxWarnings)
|
||||||
|
{
|
||||||
|
Info<< nl << "... silencing further warnings";
|
||||||
|
}
|
||||||
|
|
||||||
|
Info<< nl << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Restore previous state
|
// Restore previous state
|
||||||
FatalError.throwing(oldThrowingError);
|
FatalError.throwing(oldThrowingError);
|
||||||
FatalIOError.throwing(oldThrowingIOerr);
|
FatalIOError.throwing(oldThrowingIOerr);
|
||||||
|
|
||||||
// Reset the corresponding warning counter (if any)
|
|
||||||
if
|
|
||||||
(
|
|
||||||
(errorHandling == error::handlerTypes::WARN)
|
|
||||||
&& !warnings_.empty()
|
|
||||||
)
|
|
||||||
{
|
|
||||||
warnings_.erase(objName);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -984,7 +982,7 @@ bool Foam::functionObjectList::read()
|
|||||||
errorHandling_.resize
|
errorHandling_.resize
|
||||||
(
|
(
|
||||||
functionsDict.size(),
|
functionsDict.size(),
|
||||||
error::handlerTypes::DEFAULT
|
errorHandlingType::DEFAULT
|
||||||
);
|
);
|
||||||
|
|
||||||
HashTable<label> newIndices;
|
HashTable<label> newIndices;
|
||||||
@ -1000,12 +998,12 @@ bool Foam::functionObjectList::read()
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Top-level "errors" specification (optional)
|
// Top-level "errors" specification (optional)
|
||||||
const error::handlerTypes errorHandlingFallback =
|
const errorHandlingType errorHandlingFallback =
|
||||||
getOrDefaultErrorHandling
|
getOrDefaultErrorHandling
|
||||||
(
|
(
|
||||||
"errors",
|
"errors",
|
||||||
functionsDict,
|
functionsDict,
|
||||||
error::handlerTypes::DEFAULT
|
errorHandlingType::DEFAULT
|
||||||
);
|
);
|
||||||
|
|
||||||
label nFunc = 0;
|
label nFunc = 0;
|
||||||
@ -1047,7 +1045,7 @@ bool Foam::functionObjectList::read()
|
|||||||
bool enabled = dict.getOrDefault("enabled", true);
|
bool enabled = dict.getOrDefault("enabled", true);
|
||||||
|
|
||||||
// Per-function "errors" specification
|
// Per-function "errors" specification
|
||||||
const error::handlerTypes errorHandling =
|
const errorHandlingType errorHandling =
|
||||||
getOrDefaultErrorHandling
|
getOrDefaultErrorHandling
|
||||||
(
|
(
|
||||||
"errors",
|
"errors",
|
||||||
@ -1137,16 +1135,16 @@ bool Foam::functionObjectList::read()
|
|||||||
|
|
||||||
switch (errorHandling)
|
switch (errorHandling)
|
||||||
{
|
{
|
||||||
case error::handlerTypes::IGNORE:
|
case errorHandlingType::IGNORE:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case error::handlerTypes::STRICT:
|
case errorHandlingType::STRICT:
|
||||||
{
|
{
|
||||||
exitNow(err);
|
exitNow(err);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case error::handlerTypes::DEFAULT:
|
case errorHandlingType::DEFAULT:
|
||||||
{
|
{
|
||||||
if (isA<Foam::IOerror>(err))
|
if (isA<Foam::IOerror>(err))
|
||||||
{
|
{
|
||||||
@ -1159,7 +1157,7 @@ bool Foam::functionObjectList::read()
|
|||||||
[[fallthrough]];
|
[[fallthrough]];
|
||||||
}
|
}
|
||||||
|
|
||||||
case error::handlerTypes::WARN:
|
case errorHandlingType::WARN:
|
||||||
{
|
{
|
||||||
// Trickery to get original message
|
// Trickery to get original message
|
||||||
err.write(Warning, false);
|
err.write(Warning, false);
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
Copyright (C) 2015-2023 OpenCFD Ltd.
|
Copyright (C) 2015-2021 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -78,10 +78,11 @@ SourceFiles
|
|||||||
|
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#ifndef Foam_functionObjectList_H
|
#ifndef functionObjectList_H
|
||||||
#define Foam_functionObjectList_H
|
#define functionObjectList_H
|
||||||
|
|
||||||
#include "PtrList.H"
|
#include "PtrList.H"
|
||||||
|
#include "Enum.H"
|
||||||
#include "functionObject.H"
|
#include "functionObject.H"
|
||||||
#include "SHA1Digest.H"
|
#include "SHA1Digest.H"
|
||||||
#include "HashTable.H"
|
#include "HashTable.H"
|
||||||
@ -107,10 +108,25 @@ class functionObjectList
|
|||||||
:
|
:
|
||||||
private PtrList<functionObject>
|
private PtrList<functionObject>
|
||||||
{
|
{
|
||||||
|
// Data Types
|
||||||
|
|
||||||
|
//- Handling of construction or execution errors
|
||||||
|
enum class errorHandlingType : uint8_t
|
||||||
|
{
|
||||||
|
DEFAULT = 0, //!< Warn on construct, Fatal on runtime
|
||||||
|
WARN, //!< Warn on construct, Warn on runtime
|
||||||
|
IGNORE, //!< Ignore on construct, Ignore on runtime
|
||||||
|
STRICT, //!< Fatal on construct, Fatal on runtime
|
||||||
|
};
|
||||||
|
|
||||||
|
//- Names for error handling types
|
||||||
|
static const Enum<errorHandlingType> errorHandlingNames_;
|
||||||
|
|
||||||
|
|
||||||
// Private Data
|
// Private Data
|
||||||
|
|
||||||
//- A list of error/warning handling
|
//- A list of error/warning handling
|
||||||
List<error::handlerTypes> errorHandling_;
|
List<errorHandlingType> errorHandling_;
|
||||||
|
|
||||||
//- A list of SHA1 digests for the function object dictionaries
|
//- A list of SHA1 digests for the function object dictionaries
|
||||||
List<SHA1Digest> digests_;
|
List<SHA1Digest> digests_;
|
||||||
@ -121,7 +137,7 @@ class functionObjectList
|
|||||||
//- Track the number of warnings per function object and limit
|
//- Track the number of warnings per function object and limit
|
||||||
// to a predefined number to avoid flooding the display.
|
// to a predefined number to avoid flooding the display.
|
||||||
// Clear on re-read of functions.
|
// Clear on re-read of functions.
|
||||||
HashTable<unsigned> warnings_;
|
HashTable<uint32_t> warnings_;
|
||||||
|
|
||||||
//- Reference to Time
|
//- Reference to Time
|
||||||
const Time& time_;
|
const Time& time_;
|
||||||
@ -171,11 +187,11 @@ class functionObjectList
|
|||||||
//
|
//
|
||||||
// This additional treatment is to ensure that potentially existing
|
// This additional treatment is to ensure that potentially existing
|
||||||
// code with an "errors" functionObject will continue to run.
|
// code with an "errors" functionObject will continue to run.
|
||||||
error::handlerTypes getOrDefaultErrorHandling
|
errorHandlingType getOrDefaultErrorHandling
|
||||||
(
|
(
|
||||||
const word& key,
|
const word& key,
|
||||||
const dictionary& dict,
|
const dictionary& dict,
|
||||||
const error::handlerTypes deflt
|
const errorHandlingType deflt
|
||||||
) const;
|
) const;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,154 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | www.openfoam.com
|
||||||
|
\\/ M anipulation |
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
License
|
||||||
|
This file is part of OpenFOAM.
|
||||||
|
|
||||||
|
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||||
|
under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Class
|
||||||
|
Foam::SubDimensionedField
|
||||||
|
|
||||||
|
Description
|
||||||
|
SubDimensionedField is a DimensionedField obtained as a section of another
|
||||||
|
DimensionedField.
|
||||||
|
|
||||||
|
Thus it is itself unallocated so that no storage is allocated or
|
||||||
|
deallocated during its use. To achieve this behaviour,
|
||||||
|
SubDimensionedField is derived from SubField rather than Field.
|
||||||
|
|
||||||
|
SourceFiles
|
||||||
|
SubDimensionedFieldI.H
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#ifndef SubDimensionedField_H
|
||||||
|
#define SubDimensionedField_H
|
||||||
|
|
||||||
|
#include "Field.H"
|
||||||
|
#include "SubField.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
namespace Foam
|
||||||
|
{
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
Class SubDimensionedField Declaration
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
template<class Type, class GeoMesh>
|
||||||
|
class SubDimensionedField
|
||||||
|
:
|
||||||
|
public regIOobject,
|
||||||
|
public SubField<Type>
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
// Public typedefs
|
||||||
|
|
||||||
|
typedef typename GeoMesh::Mesh Mesh;
|
||||||
|
typedef typename Field<Type>::cmptType cmptType;
|
||||||
|
|
||||||
|
|
||||||
|
// Constructors
|
||||||
|
|
||||||
|
//- Construct from a SubField
|
||||||
|
inline SubDimensionedField(const SubField<Type>& sfield);
|
||||||
|
|
||||||
|
//- Construct from a UList and size
|
||||||
|
inline SubDimensionedField
|
||||||
|
(
|
||||||
|
const UList<Type>& list,
|
||||||
|
const label subSize
|
||||||
|
);
|
||||||
|
|
||||||
|
//- Construct from a UList start and end indices
|
||||||
|
inline SubDimensionedField
|
||||||
|
(
|
||||||
|
const UList<Type>& list,
|
||||||
|
const label subSize,
|
||||||
|
const label startIndex
|
||||||
|
);
|
||||||
|
|
||||||
|
//- Construct from UList and a (start,size) range.
|
||||||
|
// The range is subsetted with the list size itself to ensure that the
|
||||||
|
// result always addresses a valid section of the list.
|
||||||
|
inline SubDimensionedField
|
||||||
|
(
|
||||||
|
const UList<Type>& list,
|
||||||
|
const labelRange& range
|
||||||
|
);
|
||||||
|
|
||||||
|
//- Construct from UList and a (start,size) range, but bypassing
|
||||||
|
//- run-time range checking.
|
||||||
|
inline SubDimensionedField
|
||||||
|
(
|
||||||
|
const labelRange& range,
|
||||||
|
const UList<Type>& list
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
//- Construct as copy
|
||||||
|
inline SubDimensionedField
|
||||||
|
(
|
||||||
|
const SubDimensionedField<cmptType, GeoMesh>& sfield
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
// Member functions
|
||||||
|
|
||||||
|
//- Return a null SubDimensionedField
|
||||||
|
static inline const SubDimensionedField<Type, GeoMesh>& null();
|
||||||
|
|
||||||
|
//- Return a component field of the field
|
||||||
|
inline tmp<DimensionedField<cmptType, GeoMesh>> component
|
||||||
|
(
|
||||||
|
const direction d
|
||||||
|
) const;
|
||||||
|
|
||||||
|
//- Return the field transpose (only defined for second rank tensors)
|
||||||
|
tmp<DimensionedField<Type, GeoMesh>> T() const;
|
||||||
|
|
||||||
|
|
||||||
|
// Member operators
|
||||||
|
|
||||||
|
//- Assignment
|
||||||
|
inline void operator=(const SubDimensionedField<Type, GeoMesh>& rhs);
|
||||||
|
|
||||||
|
//- Allow cast to a const DimensionedField<Type, GeoMesh>&
|
||||||
|
inline operator const DimensionedField<Type, GeoMesh>&() const;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
} // End namespace Foam
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
#include "SubDimensionedFieldI.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
@ -0,0 +1,156 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | www.openfoam.com
|
||||||
|
\\/ M anipulation |
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
License
|
||||||
|
This file is part of OpenFOAM.
|
||||||
|
|
||||||
|
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||||
|
under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
template<class Type, class GeoMesh>
|
||||||
|
inline Foam::SubDimensionedField<Type, GeoMesh>::SubDimensionedField
|
||||||
|
(
|
||||||
|
const SubField<Type>& sfield
|
||||||
|
)
|
||||||
|
:
|
||||||
|
SubField<Type>(sfield)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Type, class GeoMesh>
|
||||||
|
inline Foam::SubDimensionedField<Type, GeoMesh>::SubDimensionedField
|
||||||
|
(
|
||||||
|
const UList<Type>& list,
|
||||||
|
const label subSize
|
||||||
|
)
|
||||||
|
:
|
||||||
|
SubField<Type>(list, subSize)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Type, class GeoMesh>
|
||||||
|
inline Foam::SubDimensionedField<Type, GeoMesh>::SubDimensionedField
|
||||||
|
(
|
||||||
|
const UList<Type>& list,
|
||||||
|
const label subSize,
|
||||||
|
const label startIndex
|
||||||
|
)
|
||||||
|
:
|
||||||
|
SubField<Type>(list, subSize, startIndex)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Type, class GeoMesh>
|
||||||
|
inline Foam::SubDimensionedField<Type, GeoMesh>::SubDimensionedField
|
||||||
|
(
|
||||||
|
const UList<Type>& list,
|
||||||
|
const labelRange& range
|
||||||
|
)
|
||||||
|
:
|
||||||
|
SubField<Type>(list, range)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Type, class GeoMesh>
|
||||||
|
inline Foam::SubDimensionedField<Type, GeoMesh>::SubDimensionedField
|
||||||
|
(
|
||||||
|
const labelRange& range,
|
||||||
|
const UList<Type>& list
|
||||||
|
)
|
||||||
|
:
|
||||||
|
SubField<Type>(range, list)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Type, class GeoMesh>
|
||||||
|
inline Foam::SubDimensionedField<Type, GeoMesh>::SubDimensionedField
|
||||||
|
(
|
||||||
|
const SubDimensionedField<Type, GeoMesh>& sfield
|
||||||
|
)
|
||||||
|
:
|
||||||
|
refCount(),
|
||||||
|
SubField<Type>(sfield)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
template<class Type, class GeoMesh>
|
||||||
|
inline const Foam::SubDimensionedField<Type, GeoMesh>&
|
||||||
|
Foam::SubDimensionedField<Type, GeoMesh>::null()
|
||||||
|
{
|
||||||
|
return NullObjectRef<SubDimensionedField<Type, GeoMesh>>();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Type, class GeoMesh>
|
||||||
|
inline
|
||||||
|
Foam::tmp
|
||||||
|
<
|
||||||
|
Foam::Field<typename Foam::SubDimensionedField<Type, GeoMesh>::cmptType>
|
||||||
|
>
|
||||||
|
Foam::SubDimensionedField<Type, GeoMesh>::component
|
||||||
|
(
|
||||||
|
const direction d
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
return
|
||||||
|
(
|
||||||
|
reinterpret_cast<const DimensionedField<Type, GeoMesh>&>(*this)
|
||||||
|
).component(d);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Type, class GeoMesh>
|
||||||
|
inline Foam::tmp<Foam::DimensionedField<Type, GeoMesh>>
|
||||||
|
Foam::SubDimensionedField<Type, GeoMesh>::T() const
|
||||||
|
{
|
||||||
|
return
|
||||||
|
(
|
||||||
|
reinterpret_cast<const DimensionedField<Type, GeoMesh>&>(*this)
|
||||||
|
).T();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
template<class Type, class GeoMesh>
|
||||||
|
inline void Foam::SubDimensionedField<Type, GeoMesh>::operator=
|
||||||
|
(
|
||||||
|
const SubDimensionedField<Type, GeoMesh>& rhs
|
||||||
|
)
|
||||||
|
{
|
||||||
|
dimensions() = rhs.dimensions();
|
||||||
|
SubField<Type>::operator=(rhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Type, class GeoMesh>
|
||||||
|
inline Foam::SubDimensionedField<Type, GeoMesh>::operator
|
||||||
|
const Foam::DimensionedField<Type, GeoMesh>&() const
|
||||||
|
{
|
||||||
|
return *(reinterpret_cast<const DimensionedField<Type, GeoMesh>*>(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
@ -172,7 +172,7 @@ public:
|
|||||||
|
|
||||||
#include "SubFieldI.H"
|
#include "SubFieldI.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Implementations * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
template<class Type>
|
template<class Type>
|
||||||
Foam::SubField<Type>
|
Foam::SubField<Type>
|
||||||
|
|||||||
@ -27,6 +27,7 @@ License
|
|||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include "argList.H"
|
#include "argList.H"
|
||||||
|
#include "argListRedirect.H"
|
||||||
#include "OSspecific.H"
|
#include "OSspecific.H"
|
||||||
#include "Switch.H"
|
#include "Switch.H"
|
||||||
#include "clock.H"
|
#include "clock.H"
|
||||||
@ -47,6 +48,7 @@ License
|
|||||||
#include "stringListOps.H"
|
#include "stringListOps.H"
|
||||||
#include "fileOperation.H"
|
#include "fileOperation.H"
|
||||||
#include "fileOperationInitialise.H"
|
#include "fileOperationInitialise.H"
|
||||||
|
#include "fstreamPointer.H"
|
||||||
|
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
|
|
||||||
@ -911,7 +913,9 @@ Foam::argList::argList
|
|||||||
runControl_(),
|
runControl_(),
|
||||||
args_(argc),
|
args_(argc),
|
||||||
options_(argc),
|
options_(argc),
|
||||||
libs_()
|
libs_(),
|
||||||
|
stdout_(nullptr),
|
||||||
|
stderr_(nullptr)
|
||||||
{
|
{
|
||||||
// Pre-scan for some options needed for initial setup:
|
// Pre-scan for some options needed for initial setup:
|
||||||
// -fileHandler (takes an argument)
|
// -fileHandler (takes an argument)
|
||||||
@ -1018,6 +1022,53 @@ Foam::argList::argList
|
|||||||
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
|
// Capture stdout/stderr redirection names. Filters argv
|
||||||
|
Detail::redirectOutputs redirects(argc, argv);
|
||||||
|
|
||||||
|
// Perform output redirection
|
||||||
|
if (redirects.active())
|
||||||
|
{
|
||||||
|
word suffix;
|
||||||
|
|
||||||
|
if (redirects.ranks_ && parRunControl_.parRun())
|
||||||
|
{
|
||||||
|
suffix = Foam::name(Pstream::myProcNo());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!redirects.stdout_.empty())
|
||||||
|
{
|
||||||
|
fileName file(fileName::validate(redirects.stdout_));
|
||||||
|
file.ext(suffix);
|
||||||
|
|
||||||
|
stdout_.reset(ofstreamPointer(file).release());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!redirects.stderr_.empty())
|
||||||
|
{
|
||||||
|
fileName file(fileName::validate(redirects.stderr_));
|
||||||
|
file.ext(suffix);
|
||||||
|
|
||||||
|
stderr_.reset(ofstreamPointer(file).release());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stdout_)
|
||||||
|
{
|
||||||
|
Sout.attach(*stdout_);
|
||||||
|
Pout.attach(*stdout_);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stderr_)
|
||||||
|
{
|
||||||
|
Serr.attach(*stderr_);
|
||||||
|
Perr.attach(*stderr_);
|
||||||
|
}
|
||||||
|
else if (redirects.join_)
|
||||||
|
{
|
||||||
|
Serr.attach(Sout.stdStream());
|
||||||
|
Perr.attach(Sout.stdStream());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Convert argv -> args_ and capture ( ... ) lists
|
// Convert argv -> args_ and capture ( ... ) lists
|
||||||
regroupArgv(argc, argv);
|
regroupArgv(argc, argv);
|
||||||
@ -1172,6 +1223,8 @@ Foam::argList::argList
|
|||||||
args_(args.args_),
|
args_(args.args_),
|
||||||
options_(options),
|
options_(options),
|
||||||
libs_(),
|
libs_(),
|
||||||
|
stdout_(nullptr),
|
||||||
|
stderr_(nullptr),
|
||||||
executable_(args.executable_),
|
executable_(args.executable_),
|
||||||
rootPath_(args.rootPath_),
|
rootPath_(args.rootPath_),
|
||||||
globalCase_(args.globalCase_),
|
globalCase_(args.globalCase_),
|
||||||
|
|||||||
@ -146,6 +146,12 @@ class argList
|
|||||||
//- Additional libraries
|
//- Additional libraries
|
||||||
mutable dlLibraryTable libs_;
|
mutable dlLibraryTable libs_;
|
||||||
|
|
||||||
|
//- File redirection for stdout (Sout, Pout)
|
||||||
|
std::unique_ptr<std::ostream> stdout_;
|
||||||
|
|
||||||
|
//- File redirection for stderr (Serr, Perr)
|
||||||
|
std::unique_ptr<std::ostream> stderr_;
|
||||||
|
|
||||||
word executable_;
|
word executable_;
|
||||||
fileName rootPath_;
|
fileName rootPath_;
|
||||||
fileName globalCase_;
|
fileName globalCase_;
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user