SortableList.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 | Copyright (C) 2011-2013 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "ListOps.H"
27 
28 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
29 
30 template<class T>
32 {}
33 
34 
35 template<class T>
37 :
38  List<T>(values)
39 {
40  sort();
41 }
42 
43 
44 template<class T>
45 Foam::SortableList<T>::SortableList(const Xfer<List<T> >& values)
46 :
47  List<T>(values)
48 {
49  sort();
50 }
51 
52 
53 template<class T>
55 :
56  List<T>(size)
57 {}
58 
59 
60 template<class T>
61 Foam::SortableList<T>::SortableList(const label size, const T& val)
62 :
63  List<T>(size, val)
64 {}
65 
66 
67 template<class T>
68 Foam::SortableList<T>::SortableList(const SortableList<T>& lst)
69 :
70  List<T>(lst),
71  indices_(lst.indices())
72 {}
73 
74 
75 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
76 
77 
78 template<class T>
80 {
82  indices_.clear();
83 }
84 
85 
86 template<class T>
88 {
89  indices_.clear();
90  return static_cast<List<T>&>(*this);
91 }
92 
93 
94 template<class T>
96 {
97  sortedOrder(*this, indices_);
98 
99  List<T> lst(this->size());
100  forAll(indices_, i)
101  {
102  lst[i] = this->operator[](indices_[i]);
103  }
104 
105  List<T>::transfer(lst);
106 }
107 
108 
109 template<class T>
111 {
112  sortedOrder(*this, indices_, typename UList<T>::greater(*this));
113 
114  List<T> lst(this->size());
115  forAll(indices_, i)
116  {
117  lst[i] = this->operator[](indices_[i]);
118  }
119 
120  List<T>::transfer(lst);
121 }
122 
123 
124 template<class T>
126 {
127  return xferMoveTo<List<T> >(*this);
128 }
129 
130 
131 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
132 
133 template<class T>
134 inline void Foam::SortableList<T>::operator=(const T& t)
135 {
137 }
138 
139 
140 template<class T>
141 inline void Foam::SortableList<T>::operator=(const UList<T>& rhs)
142 {
143  List<T>::operator=(rhs);
144  indices_.clear();
145 }
146 
147 
148 template<class T>
149 inline void Foam::SortableList<T>::operator=(const SortableList<T>& rhs)
150 {
151  List<T>::operator=(rhs);
152  indices_ = rhs.indices();
153 }
154 
155 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
156 
157 // ************************************************************************* //
Foam::SortableList::sort
void sort()
(stable) sort the list (if changed after construction time)
Definition: SortableList.C:95
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::SortableList::reverseSort
void reverseSort()
Reverse (stable) sort the list.
Definition: SortableList.C:110
Foam::List::transfer
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
Foam::List::operator=
void operator=(const UList< T > &)
Assignment from UList operator. Takes linear time.
Foam::SortableList::operator=
void operator=(const T &)
Assignment of all entries to the given value.
Foam::Xfer
A simple container for copying or transferring objects of type <T>.
Definition: Xfer.H:85
Foam::sortedOrder
void sortedOrder(const UList< T > &, labelList &order)
Generate the (stable) sort order for the list.
Definition: ListOpsTemplates.C:179
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:59
Foam::SortableList::SortableList
SortableList()
Null constructor, sort later (eg, after assignment or transfer)
Definition: SortableList.C:31
Foam::T
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Definition: FieldFieldFunctions.C:55
Foam::SortableList::shrink
List< T > & shrink()
Clear the indices and return a reference to the underlying List.
Definition: SortableList.C:87
T
const volScalarField & T
Definition: createFields.H:25
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::UList< T >
Foam::List::clear
void clear()
Clear the list, i.e. set size to zero.
Definition: List.C:379
List
Definition: Test.C:19
ListOps.H
Various functions to operate on Lists.
Foam::SortableList::clear
void clear()
Clear the list and the indices.
Definition: SortableList.C:79
Foam::UList::operator=
void operator=(const T &)
Assignment of all entries to the given value.
Definition: UList.C:70
Foam::SortableList::xfer
Xfer< List< T > > xfer()
Transfer contents to the Xfer container as a plain List.
Definition: SortableList.C:125