From ed12c73af4d80ca3f667c790baff12fa8b88fc4f Mon Sep 17 00:00:00 2001 From: mark <mark@opencfd> Date: Tue, 24 Jan 2017 12:59:13 +0100 Subject: [PATCH] BUG: not incrementing when reading via singly-linked list --- applications/test/List/Test-List.C | 21 +++++++++++++++++-- src/OpenFOAM/containers/Lists/List/ListIO.C | 2 +- src/OpenFOAM/containers/Lists/UList/UList.C | 2 +- src/OpenFOAM/containers/Lists/UList/UListIO.C | 14 ++++++------- 4 files changed, 28 insertions(+), 11 deletions(-) diff --git a/applications/test/List/Test-List.C b/applications/test/List/Test-List.C index 65073700ab1..fc8fab51780 100644 --- a/applications/test/List/Test-List.C +++ b/applications/test/List/Test-List.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -42,7 +42,11 @@ See also #include "vector.H" #include "ListOps.H" -#include<list> +#include "labelRange.H" +#include "ListOps.H" +#include "SubList.H" + +#include <list> using namespace Foam; @@ -61,6 +65,19 @@ int main(int argc, char *argv[]) #include "setRootCase.H" + if (false) + { + labelList intlist(IStringStream("(0 1 2)")()); + Info<<"construct from Istream: " << intlist << endl; + + IStringStream("(3 4 5)")() >> static_cast<labelUList&>(intlist); + Info<<"is >>: " << intlist << endl; + + IStringStream("(6 7 8)")() >> intlist; + Info<<"is >>: " << intlist << endl; + } + + List<vector> list1(IStringStream("1 ((0 1 2))")()); Info<< "list1: " << list1 << endl; diff --git a/src/OpenFOAM/containers/Lists/List/ListIO.C b/src/OpenFOAM/containers/Lists/List/ListIO.C index bbc55ec10dd..6229cb94904 100644 --- a/src/OpenFOAM/containers/Lists/List/ListIO.C +++ b/src/OpenFOAM/containers/Lists/List/ListIO.C @@ -64,7 +64,7 @@ Foam::Istream& Foam::operator>>(Istream& is, List<T>& L) } else if (firstToken.isLabel()) { - label s = firstToken.labelToken(); + const label s = firstToken.labelToken(); // Set list length to that read L.setSize(s); diff --git a/src/OpenFOAM/containers/Lists/UList/UList.C b/src/OpenFOAM/containers/Lists/UList/UList.C index 52177d79bcb..320b22f68fe 100644 --- a/src/OpenFOAM/containers/Lists/UList/UList.C +++ b/src/OpenFOAM/containers/Lists/UList/UList.C @@ -183,7 +183,7 @@ bool Foam::UList<T>::operator<(const UList<T>& a) const ( const_iterator vi = begin(), ai = a.begin(); vi < end() && ai < a.end(); - vi++, ai++ + ++vi, ++ai ) { if (*vi < *ai) diff --git a/src/OpenFOAM/containers/Lists/UList/UListIO.C b/src/OpenFOAM/containers/Lists/UList/UListIO.C index a4648137cfc..0559a63adce 100644 --- a/src/OpenFOAM/containers/Lists/UList/UListIO.C +++ b/src/OpenFOAM/containers/Lists/UList/UListIO.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -165,7 +165,7 @@ Foam::Istream& Foam::operator>>(Istream& is, UList<T>& L) ) ); // Check list length - label s = elems.size(); + const label s = elems.size(); if (s != L.size()) { @@ -174,14 +174,14 @@ Foam::Istream& Foam::operator>>(Istream& is, UList<T>& L) << " expected " << L.size() << exit(FatalIOError); } - for (label i=0; i<s; i++) + for (label i=0; i<s; ++i) { L[i] = elems[i]; } } else if (firstToken.isLabel()) { - label s = firstToken.labelToken(); + const label s = firstToken.labelToken(); // Set list length to that read if (s != L.size()) @@ -203,7 +203,7 @@ Foam::Istream& Foam::operator>>(Istream& is, UList<T>& L) { if (delimiter == token::BEGIN_LIST) { - for (label i=0; i<s; i++) + for (label i=0; i<s; ++i) { is >> L[i]; @@ -226,7 +226,7 @@ Foam::Istream& Foam::operator>>(Istream& is, UList<T>& L) "reading the single entry" ); - for (label i=0; i<s; i++) + for (label i=0; i<s; ++i) { L[i] = element; } @@ -281,7 +281,7 @@ Foam::Istream& Foam::operator>>(Istream& is, UList<T>& L) ( typename SLList<T>::const_iterator iter = sll.begin(); iter != sll.end(); - ++iter + ++iter, ++i ) { L[i] = iter(); -- GitLab