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-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// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
29
30template<class T, class Addr>
32(
33 const T& val,
34 label pos
35) const
36{
37 const label len = addr_.size();
38
39 if (pos >= 0 && len)
40 {
41 List_CONST_ACCESS(T, values_, vals);
42
43 while (pos < len)
44 {
45 if (vals[addr_[pos]] == val)
46 {
47 return pos;
48 }
49
50 ++pos;
51 }
52 }
53
54 return -1;
55}
56
57
58template<class T, class Addr>
60(
61 const T& val,
62 label pos
63) const
64{
65 // pos == -1 has same meaning as std::string::npos - search from end
66
67 if (pos < 0 || pos >= addr_.size())
68 {
69 pos = addr_.size()-1;
70 }
71
72 List_CONST_ACCESS(T, values_, vals);
73
74 while (pos >= 0)
75 {
76 if (vals[addr_[pos]] == val)
77 {
78 return pos;
79 }
80
81 --pos;
82 }
83
84 return -1;
85}
86
87
88// ************************************************************************* //
#define List_CONST_ACCESS(type, f, fp)
Definition: ListLoopM.H:43
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) const
Find index of the first occurrence of the value.
const volScalarField & T
dimensionedScalar pos(const dimensionedScalar &ds)