IntRanges.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) 2020 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
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 "token.H"
29 #include "List.H"
30 #include "Istream.H"
31 #include "Ostream.H"
32 #include <numeric>
33 
34 // * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38 
39  template<class T>
40  inline static List<label> makeIdentity(const IntRange<T>& range)
41  {
42  if (range.size() < 0)
43  {
44  // Skip this check?
45  return List<label>();
46  }
47 
48  List<label> result(range.size());
49  std::iota(result.begin(), result.end(), range.start());
50 
51  return result;
52  }
53 
54  template<class T>
55  inline static Istream& input(Istream& is, IntRange<T>& range)
56  {
57  is.readBegin("IntRange");
58  is >> range.start() >> range.size();
59  is.readEnd("IntRange");
60 
61  is.check(FUNCTION_NAME);
62  return is;
63  }
64 
65  template<class T>
66  inline static Ostream& output(Ostream& os, const IntRange<T>& range)
67  {
69  << range.start() << token::SPACE << range.size()
70  << token::END_LIST;
71 
73  return os;
74  }
75 
76 } // End namespace Foam
77 
78 
79 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
80 
82 {
83  return makeIdentity(range);
84 }
85 
86 
87 #if defined(WM_LABEL_SIZE) && (WM_LABEL_SIZE >= 64)
88 Foam::List<Foam::label> Foam::identity(const IntRange<int64_t>& range)
89 {
90  return makeIdentity(range);
91 }
92 #endif
93 
94 
95 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
96 
98 {
99  return input(is, range);
100 }
101 
102 
104 {
105  return input(is, range);
106 }
107 
108 
110 {
111  return output(os, range);
112 }
113 
114 
116 {
117  return output(os, range);
118 }
119 
120 
121 // ************************************************************************* //
token.H
Foam::output
static Ostream & output(Ostream &os, const IntRange< T > &range)
Definition: IntRanges.C:66
List.H
Foam::IntRange
An interval of (signed) integers defined by a start and a size.
Definition: IntRange.H:63
Foam::operator>>
Istream & operator>>(Istream &, directionInfo &)
Definition: directionInfo.C:230
Foam::Istream::readEnd
bool readEnd(const char *funcName)
End read of data chunk, ends with ')'.
Definition: Istream.C:129
Foam::Istream::readBegin
bool readBegin(const char *funcName)
Begin read of data chunk, starts with '('.
Definition: Istream.C:111
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::makeIdentity
static List< label > makeIdentity(const IntRange< T > &range)
Definition: IntRanges.C:40
Istream.H
Foam::IOstream::check
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:58
os
OBJstream os(runTime.globalPath()/outputName)
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Ostream.H
range
scalar range
Definition: LISASMDCalcMethod1.H:12
Foam::List< label >
Foam::token::SPACE
Space [isspace].
Definition: token.H:125
Foam::identity
labelList identity(const label len, label start=0)
Create identity map of the given length with (map[i] == i)
Definition: labelList.C:38
Foam::input
static Istream & input(Istream &is, IntRange< T > &range)
Definition: IntRanges.C:55
FUNCTION_NAME
#define FUNCTION_NAME
Definition: messageStream.H:295
Foam::token::END_LIST
End list [isseparator].
Definition: token.H:156
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::token::BEGIN_LIST
Begin list [isseparator].
Definition: token.H:155