sliceRange.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) 2019-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 "sliceRange.H"
29 #include "FixedList.H"
30 #include "List.H"
31 #include "token.H"
32 
33 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
34 
36 :
37  start_(coeffs[0]),
38  size_(std::max(label(0),coeffs[1])), // No negative size
39  stride_(std::max(label(0),coeffs[2])) // No negative stride
40 {}
41 
42 
43 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
44 
46 {
47  List<label> result(size_);
48 
49  if (stride_)
50  {
51  std::copy(cbegin(), cend(), result.begin());
52  }
53  else
54  {
55  // stride = 0 (identical values!)
56  std::fill(result.begin(), result.end(), start_);
57  }
58 
59  return result;
60 }
61 
62 
63 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
64 
65 Foam::Istream& Foam::operator>>(Istream& is, sliceRange& range)
66 {
67  label beg, len, stride;
68 
69  is.readBegin("sliceRange");
70  is >> beg >> len >> stride;
71  is.readEnd("sliceRange");
72 
73  range = sliceRange(beg, len, stride);
74 
75  is.check(FUNCTION_NAME);
76  return is;
77 }
78 
79 
80 Foam::Ostream& Foam::operator<<(Ostream& os, const sliceRange& range)
81 {
83  << range.start() << token::SPACE
84  << range.size() << token::SPACE
85  << range.stride() << token::END_LIST;
86 
88  return os;
89 }
90 
91 
92 // ************************************************************************* //
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:45
bool readBegin(const char *funcName)
Begin read of data chunk, starts with &#39;(&#39;.
Definition: Istream.C:104
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:56
const_iterator cbegin() const noexcept
A const_iterator set to the beginning of the range.
Definition: sliceRangeI.H:315
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:40
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
List< label > labels() const
Return list of labels corresponding to the slice.
Definition: sliceRange.C:38
Begin list [isseparator].
Definition: token.H:158
scalar range
Istream & operator>>(Istream &, directionInfo &)
Space [isspace].
Definition: token.H:128
End list [isseparator].
Definition: token.H:159
constexpr sliceRange() noexcept
Default construct an empty slice (0,0,0)
Definition: sliceRangeI.H:23
A set of labels defined by a start, a length and a stride.
Definition: sliceRange.H:52
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:55
OBJstream os(runTime.globalPath()/outputName)
#define FUNCTION_NAME
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:76
const_iterator cend() const noexcept
A const_iterator set to 1 beyond the end of the range.
Definition: sliceRangeI.H:329