UILListIO.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 OpenFOAM Foundation
9  Copyright (C) 2017 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
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 "UILList.H"
30 #include "Ostream.H"
31 #include "token.H"
32 
33 // * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
34 
35 template<class LListBase, class T>
37 (
38  Ostream& os,
39  const label shortLen
40 ) const
41 {
42  // NB: no binary, contiguous output
43 
44  const label len = this->size();
45 
46  if
47  (
48  (len <= 1 || !shortLen)
49  || (len <= shortLen)
50  )
51  {
52  // Size and start delimiter
53  os << len << token::BEGIN_LIST;
54 
55  // Contents
56  bool space = false;
57  for (const T& val : *this)
58  {
59  if (space) os << token::SPACE;
60  space = true;
61  os << val;
62  }
63 
64  // End delimiter
65  os << token::END_LIST;
66  }
67  else
68  {
69  // Size and start delimiter
70  os << nl << len << nl << token::BEGIN_LIST << nl;
71 
72  // Contents
73  for (const T& val : *this)
74  {
75  os << val << nl;
76  }
77 
78  // End delimiter
79  os << token::END_LIST;
80  }
81 
82  os.check(FUNCTION_NAME);
83  return os;
84 
85 }
86 
87 
88 template<class LListBase, class T>
90 {
91  return lst.writeList(os, -1);
92 }
93 
94 
95 // ************************************************************************* //
token.H
UILList.H
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Foam::UILList::writeList
Ostream & writeList(Ostream &os, const label shortLen=0) const
Write UILList with line-breaks when length exceeds shortLen.
Definition: UILListIO.C:37
os
OBJstream os(runTime.globalPath()/outputName)
T
const volScalarField & T
Definition: createFieldRefs.H:2
Ostream.H
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::UILList
Template class for intrusive linked lists.
Definition: UILList.H:52
FUNCTION_NAME
#define FUNCTION_NAME
Definition: messageStream.H:295
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56