FixedList.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) 2011-2015 OpenFOAM Foundation
9  Copyright (C) 2017-2019 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "FixedList.H"
30 #include "ListLoopM.H"
31 
32 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
33 
34 template<class T, unsigned N>
36 (
37  const T& val,
38  const label start
39 ) const
40 {
41  if (start >= 0)
42  {
43  List_CONST_ACCESS(T, *this, list);
44 
45  for (label i = start; i < label(N); ++i)
46  {
47  if (list[i] == val)
48  {
49  return i;
50  }
51  }
52  }
53 
54  return -1;
55 }
56 
57 
58 template<class T, unsigned N>
60 {
61  checkIndex(i);
62 
63  for (label lower = 0; lower < i; ++lower)
64  {
65  Foam::Swap(v_[lower], v_[i]);
66  }
67 }
68 
69 
70 template<class T, unsigned N>
72 {
73  checkIndex(i);
74 
75  for (label upper = label(N-1); upper > i; --upper)
76  {
77  Foam::Swap(v_[i], v_[upper]);
78  }
79 }
80 
81 
82 template<class T, unsigned N>
84 {
85  checkIndex(i);
86 
87  if (i > 0)
88  {
89  Foam::Swap(v_[0], v_[i]);
90  }
91 }
92 
93 
94 template<class T, unsigned N>
96 {
97  checkIndex(i);
98 
99  const label upper = label(N-1);
100 
101  if (i < upper)
102  {
103  Foam::Swap(v_[i], v_[upper]);
104  }
105 }
106 
107 
108 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
109 
110 template<class T, unsigned N>
112 {
113  List_CONST_ACCESS(T, *this, lhs);
114  List_CONST_ACCESS(T, (list), rhs);
115 
116  // List sizes are identical by definition (template parameter)
117  for (unsigned i = 0; i < N; ++i)
118  {
119  if (!(lhs[i] == rhs[i]))
120  {
121  return false;
122  }
123  }
124 
125  // Contents appear to be identical.
126  return true;
127 }
128 
129 
130 template<class T, unsigned N>
132 {
133  List_CONST_ACCESS(T, *this, lhs);
134  List_CONST_ACCESS(T, (list), rhs);
135 
136  // List sizes are identical by definition (template parameter)
137  for (unsigned i=0; i<N; ++i)
138  {
139  if (lhs[i] < rhs[i])
140  {
141  return true;
142  }
143  else if (rhs[i] < lhs[i])
144  {
145  return false;
146  }
147  }
148 
149  // Contents appear to be identical.
150  return false;
151 }
152 
153 
154 template<class T, unsigned N>
156 {
157  return !operator==(list);
158 }
159 
160 
161 template<class T, unsigned N>
163 {
164  return list.operator<(*this);
165 }
166 
167 
168 template<class T, unsigned N>
170 {
171  return !list.operator<(*this);
172 }
173 
174 
175 template<class T, unsigned N>
177 {
178  return !operator<(list);
179 }
180 
181 
182 // * * * * * * * * * * * * * * * * IOStream operators * * * * * * * * * * * //
183 
184 #include "FixedListIO.C"
185 
186 // ************************************************************************* //
FixedListIO.C
Foam::val
label ListType::const_reference val
Definition: ListOps.H:407
Foam::FixedList::swapLast
void swapLast(const label i)
Swap element with the last element.
Definition: FixedList.C:95
Foam::FixedList::operator<=
bool operator<=(const FixedList< T, N > &list) const
Return true if !(a > b). Takes linear time.
Definition: FixedList.C:169
Foam::stringOps::lower
string lower(const std::string &str)
Return string transformed with std::tolower on each character.
Definition: stringOps.C:1199
Foam::FixedList::operator!=
bool operator!=(const FixedList< T, N > &list) const
The opposite of the equality operation. Takes linear time.
Definition: FixedList.C:155
Foam::Swap
void Swap(DynamicList< T, SizeMin1 > &a, DynamicList< T, SizeMin2 > &b)
Definition: DynamicListI.H:909
Foam::FixedList::operator==
bool operator==(const FixedList< T, N > &list) const
Equality operation on FixedLists of the same type.
Definition: FixedList.C:111
Foam::FixedList::operator<
bool operator<(const FixedList< T, N > &list) const
Compare two FixedLists lexicographically. Takes linear time.
Definition: FixedList.C:131
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::operator==
tmp< faMatrix< Type > > operator==(const faMatrix< Type > &, const faMatrix< Type > &)
Foam::stringOps::upper
string upper(const std::string &str)
Return string transformed with std::toupper on each character.
Definition: stringOps.C:1219
Foam::FixedList::find
label find(const T &val, const label start=0) const
Find index of the first occurence of the value.
Definition: FixedList.C:36
Foam::FixedList::moveFirst
void moveFirst(const label i)
Move element to the first position.
Definition: FixedList.C:59
T
const volScalarField & T
Definition: createFieldRefs.H:2
List_CONST_ACCESS
#define List_CONST_ACCESS(type, f, fp)
Definition: ListLoopM.H:43
Foam::operator<
bool operator<(const Instant< T1 > &a, const Instant< T2 > &b)
Compare instant values for less-than.
Definition: Instant.C:90
Foam::FixedList::operator>
bool operator>(const FixedList< T, N > &list) const
Compare two FixedLists lexicographically. Takes linear time.
Definition: FixedList.C:162
Foam::FixedList::operator>=
bool operator>=(const FixedList< T, N > &list) const
Return true if !(a < b). Takes linear time.
Definition: FixedList.C:176
Foam::FixedList::swapFirst
void swapFirst(const label i)
Swap element with the first element.
Definition: FixedList.C:83
Foam::start
label ListType::const_reference const label start
Definition: ListOps.H:408
Foam::FixedList
A 1D vector of objects of type <T> with a fixed length <N>.
Definition: HashTable.H:104
N
const Vector< label > N(dict.get< Vector< label >>("N"))
FixedList.H
ListLoopM.H
Macros for accessing List elements.
Foam::FixedList::moveLast
void moveLast(const label i)
Move element to the last position.
Definition: FixedList.C:71