diff --git a/meshLibrary/utilities/containers/VRWGraph/VRWGraph.H b/meshLibrary/utilities/containers/VRWGraph/VRWGraph.H index c8d8c11052c2247da6f9cfb31115e8b0661bf901..32fb229cf77f1bc66800d5dae76bec3c793683ab 100644 --- a/meshLibrary/utilities/containers/VRWGraph/VRWGraph.H +++ b/meshLibrary/utilities/containers/VRWGraph/VRWGraph.H @@ -38,10 +38,11 @@ SourceFiles #define VRWGraph_H #include "labelLongList.H" -#include "graphRow.H" #include "DynList.H" #include "bool.H" #include "error.H" +#include "graphRow.H" +#include "graphConstRow.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -108,7 +109,7 @@ public: // Useful typedefs -typedef const graphRow constRow; +typedef const graphConstRow constRow; typedef graphRow row; diff --git a/meshLibrary/utilities/containers/VRWGraph/VRWGraphI.H b/meshLibrary/utilities/containers/VRWGraph/VRWGraphI.H index 90f022b321cbff817e784c589459f7b3dc7d2723..d1cfe6fa4b50c6261a604e94470d1e32485a4382 100644 --- a/meshLibrary/utilities/containers/VRWGraph/VRWGraphI.H +++ b/meshLibrary/utilities/containers/VRWGraph/VRWGraphI.H @@ -25,19 +25,21 @@ License inline void Foam::VRWGraph::checkIndex(const label i, const label j) const { - if ((i < 0) || (i >= rows_.size())) + if (i < 0 || i >= rows_.size()) { FatalErrorInFunction << "Row index " << i - << " is not in range " << 0 - << " and " << rows_.size() << abort(FatalError); + << " is not in range [0.." << rows_.size() << ")" + << abort(FatalError); } - if ((j < 0) || (j >= rows_[i].size())) + if (j < 0 || j >= rows_[i].size()) + { FatalErrorInFunction << "Column index " << j - << " is not in range " << 0 - << " and " << rows_[i].size() << abort(FatalError); + << " is not in range [0.." << rows_[i].size() << ")" + << abort(FatalError); + } } diff --git a/meshLibrary/utilities/containers/graphRow/graphConstRow.H b/meshLibrary/utilities/containers/graphRow/graphConstRow.H new file mode 100644 index 0000000000000000000000000000000000000000..48f8c65ed246a1c89f1dab06b197eb2a9612d421 --- /dev/null +++ b/meshLibrary/utilities/containers/graphRow/graphConstRow.H @@ -0,0 +1,132 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | cfMesh: A library for mesh generation + \\ / O peration | + \\ / A nd | Author: Franjo Juretic (franjo.juretic@c-fields.com) + \\/ M anipulation | Copyright (C) Creative Fields, Ltd. +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +Class + Foam::graphConstRow + +Description + This class provides const access to a row of a graph + +SourceFiles + graphConstRowI.H + +\*---------------------------------------------------------------------------*/ + +#ifndef graphConstRow_H +#define graphConstRow_H + +#include "Ostream.H" +#include "error.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +class Ostream; +template class graphRow; +template class graphConstRow; + +template +Ostream& operator<<(Ostream&, const graphConstRow&); + + +/*---------------------------------------------------------------------------*\ + Class graphConstRow Declaration +\*---------------------------------------------------------------------------*/ + +template +class graphConstRow +{ + // Private data + + //- Const reference to the graph + const graphType& data_; + + //- Row number + const label rowI_; + + + // Private Member Functions + + //- Avoid possible confusion + void operator=(const graphConstRow&) = delete; + +public: + + // Constructors + + //- Construct from graph and row number + inline graphConstRow(const graphType& g, const label i); + + //- Copy contructor + inline graphConstRow(const graphConstRow& r); + + //- Copy contructor from non-const version + inline graphConstRow(const graphRow& r); + + + //- Destructor + ~graphConstRow() = default; + + + // Member Functions + + //- Return the number of elements in the row + inline label size() const; + + + // Member Operators + + //- check if the element is in the given row (takes linear time) + inline bool contains(const label e) const; + inline bool found(const label e) const; + inline label find(const label e) const; + + //- Get operator + inline label operator[](const label) const; + + // IOstream operators + + //- Write graphConstRow contents to Ostream. + friend Ostream& operator<< + ( + Ostream& os, + const graphConstRow& r + ); + +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#include "graphConstRowI.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/meshLibrary/utilities/containers/graphRow/graphConstRowI.H b/meshLibrary/utilities/containers/graphRow/graphConstRowI.H new file mode 100644 index 0000000000000000000000000000000000000000..ae4f9608dae6972a6b7973698943fc07b220c0a4 --- /dev/null +++ b/meshLibrary/utilities/containers/graphRow/graphConstRowI.H @@ -0,0 +1,130 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | cfMesh: A library for mesh generation + \\ / O peration | + \\ / A nd | Author: Franjo Juretic (franjo.juretic@c-fields.com) + \\/ M anipulation | Copyright (C) Creative Fields, Ltd. +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "Ostream.H" + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +template +inline Foam::graphConstRow::graphConstRow +( + const graphType& g, + const label i +) +: + data_(g), + rowI_(i) +{} + + +template +inline Foam::graphConstRow::graphConstRow +( + const graphConstRow& r +) +: + data_(r.data_), + rowI_(r.rowI_) +{} + + +template +inline Foam::graphConstRow::graphConstRow +( + const graphRow& r +) +: + data_(r.data_), + rowI_(r.rowI_) +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +template +inline Foam::label Foam::graphConstRow::size() const +{ + return data_.sizeOfRow(rowI_); +} + + +template +inline bool Foam::graphConstRow::contains(const label e) const +{ + return data_.contains(rowI_, e); +} + + +template +inline bool Foam::graphConstRow::found(const label e) const +{ + return data_.found(rowI_, e); +} + + +template +inline Foam::label Foam::graphConstRow::find +( + const label e +) const +{ + return data_.find(rowI_, e); +} + + +// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // + +template +inline Foam::label Foam::graphConstRow::operator[] +( + const label i +) const +{ + return data_(rowI_, i); +} + + +template +inline Foam::Ostream& Foam::operator<< +( + Ostream& os, + const Foam::graphConstRow& r +) +{ + const label len = r.size(); + + os << len << '('; + for (label i = 0; i < len; ++i) + { + if (i) os << ' '; + os << r[i]; + } + os << ')'; + + return os; +} + + +// ************************************************************************* // diff --git a/meshLibrary/utilities/containers/graphRow/graphRow.H b/meshLibrary/utilities/containers/graphRow/graphRow.H index 12a37953ba235440717412d5ec4e26c396a64531..59b12a137f5a042445100ea6835bd59df73dcc49 100644 --- a/meshLibrary/utilities/containers/graphRow/graphRow.H +++ b/meshLibrary/utilities/containers/graphRow/graphRow.H @@ -25,7 +25,7 @@ Class Foam::graphRow Description - This class provides access to a row of a graph + This class provides non-const access to a row of a graph SourceFiles graphRowI.H @@ -35,21 +35,18 @@ SourceFiles #ifndef graphRow_H #define graphRow_H -#include "bool.H" -#include "Ostream.H" -#include "error.H" - // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam { - -template -class graphRow; +class Ostream; +template class graphRow; +template class graphConstRow; template Ostream& operator<<(Ostream&, const graphRow&); + /*---------------------------------------------------------------------------*\ Class graphRow Declaration \*---------------------------------------------------------------------------*/ @@ -59,17 +56,14 @@ class graphRow { // Private data - //- reference to the graph + //- Reference to the graph graphType& data_; - //- row number + //- Row number const label rowI_; - - // Private member functions - - //- check index - inline void checkIndex(const label i) const; + // Allow copy construct from non-const to const version + friend class graphConstRow; public: @@ -80,7 +74,7 @@ public: inline graphRow(graphType& g, const label i); //- Copy contructor - inline graphRow(const graphRow&); + inline graphRow(const graphRow& r); //- Destructor @@ -89,7 +83,7 @@ public: // Member Functions - //- Returns the number of elements in the row + //- Return the number of elements in the row inline label size() const; //- Reset the number of elements in the row @@ -116,20 +110,21 @@ public: inline label operator[](const label) const; inline label& operator[](const label); - //- Assignment operator - inline void operator=(const graphRow&); + //- Copy contents from another row + inline void operator=(const graphRow& rhs); - template - inline void operator=(const listType&); + //- Copy contents from a list + template + inline void operator=(const ListType& rhs); // IOstream operators - // Write graphRow to Ostream. + //- Write graphRow contents to Ostream. friend Ostream& operator<< ( - Ostream&, - const graphRow& + Ostream& os, + const graphRow& r ); }; diff --git a/meshLibrary/utilities/containers/graphRow/graphRowI.H b/meshLibrary/utilities/containers/graphRow/graphRowI.H index 3a464c6a705da19cf1239c7ef6453d8b1cc04878..422e267580203ae34939d95ee25bf227614036ac 100644 --- a/meshLibrary/utilities/containers/graphRow/graphRowI.H +++ b/meshLibrary/utilities/containers/graphRow/graphRowI.H @@ -23,21 +23,7 @@ License \*---------------------------------------------------------------------------*/ -namespace Foam -{ - -template -inline void Foam::graphRow::checkIndex(const label i) const -{ - if ((i < 0) || (i >=data_.sizeOfRow(rowI_))) - { - FatalErrorInFunction - << "Row index " << rowI_ - << " is not in range " << Foam::label(0) - << " and " << data_.sizeOfRow(rowI_) << abort(FatalError); - } -} - +#include "Ostream.H" // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // @@ -52,11 +38,11 @@ inline Foam::graphRow::graphRow(graphType& g, const label i) template inline Foam::graphRow::graphRow ( - const graphRow& ol + const graphRow& r ) : - data_(ol.data_), - rowI_(ol.rowI_) + data_(r.data_), + rowI_(r.rowI_) {} @@ -140,49 +126,52 @@ inline Foam::label& Foam::graphRow::operator[](const label i) template inline void Foam::graphRow::operator= ( - const graphRow& l + const graphRow& rhs ) { - data_.setRowSize(rowI_, l.size()); - for (label i = 0; i < l.size(); ++i) + const label len = rhs.size(); + + data_.setRowSize(rowI_, len); + for (label i = 0; i < len; ++i) { - data_(rowI_, i) = l[i]; + data_(rowI_, i) = rhs[i]; } } template -template -inline void Foam::graphRow::operator=(const listType& l) +template +inline void Foam::graphRow::operator=(const ListType& rhs) { - data_.setRowSize(rowI_, l.size()); - for (label i = 0; i < l.size(); ++i) + const label len = rhs.size(); + + data_.setRowSize(rowI_, len); + for (label i = 0; i < len; ++i) { - data_(rowI_, i) = l[i]; + data_(rowI_, i) = rhs[i]; } } template -inline Foam::Ostream& operator<< +inline Foam::Ostream& Foam::operator<< ( - Foam::Ostream& os, + Ostream& os, const Foam::graphRow& r ) { - os << r.size() << "("; - for (Foam::label i = 0; i < r.size(); ++i) + const label len = r.size(); + + os << len << '('; + for (label i = 0; i < len; ++i) { - os << r[i] << " "; + if (i) os << ' '; + os << r[i]; } - os << ")"; + os << ')'; return os; } -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam - // ************************************************************************* // diff --git a/meshLibrary/utilities/containers/subGraph/subGraph.H b/meshLibrary/utilities/containers/subGraph/subGraph.H index 09029e8895bd786a99144b4b808d989567523d49..eff4d30372a2b972760a7ee3f042ec6fdaff4c75 100644 --- a/meshLibrary/utilities/containers/subGraph/subGraph.H +++ b/meshLibrary/utilities/containers/subGraph/subGraph.H @@ -39,6 +39,7 @@ SourceFiles #include "Ostream.H" #include "error.H" #include "graphRow.H" +#include "graphConstRow.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -116,7 +117,7 @@ public: //- set and get operators inline label operator()(const label i, const label j) const; inline label& operator()(const label i, const label j); - inline const graphRow operator[](const label) const; + inline const graphConstRow operator[](const label) const; inline graphRow operator[](const label); diff --git a/meshLibrary/utilities/containers/subGraph/subGraphI.H b/meshLibrary/utilities/containers/subGraph/subGraphI.H index b9e598b2f90ea2df050fdd542abb955af20dca14..1453cb2597963ea3c73ea204d73eb5a597e40b18 100644 --- a/meshLibrary/utilities/containers/subGraph/subGraphI.H +++ b/meshLibrary/utilities/containers/subGraph/subGraphI.H @@ -163,7 +163,7 @@ inline Foam::label& Foam::subGraph::operator() template -inline const Foam::graphRow +inline const Foam::graphConstRow Foam::subGraph::operator[] ( const label i