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 #include <algorithm>
33 
34 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
35 
37 :
38  start_(coeffs[0]),
39  size_(std::max(label(0),coeffs[1])), // No negative size
40  stride_(std::max(label(0),coeffs[2])) // No negative stride
41 {}
42 
43 
44 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
45 
47 {
48  List<label> result(size_);
49 
50  if (stride_)
51  {
52  std::copy(cbegin(), cend(), result.begin());
53  }
54  else
55  {
56  // stride = 0 (identical values!)
57  std::fill(result.begin(), result.end(), start_);
58  }
59 
60  return result;
61 }
62 
63 
64 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
65 
67 {
68  label beg, len, stride;
69 
70  is.readBegin("sliceRange");
71  is >> beg >> len >> stride;
72  is.readEnd("sliceRange");
73 
74  range = sliceRange(beg, len, stride);
75 
76  is.check(FUNCTION_NAME);
77  return is;
78 }
79 
80 
82 {
84  << range.start() << token::SPACE
85  << range.size() << token::SPACE
86  << range.stride() << token::END_LIST;
87 
89  return os;
90 }
91 
92 
93 // ************************************************************************* //
token.H
Foam::sliceRange::labels
List< label > labels() const
Return list of labels corresponding to the slice.
Definition: sliceRange.C:46
List.H
sliceRange.H
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::max
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
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)
stdFoam::cend
constexpr auto cend(const C &c) -> decltype(c.end())
Return const_iterator to the end of the container c.
Definition: stdFoam.H:137
Foam::sliceRange
A set of labels defined by a start, a length and a stride.
Definition: sliceRange.H:58
Foam::sliceRange::sliceRange
constexpr sliceRange() noexcept
Default construct an empty slice (0,0,0)
Definition: sliceRangeI.H:32
range
scalar range
Definition: LISASMDCalcMethod1.H:12
stdFoam::cbegin
constexpr auto cbegin(const C &c) -> decltype(c.begin())
Return const_iterator to the beginning of the container c.
Definition: stdFoam.H:113
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:63
Foam::FixedList< label, 3 >
Foam::token::SPACE
Space [isspace].
Definition: token.H:125
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
FixedList.H
Foam::token::BEGIN_LIST
Begin list [isseparator].
Definition: token.H:155