From 2b53bc4c435547768fb2d986f8deead8738beb16 Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Fri, 11 Nov 2016 14:41:50 +0100 Subject: [PATCH] Add begin() and end() to Box. --- opm/parser/eclipse/EclipseState/Grid/Box.cpp | 10 ++++++++++ opm/parser/eclipse/EclipseState/Grid/Box.hpp | 3 ++- .../eclipse/EclipseState/Grid/tests/BoxTests.cpp | 8 +++++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/opm/parser/eclipse/EclipseState/Grid/Box.cpp b/opm/parser/eclipse/EclipseState/Grid/Box.cpp index f3e970303..75b1283d1 100644 --- a/opm/parser/eclipse/EclipseState/Grid/Box.cpp +++ b/opm/parser/eclipse/EclipseState/Grid/Box.cpp @@ -103,6 +103,16 @@ namespace Opm { } + + std::vector::const_iterator Box::begin() const { + return m_indexList.begin(); + } + + std::vector::const_iterator Box::end() const { + return m_indexList.end(); + } + + const std::vector& Box::getIndexList() const { return m_indexList; } diff --git a/opm/parser/eclipse/EclipseState/Grid/Box.hpp b/opm/parser/eclipse/EclipseState/Grid/Box.hpp index abab90963..ca379399d 100644 --- a/opm/parser/eclipse/EclipseState/Grid/Box.hpp +++ b/opm/parser/eclipse/EclipseState/Grid/Box.hpp @@ -38,7 +38,8 @@ namespace Opm { bool equal(const Box& other) const; explicit operator bool() const; - + std::vector::const_iterator begin() const; + std::vector::const_iterator end() const; private: void initIndexList(); diff --git a/opm/parser/eclipse/EclipseState/Grid/tests/BoxTests.cpp b/opm/parser/eclipse/EclipseState/Grid/tests/BoxTests.cpp index 0e888cb51..1adfa714b 100644 --- a/opm/parser/eclipse/EclipseState/Grid/tests/BoxTests.cpp +++ b/opm/parser/eclipse/EclipseState/Grid/tests/BoxTests.cpp @@ -53,10 +53,16 @@ BOOST_AUTO_TEST_CASE(CreateBox) { for (i=0; i < box.getDim(0); i++) { size_t g = i + j*box.getDim(0) + k*box.getDim(0)*box.getDim(1); BOOST_CHECK_EQUAL( indexList[g] , g); - + } } } + + i = 0; + for (auto index : box) { + BOOST_CHECK_EQUAL( index , indexList[i]); + i++; + } } }