Skip to content
Snippets Groups Projects
Commit 6c387489 authored by mattijs's avatar mattijs
Browse files

subset constructor

parent 642dadf1
No related branches found
No related tags found
No related merge requests found
...@@ -46,7 +46,7 @@ int main(int argc, char *argv[]) ...@@ -46,7 +46,7 @@ int main(int argc, char *argv[])
List<vector> list(IStringStream("1 ((0 1 2))")()); List<vector> list(IStringStream("1 ((0 1 2))")());
Info<< list << endl; Info<< list << endl;
List<vector> list2(IStringStream("((0 1 2) (3 4 5) (3 4 5))")()); List<vector> list2(IStringStream("((0 1 2) (3 4 5) (6 7 8))")());
Info<< list2 << endl; Info<< list2 << endl;
Info<< findIndex(list2, vector(3, 4, 5)) << endl; Info<< findIndex(list2, vector(3, 4, 5)) << endl;
...@@ -59,6 +59,13 @@ int main(int argc, char *argv[]) ...@@ -59,6 +59,13 @@ int main(int argc, char *argv[])
Info<< list2 << nl Info<< list2 << nl
<< list3 << endl; << list3 << endl;
// Subset
const labelList map(IStringStream("2 (0 2)")());
List<vector> subList3(list3, map);
Info<< "Elements " << map << " out of " << list3
<< " : " << subList3 << endl;
return 0; return 0;
} }
......
...@@ -171,6 +171,29 @@ Foam::List<T>::List(List<T>& a, bool reUse) ...@@ -171,6 +171,29 @@ Foam::List<T>::List(List<T>& a, bool reUse)
} }
// Construct as subset
template<class T>
Foam::List<T>::List(const UList<T>& a, const unallocLabelList& map)
:
UList<T>(NULL, map.size())
{
if (this->size_)
{
this->v_ = new T[this->size_];
List_ACCESS(T, (*this), vp);
List_CONST_ACCESS(T, a, ap);
List_FOR_ALL(map, i)
List_ELEM((*this), vp, i) = List_ELEM(a, ap, (map[i]));
List_END_FOR_ALL
}
else
{
this->v_ = 0;
}
}
// Construct given start and end iterators. // Construct given start and end iterators.
template<class T> template<class T>
template<class InputIterator> template<class InputIterator>
......
...@@ -68,6 +68,7 @@ template<class T> class SortableList; ...@@ -68,6 +68,7 @@ template<class T> class SortableList;
template<class T> class IndirectList; template<class T> class IndirectList;
template<class T> class BiIndirectList; template<class T> class BiIndirectList;
typedef UList<label> unallocLabelList;
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class List Declaration Class List Declaration
...@@ -112,6 +113,9 @@ public: ...@@ -112,6 +113,9 @@ public:
//- Construct as copy or re-use as specified. //- Construct as copy or re-use as specified.
List(List<T>&, bool reUse); List(List<T>&, bool reUse);
//- Construct as subset.
List(const UList<T>&, const unallocLabelList& mapAddressing);
//- Construct given start and end iterators. //- Construct given start and end iterators.
template<class InputIterator> template<class InputIterator>
List(InputIterator first, InputIterator last); List(InputIterator first, InputIterator last);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment