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  const label len = this->size();
43 
44  if
45  (
46  (len <= 1 || !shortLen)
47  || (len <= shortLen)
48  )
49  {
50  // Size and start delimiter
51  os << len << token::BEGIN_LIST;
52 
53  // Contents
54  bool space = false;
55  for (const T& val : *this)
56  {
57  if (space) os << token::SPACE;
58  space = true;
59  os << val;
60  }
61 
62  // End delimiter
63  os << token::END_LIST;
64  }
65  else
66  {
67  // Size and start delimiter
68  os << nl << len << nl << token::BEGIN_LIST << nl;
69 
70  // Contents
71  for (const T& val : *this)
72  {
73  os << val << nl;
74  }
75 
76  // End delimiter
77  os << token::END_LIST;
78  }
79 
80  os.check(FUNCTION_NAME);
81  return os;
82 
83 }
84 
85 
86 template<class LListBase, class T>
88 {
89  return lst.writeList(os, -1);
90 }
91 
92 
93 // ************************************************************************* //
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
Foam::IOstream::check
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:51
T
const volScalarField & T
Definition: createFieldRefs.H:2
Ostream.H
Foam::nl
constexpr char nl
Definition: Ostream.H:385
Foam::UILList
Template class for intrusive linked lists.
Definition: UILList.H:53
FUNCTION_NAME
#define FUNCTION_NAME
Definition: messageStream.H:270
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56