diff --git a/src/OpenFOAM/containers/Lists/FixedList/FixedList.H b/src/OpenFOAM/containers/Lists/FixedList/FixedList.H index f59582971eea20f3137bb00db2b9d77ef51f3604..375151c4635066b9c6f3da4917ef1356ca76157f 100644 --- a/src/OpenFOAM/containers/Lists/FixedList/FixedList.H +++ b/src/OpenFOAM/containers/Lists/FixedList/FixedList.H @@ -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. @@ -86,6 +86,14 @@ class FixedList T v_[Size]; +protected: + + // Protected Member Functions + + //- Write the FixedList with its compound type + void writeEntry(Ostream& os) const; + + public: //- Hashing function class. @@ -207,12 +215,6 @@ public: // needed to make FixedList consistent with List void transfer(const FixedList<T, Size>&); - //- Write the FixedList as a dictionary entry - void writeEntry(Ostream&) const; - - //- Write the FixedList as a dictionary entry with keyword - void writeEntry(const word& keyword, Ostream&) const; - // Member operators @@ -357,6 +359,12 @@ public: bool operator>=(const FixedList<T, Size>&) const; + // Writing + + //- Write the List as a dictionary entry with keyword + void writeEntry(const word& keyword, Ostream& os) const; + + // IOstream operators //- Read List from Istream, discarding contents of existing List diff --git a/src/OpenFOAM/containers/Lists/FixedList/FixedListIO.C b/src/OpenFOAM/containers/Lists/FixedList/FixedListIO.C index e6ba7a46787dac58c13666061b150ce0a6896e80..6e300a7da30f1387a5b39d13f59d805afe14bf33 100644 --- a/src/OpenFOAM/containers/Lists/FixedList/FixedListIO.C +++ b/src/OpenFOAM/containers/Lists/FixedList/FixedListIO.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. @@ -29,6 +29,37 @@ License #include "token.H" #include "contiguous.H" + +// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // + +template<class T, unsigned Size> +void Foam::FixedList<T, Size>::writeEntry(Ostream& os) const +{ + const word tag = "List<" + word(pTraits<T>::typeName) + '>'; + if (token::compound::isCompound(tag)) + { + os << tag << ' '; + } + + os << *this; +} + + +// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // + +template<class T, unsigned Size> +void Foam::FixedList<T, Size>::writeEntry +( + const word& keyword, + Ostream& os +) const +{ + os.writeKeyword(keyword); + writeEntry(os); + os << token::END_STATEMENT << endl; +} + + // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * // template<class T, unsigned Size> @@ -85,7 +116,7 @@ Foam::Istream& Foam::operator>>(Foam::Istream& is, FixedList<T, Size>& L) if (delimiter == token::BEGIN_LIST) { - for (unsigned i=0; i<Size; i++) + for (unsigned i=0; i<Size; ++i) { is >> L[i]; @@ -107,7 +138,7 @@ Foam::Istream& Foam::operator>>(Foam::Istream& is, FixedList<T, Size>& L) "reading the single entry" ); - for (unsigned i=0; i<Size; i++) + for (unsigned i=0; i<Size; ++i) { L[i] = element; } @@ -135,32 +166,6 @@ Foam::Istream& Foam::operator>>(Foam::Istream& is, FixedList<T, Size>& L) // * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * // -template<class T, unsigned Size> -void Foam::FixedList<T, Size>::writeEntry(Ostream& os) const -{ - const word tag = "List<" + word(pTraits<T>::typeName) + '>'; - if (token::compound::isCompound(tag)) - { - os << tag << " "; - } - - os << *this; -} - - -template<class T, unsigned Size> -void Foam::FixedList<T, Size>::writeEntry -( - const word& keyword, - Ostream& os -) const -{ - os.writeKeyword(keyword); - writeEntry(os); - os << token::END_STATEMENT << endl; -} - - template<class T, unsigned Size> Foam::Ostream& Foam::operator<<(Ostream& os, const FixedList<T, Size>& L) { diff --git a/src/OpenFOAM/containers/Lists/PackedList/PackedList.C b/src/OpenFOAM/containers/Lists/PackedList/PackedList.C index 6addd5d23ebaa6c1177f3cf75031780d2c783478..095453d9c93b3226bb8123a33e3db40d0c1410c8 100644 --- a/src/OpenFOAM/containers/Lists/PackedList/PackedList.C +++ b/src/OpenFOAM/containers/Lists/PackedList/PackedList.C @@ -26,27 +26,35 @@ License #include "PackedList.H" #include "IOstreams.H" +// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // + +template<unsigned nBits> +void Foam::PackedList<nBits>::writeEntry(Ostream& os) const +{ + os << *this; +} + // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // #if (UINT_MAX == 0xFFFFFFFF) -// 32-bit counting, Hamming weight method - #define COUNT_PACKEDBITS(sum, x) \ + // 32-bit counting, Hamming weight method + #define COUNT_PACKEDBITS(sum, x) \ { \ x -= (x >> 1) & 0x55555555; \ x = (x & 0x33333333) + ((x >> 2) & 0x33333333); \ sum += (((x + (x >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24; \ } #elif (UINT_MAX == 0xFFFFFFFFFFFFFFFF) -// 64-bit counting, Hamming weight method - #define COUNT_PACKEDBITS(sum, x) \ + // 64-bit counting, Hamming weight method + #define COUNT_PACKEDBITS(sum, x) \ { \ x -= (x >> 1) & 0x5555555555555555; \ x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333); \ - sum += (((x + (x >> 4)) & 0x0F0F0F0F0F0F0F0F) * 0x0101010101010101) >> 56;\ + sum += (((x + (x >> 4)) & 0x0F0F0F0F0F0F0F0F) * 0x0101010101010101) >> 56; \ } #else -// Arbitrary number of bits, Brian Kernighan's method + // Arbitrary number of bits, Brian Kernighan's method #define COUNT_PACKEDBITS(sum, x) for (; x; ++sum) { x &= x - 1; } #endif @@ -69,6 +77,8 @@ unsigned int Foam::PackedList<nBits>::count() const return c; } +#undef COUNT_PACKEDBITS + template<unsigned nBits> bool Foam::PackedList<nBits>::trim() @@ -491,13 +501,6 @@ Foam::Ostream& Foam::PackedList<nBits>::write } -template<unsigned nBits> -void Foam::PackedList<nBits>::writeEntry(Ostream& os) const -{ - os << *this; -} - - template<unsigned nBits> void Foam::PackedList<nBits>::writeEntry ( diff --git a/src/OpenFOAM/containers/Lists/PackedList/PackedList.H b/src/OpenFOAM/containers/Lists/PackedList/PackedList.H index 43bc8a5cdac5375453bc186c7b3d0694acb549fc..1d04851e4c74400fad9b6aff136bfb5f4ef55ed3 100644 --- a/src/OpenFOAM/containers/Lists/PackedList/PackedList.H +++ b/src/OpenFOAM/containers/Lists/PackedList/PackedList.H @@ -186,6 +186,14 @@ private: label size_; +protected: + + // Protected Member Functions + + //- Write as a dictionary entry + void writeEntry(Ostream& os) const; + + public: // Public data @@ -322,10 +330,10 @@ public: //- Reset addressable list size, does not shrink the allocated size. // Optionally specify a value for new elements. - inline void resize(const label, const unsigned int& val = 0u); + inline void resize(const label, const unsigned int val = 0u); //- Alias for resize() - inline void setSize(const label, const unsigned int& val = 0u); + inline void setSize(const label, const unsigned int val = 0u); //- Reserve allocation space for at least this size. // Never shrinks the allocated size. @@ -354,7 +362,7 @@ public: // IO //- Clear list and read from stream - Istream& read(Istream&); + Istream& read(Istream& is); //- Write, optionally with indexedOutput // @@ -372,16 +380,13 @@ public: // Note the indexed output is only supported for ASCII streams. Ostream& write ( - Ostream&, + Ostream& os, const bool indexedOutput=false ) const; - //- Write as a dictionary entry - void writeEntry(Ostream&) const; - //- Write as a dictionary entry with keyword - void writeEntry(const word& keyword, Ostream&) const; + void writeEntry(const word& keyword, Ostream& os) const; // Member operators diff --git a/src/OpenFOAM/containers/Lists/PackedList/PackedListI.H b/src/OpenFOAM/containers/Lists/PackedList/PackedListI.H index c945ca0ba35acaa70acff8ea408a7c75f112f37e..2397a45768e2614282f7d3cf822b3b88db1b9341 100644 --- a/src/OpenFOAM/containers/Lists/PackedList/PackedListI.H +++ b/src/OpenFOAM/containers/Lists/PackedList/PackedListI.H @@ -727,7 +727,7 @@ template<unsigned nBits> inline void Foam::PackedList<nBits>::resize ( const label newSize, - const unsigned int& val + const unsigned int val ) { reserve(newSize); @@ -821,7 +821,7 @@ template<unsigned nBits> inline void Foam::PackedList<nBits>::setSize ( const label newSize, - const unsigned int& val + const unsigned int val ) { resize(newSize, val); diff --git a/src/OpenFOAM/containers/Lists/UList/UList.H b/src/OpenFOAM/containers/Lists/UList/UList.H index a31416cc7374a5f520a486c099b003c163ea49a6..fa3f7b5c19bb0e56c2b62ac9823ab6b506067c00 100644 --- a/src/OpenFOAM/containers/Lists/UList/UList.H +++ b/src/OpenFOAM/containers/Lists/UList/UList.H @@ -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. @@ -93,6 +93,14 @@ class UList void operator=(const UList<T>&) = delete; +protected: + + // Protected Member Functions + + //- Write the UList with its compound type + void writeEntry(Ostream& os) const; + + public: // Related types @@ -219,12 +227,6 @@ public: //- Copy elements of the given UList void deepCopy(const UList<T>&); - //- Write the UList with its compound type - void writeEntry(Ostream&) const; - - //- Write the UList as a dictionary entry with keyword - void writeEntry(const word& keyword, Ostream&) const; - // Member operators @@ -365,6 +367,12 @@ public: bool operator>=(const UList<T>&) const; + // Writing + + //- Write the List as a dictionary entry with keyword + void writeEntry(const word& keyword, Ostream& os) const; + + // Ostream operator // Write UList to Ostream diff --git a/src/OpenFOAM/containers/Lists/UList/UListIO.C b/src/OpenFOAM/containers/Lists/UList/UListIO.C index 0559a63adce6ca8d37518d09bf3359efa785881c..d55860f2eaa76f5b0463ca8d01c70d904157cd4d 100644 --- a/src/OpenFOAM/containers/Lists/UList/UListIO.C +++ b/src/OpenFOAM/containers/Lists/UList/UListIO.C @@ -29,7 +29,7 @@ License #include "SLList.H" #include "contiguous.H" -// * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * // +// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // template<class T> void Foam::UList<T>::writeEntry(Ostream& os) const @@ -56,6 +56,8 @@ void Foam::UList<T>::writeEntry(Ostream& os) const } +// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // + template<class T> void Foam::UList<T>::writeEntry(const word& keyword, Ostream& os) const { @@ -65,6 +67,8 @@ void Foam::UList<T>::writeEntry(const word& keyword, Ostream& os) const } +// * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * // + template<class T> Foam::Ostream& Foam::operator<<(Foam::Ostream& os, const Foam::UList<T>& L) {