Loading...
Searching...
No Matches
IndirectListBase.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) 2017-2022 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// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
29
30template<class T, class Addr>
32(
33 const T& val,
34 label pos,
35 label len
36) const
37{
38 if (pos >= 0 && pos < addr_.size())
39 {
40 // Change sub-length to (one-past) end position
41 // len == -1 (like std::string::npos) - search until end
42
43 if (len > 0) len += pos;
44 if (len < 0 || len > addr_.size())
45 {
46 len = addr_.size();
47 }
48
49 const T* const vals = values_.begin();
50
51 while (pos < len)
52 {
53 if (vals[addr_[pos]] == val)
54 {
55 return pos;
56 }
57
58 ++pos;
59 }
60 }
61
62 return -1;
63}
64
65
66template<class T, class Addr>
68(
69 const T& val,
70 label pos
71) const
72{
73 // pos == -1 (like std::string::npos) - search from end
74
75 if (pos < 0 || pos >= addr_.size())
76 {
77 pos = addr_.size()-1;
78 }
79
80 const T* const vals = values_.begin();
81
82 while (pos >= 0)
83 {
84 if (vals[addr_[pos]] == val)
85 {
86 return pos;
87 }
88
89 --pos;
90 }
91
92 return -1;
93}
94
95
96// ************************************************************************* //
label rfind(const T &val, label pos=-1) const
Find index of the last occurrence of the value.
label find(const T &val, label pos=0, label len=-1) const
Find index of the first occurrence of the value.
const volScalarField & T
dimensionedScalar pos(const dimensionedScalar &ds)
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)