From 0cfd019b92e20c63291e19b8df100c7fa20d6f97 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 6 Aug 2019 12:00:56 +0200 Subject: [PATCH] STYLE: add data/cdata to VectorSpace for consistency with FixedList etc --- applications/test/vector/Test-vector.C | 20 +++++++++++++++++++ .../primitives/VectorSpace/VectorSpace.H | 8 +++++++- .../primitives/VectorSpace/VectorSpaceI.H | 14 +++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/applications/test/vector/Test-vector.C b/applications/test/vector/Test-vector.C index fc3e430882..799dfd83f1 100644 --- a/applications/test/vector/Test-vector.C +++ b/applications/test/vector/Test-vector.C @@ -87,6 +87,25 @@ void testIterator(const VecSpace& vs) } +template +void testData(const VecSpace& vs) +{ + Info<< "size: " << vs.size() << " for:"; + + const auto* data = vs.cdata(); + for + ( + const auto* endData = data + VecSpace::nComponents; + data != endData; + ++data + ) + { + Info<< " " << *data; + } + Info<< nl; +} + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // Main program: @@ -105,6 +124,7 @@ int main(int argc, char *argv[]) testIterator(vec1); testIterator(vec2); + testData(vec2); // Use STL algorithm(s) diff --git a/src/OpenFOAM/primitives/VectorSpace/VectorSpace.H b/src/OpenFOAM/primitives/VectorSpace/VectorSpace.H index 738da8248c..510c29ded5 100644 --- a/src/OpenFOAM/primitives/VectorSpace/VectorSpace.H +++ b/src/OpenFOAM/primitives/VectorSpace/VectorSpace.H @@ -178,6 +178,12 @@ public: inline void component(Cmpt&, const direction) const; inline void replace(const direction, const Cmpt&); + //- Return const pointer to the first data element + inline const Cmpt* cdata() const noexcept; + + //- Return pointer to the first data element + inline Cmpt* data() noexcept; + //- Return a VectorSpace with all elements = s inline static Form uniform(const Cmpt& s); @@ -213,7 +219,7 @@ public: //- Return an iterator to begin of VectorSpace inline iterator begin(); - //- Return an iterator to end of UListVectorSpace + //- Return an iterator to end of VectorSpace inline iterator end(); diff --git a/src/OpenFOAM/primitives/VectorSpace/VectorSpaceI.H b/src/OpenFOAM/primitives/VectorSpace/VectorSpaceI.H index bba3f77740..d81a43cdfc 100644 --- a/src/OpenFOAM/primitives/VectorSpace/VectorSpaceI.H +++ b/src/OpenFOAM/primitives/VectorSpace/VectorSpaceI.H @@ -193,6 +193,20 @@ Foam::VectorSpace::block() const // * * * * * * * * * * * * * * * * Iterator * * * * * * * * * * * * * * * * // +template +inline Cmpt* Foam::VectorSpace::data() noexcept +{ + return v_; +} + + +template +inline const Cmpt* Foam::VectorSpace::cdata() const noexcept +{ + return v_; +} + + template inline Cmpt* Foam::VectorSpace::begin() {