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-------------------------------------------------------------------------------
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 "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
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// ************************************************************************* //
scalar range
Y[inertIndex] max(0.0)
A 1D vector of objects of type <T> with a fixed length <N>.
Definition: FixedList.H:81
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:58
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
A set of labels defined by a start, a length and a stride.
Definition: sliceRange.H:59
constexpr sliceRange() noexcept
Default construct an empty slice (0,0,0)
Definition: sliceRangeI.H:32
List< label > labels() const
Return list of labels corresponding to the slice.
Definition: sliceRange.C:46
@ 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
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Istream & operator>>(Istream &, directionInfo &)