OpenFOAM: API Guide
v2006
The open source CFD toolbox
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
-------------------------------------------------------------------------------
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
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
29
30
template
<
class
T,
class
Addr>
31
Foam::label
Foam::IndirectListBase<T, Addr>::find
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
58
template
<
class
T,
class
Addr>
59
Foam::label
Foam::IndirectListBase<T, Addr>::rfind
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
// ************************************************************************* //
Foam::IndirectListBase::rfind
label rfind(const T &val, label pos=-1) const
Find index of the last occurrence of the value.
Definition:
IndirectListBase.C:60
Foam::IndirectListBase::find
label find(const T &val, label pos=0) const
Find index of the first occurrence of the value.
Definition:
IndirectListBase.C:32
T
const volScalarField & T
Definition:
createFieldRefs.H:2
List_CONST_ACCESS
#define List_CONST_ACCESS(type, f, fp)
Definition:
ListLoopM.H:43
Foam::pos
dimensionedScalar pos(const dimensionedScalar &ds)
Definition:
dimensionedScalar.C:177
src
OpenFOAM
containers
IndirectLists
IndirectListBase
IndirectListBase.C
Generated by
1.8.17
OPENFOAM® is a registered
trademark
of OpenCFD Ltd.