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 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  // Or even this
55  // std::generate(result.begin(), result.end(), generator());
56  }
57  else
58  {
59  std::fill(result.begin(), result.end(), start_);
60  }
61 
62  return result;
63 }
64 
65 
66 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
67 
69 {
70  os << token::BEGIN_LIST
71  << range.start() << token::SPACE
72  << range.size() << token::SPACE
73  << range.stride() << token::END_LIST;
74 
75  os.check(FUNCTION_NAME);
76  return os;
77 }
78 
79 
80 // ************************************************************************* //
token.H
Foam::sliceRange::labels
List< label > labels() const
Return the slice as a list of labels.
Definition: sliceRange.C:46
List.H
sliceRange.H
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:62
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:51
stdFoam::cend
constexpr auto cend(const C &c) -> decltype(c.end())
Return const_iterator to the end of the container c.
Definition: stdFoam.H:131
Foam::sliceRange
A set of labels defined by a start, a length and a stride.
Definition: sliceRange.H:56
Foam::sliceRange::sliceRange
constexpr sliceRange() noexcept
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:107
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:102
Foam::FixedList< label, 3 >
Foam::token::SPACE
Space [isspace].
Definition: token.H:112
FUNCTION_NAME
#define FUNCTION_NAME
Definition: messageStream.H:261
Foam::token::END_LIST
End list [isseparator].
Definition: token.H:118
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:117
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &)
Definition: boundaryPatch.C:102