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-------------------------------------------------------------------------------
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 "token.H"
29#include "List.H"
30#include "Istream.H"
31#include "Ostream.H"
32#include <numeric>
33
34// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
35
36namespace Foam
37{
38
39 template<class T>
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
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()
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)
88Foam::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// ************************************************************************* //
scalar range
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:58
An interval of (signed) integers defined by a start and a size.
Definition: IntRange.H:64
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
bool readEnd(const char *funcName)
End read of data chunk, ends with ')'.
Definition: Istream.C:129
bool readBegin(const char *funcName)
Begin read of data chunk, starts with '('.
Definition: Istream.C:111
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
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
iterator begin() noexcept
Return an iterator to begin traversing the UList.
Definition: UListI.H:329
iterator end() noexcept
Return an iterator to end traversing the UList.
Definition: UListI.H:350
@ BEGIN_LIST
Begin list [isseparator].
Definition: token.H:155
@ END_LIST
End list [isseparator].
Definition: token.H:156
@ SPACE
Space [isspace].
Definition: token.H:125
OBJstream os(runTime.globalPath()/outputName)
#define FUNCTION_NAME
Namespace for OpenFOAM.
labelList identity(const label len, label start=0)
Return an identity map of the given length with (map[i] == i)
Definition: labelList.C:38
static Istream & input(Istream &is, IntRange< T > &range)
Definition: IntRanges.C:55
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Istream & operator>>(Istream &, directionInfo &)
static Ostream & output(Ostream &os, const IntRange< T > &range)
Definition: IntRanges.C:66
static List< label > makeIdentity(const IntRange< T > &range)
Definition: IntRanges.C:40