Commit 2f091ae6 authored by Mark Olesen's avatar Mark Olesen
Browse files

STYLE: make UList::writeEntry(Ostream&) protected

- outputs compound tags etc.
  Should only be called by itself or by a derived class.
parent 0067c9e3
......@@ -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
......
......@@ -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)
{
......
......@@ -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
(
......
......@@ -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
......
......@@ -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);
......
......@@ -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
......
......@@ -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)
{
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment