charList.C
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2021 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26\*---------------------------------------------------------------------------*/
27
28#include "charList.H"
29#include "Istream.H"
30#include "Ostream.H"
31#include "token.H"
33
34// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35
36namespace Foam
37{
40}
41
42
43// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
44
45namespace Foam
46{
47
48template<>
50{
51 List<char>& list = *this;
52
53 // Anull list
54 list.clear();
55
57
58 token tok(is);
59
60 is.fatalCheck("List<char>::readList(Istream&) : reading first token");
61
62 if (tok.isCompound())
63 {
64 // Compound: simply transfer contents
65
66 list.transfer
67 (
69 (
71 )
72 );
73 }
74 else if (tok.isLabel())
75 {
76 // Label: could be int(..) or just a plain '0'
77
78 const label len = tok.labelToken();
79
80 // Resize to actual length read
81 list.resize(len);
82
83 // Binary, always contiguous
84
85 if (len)
86 {
87 const auto oldFmt = is.format(IOstream::BINARY);
88
89 // read(...) includes surrounding start/end delimiters
90 is.read(list.data(), std::streamsize(len));
91
92 is.format(oldFmt);
93
94 is.fatalCheck
95 (
96 "List<char>::readList(Istream&) : "
97 "reading binary block"
98 );
99 }
100 }
101 else
102 {
104 << "incorrect first token, expected <int>, found "
105 << tok.info() << nl
106 << exit(FatalIOError);
107 }
108
109 return is;
110}
111
112
113} // End namespace Foam
114
115
116// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
streamFormat format() const noexcept
Get the current stream format.
bool fatalCheck(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:64
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
virtual Istream & read(token &)=0
Return next token from stream.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:77
void transfer(List< T > &list)
Definition: List.C:447
void resize(const label len)
Adjust allocated size of list.
Definition: ListI.H:139
void clear()
Clear the list, i.e. set size to zero.
Definition: ListI.H:116
Istream & readList(Istream &is)
Read List from Istream, discarding contents of existing List.
Definition: ListIO.C:49
T * data() noexcept
Return pointer to the underlying array serving as data storage.
Definition: UListI.H:237
A templated class for holding compound tokens.
Definition: token.H:250
A token holds an item read from Istream.
Definition: token.H:69
compound & transferCompoundToken()
Return reference to compound and mark internally as released.
Definition: token.C:90
bool isLabel() const noexcept
Token is LABEL.
Definition: tokenI.H:497
label labelToken() const
Return label value.
Definition: tokenI.H:513
InfoProxy< token > info() const
Return info proxy for printing token information to a stream.
Definition: token.H:586
bool isCompound() const noexcept
Token is COMPOUND.
Definition: tokenI.H:716
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:473
#define FUNCTION_NAME
Namespace for OpenFOAM.
IOerror FatalIOError
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
To & dynamicCast(From &r)
Definition: typeInfo.H:88
#define addCompoundToRunTimeSelectionTable(Type, Tag)
Add compound to selection table, lookup using typeName.
Definition: token.H:720
#define defineCompoundTypeName(Type, UnusedTag)
Define compound using Type for its name.
Definition: token.H:712