LPtrListIO.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) 2011-2015 OpenFOAM Foundation
9 Copyright (C) 2017-2021 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27\*---------------------------------------------------------------------------*/
28
29#include "LPtrList.H"
30#include "Istream.H"
31#include "Ostream.H"
32#include "INew.H"
33
34// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
35
36template<class LListBase, class T>
37template<class INew>
38void Foam::LPtrList<LListBase, T>::readIstream(Istream& is, const INew& inew)
39{
40 is.fatalCheck(FUNCTION_NAME);
41
42 token tok(is);
43
44 is.fatalCheck
45 (
46 "LPtrList::readIstream : "
47 "reading first token"
48 );
49
50 if (tok.isLabel())
51 {
52 const label len = tok.labelToken();
53
54 // Read beginning of contents
55 const char delimiter = is.readBeginList("LPtrList");
56
57 if (len)
58 {
59 if (delimiter == token::BEGIN_LIST)
60 {
61 for (label i=0; i<len; ++i)
62 {
63 T* p = inew(is).ptr();
64 this->append(p);
65
66 is.fatalCheck
67 (
68 "LPtrList::readIstream : "
69 "reading entry"
70 );
71 }
72 }
73 else // Assumed to be token::BEGIN_BLOCK
74 {
75 T* p = inew(is).ptr();
76 this->append(p);
77
78 is.fatalCheck
79 (
80 "LPtrList::readIstream : "
81 "reading the single entry"
82 );
83
84 for (label i=1; i<len; ++i)
85 {
86 this->append(p->clone().ptr());
87 }
88 }
89 }
90
91 // Read end of contents
92 is.readEndList("LPtrList");
93 }
94 else if (tok.isPunctuation(token::BEGIN_LIST))
95 {
96 is >> tok;
97 is.fatalCheck(FUNCTION_NAME);
98
99 while (!tok.isPunctuation(token::END_LIST))
100 {
101 is.putBack(tok);
102 this->append(inew(is).ptr());
103
104 is >> tok;
105 is.fatalCheck(FUNCTION_NAME);
106 }
107 }
108 else
109 {
111 << "incorrect first token, expected <int> or '(', found "
112 << tok.info() << nl
113 << exit(FatalIOError);
114 }
115
116 is.fatalCheck(FUNCTION_NAME);
117}
118
119
120// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
121
122template<class LListBase, class T>
123template<class INew>
125{
126 this->readIstream(is, inew);
127}
128
129
130template<class LListBase, class T>
132{
133 this->readIstream(is, INew<T>());
134}
135
136
137// * * * * * * * * * * * * * * * Istream Operator * * * * * * * * * * * * * //
138
139template<class LListBase, class T>
141{
142 list.clear();
143 list.readIstream(is, INew<T>());
144
145 return is;
146}
147
148
149// * * * * * * * * * * * * * * * Ostream Operators * * * * * * * * * * * * * //
150
151template<class LListBase, class T>
152Foam::Ostream& Foam::operator<<
153(
154 Ostream& os,
155 const LPtrList<LListBase, T>& list
156)
157{
158 // Size and start delimiter
159 os << nl << list.size() << nl << token::BEGIN_LIST << nl;
160
161 // Contents
162 for (auto iter = list.cbegin(); iter != list.cend(); ++iter)
163 {
164 os << *iter << nl;
165 }
166
167 // End delimiter
168 os << token::END_LIST;
169
170 os.check(FUNCTION_NAME);
171 return os;
172}
173
174// ************************************************************************* //
A helper class when constructing from an Istream or dictionary.
Definition: INew.H:52
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
Template class for non-intrusive linked PtrLists.
Definition: LPtrList.H:75
const_iterator cbegin() const
Iterator to first item in list with const access.
Definition: LPtrList.H:350
const const_iterator & cend() const
End of list for forward iterators.
Definition: LPtrList.H:387
void clear()
Clear the contents of the list.
Definition: LPtrList.C:75
LPtrList()=default
Default construct.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
volScalarField & p
const volScalarField & T
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:473
OBJstream os(runTime.globalPath()/outputName)
#define FUNCTION_NAME
rAUs append(new volScalarField(IOobject::groupName("rAU", phase1.name()), 1.0/(U1Eqn.A()+byDt(max(phase1.residualAlpha() - alpha1, scalar(0)) *rho1))))
Istream & operator>>(Istream &, directionInfo &)
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