From 805b76d4b9a6d6bb97f5a8f93b5665d26f7248ed Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Mon, 1 May 2017 14:01:09 +0200 Subject: [PATCH] ENH: support UList[labelRange] and SubList construction with labelRange This uses a concept similar to what std::valarray and std::slice do. A labelRange provides a convenient container for holding start/size and lends itself to addressing 'sliced' views of lists. For safety, the operations and constructors restricts the given input range to a valid addressible region of the underlying list, while the labelRange itself precludes negative sizes. The SubList version is useful for patches or other things that have a SubList as its parameter. Otherwise the UList [] operator will be the more natural solution. The slices can be done with a labelRange, or a {start,size} pair. Examples, labelList list1 = identity(20); list1[labelRange(18,10)] = -1; list1[{-20,25}] = -2; list1[{1000,5}] = -3; const labelList list2 = identity(20); list2[{5,10}] = -3; // ERROR: cannot assign to const! --- applications/test/List/Test-List.C | 62 +++++++++++++- .../containers/Lists/SubList/SubList.H | 27 ++++-- .../containers/Lists/SubList/SubListI.H | 33 ++++++-- src/OpenFOAM/containers/Lists/UList/UList.C | 83 ++++++++++++++++++- src/OpenFOAM/containers/Lists/UList/UList.H | 37 ++++++++- src/OpenFOAM/containers/Lists/UList/UListI.H | 7 +- 6 files changed, 229 insertions(+), 20 deletions(-) diff --git a/applications/test/List/Test-List.C b/applications/test/List/Test-List.C index bbba8219b3..9ab2732c2e 100644 --- a/applications/test/List/Test-List.C +++ b/applications/test/List/Test-List.C @@ -76,7 +76,6 @@ int main(int argc, char *argv[]) Info<<"is >>: " << intlist << endl; } - List list1(IStringStream("1 ((0 1 2))")()); Info<< "list1: " << list1 << endl; @@ -150,7 +149,6 @@ int main(int argc, char *argv[]) Info<< "normal: " << longLabelList << nl; Info<< "flatOutput: " << flatOutput(longLabelList) << nl; // Info<< "flatOutput(14): " << flatOutput(longLabelList, 14) << nl; - // Info<< "flatOutput(15): " << flatOutput(longLabelList, 15) << nl; stringList longStringList(12); forAll(longStringList, i) @@ -165,6 +163,66 @@ int main(int argc, char *argv[]) // contiguous longStringList[i].resize(3, 'a' + i); } + // test SubList and labelRange + { + Info<< nl; + labelList longLabelList = identity(25); + reverse(longLabelList); + + FixedList fixedLabelList{0,1,2,3,4,5}; + const labelList constLabelList = identity(25); + + Info<< "full-list: " << flatOutput(longLabelList) << nl; + + labelRange range1(-15, 25); + Info<<"sub range:" << range1 << "="; + Info<< SubList