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