Commit f7682ade authored by franjo_j@hotmail.com's avatar franjo_j@hotmail.com
Browse files

Bug fix in the read operator for the LongList. It did not read () in

case of zero length list.


git-svn-id: https://pl5.projectlocker.com/igui/meshGeneration/svn@20 fdcce57e-7e00-11e2-b579-49867b4cea03
parent 901d2e23
......@@ -31,7 +31,7 @@ License
#include "Time.H"
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
template<class T, Foam::label Offset>
void Foam::LongList<T, Offset>::writeEntry(Ostream& os) const
{
......@@ -46,7 +46,7 @@ void Foam::LongList<T, Offset>::writeEntry(Ostream& os) const
{
os << word("LongList<" + word(pTraits<T>::typeName) + '>') << " ";
}
os << *this;
}
......@@ -75,14 +75,14 @@ Foam::Ostream& Foam::operator<<
{
// Write size of list and start contents delimiter
os << DL.size() << token::BEGIN_LIST;
// Write list contents
forAll(DL, i)
{
if( i != 0 ) os << token::SPACE;
os << DL[i];
}
// Write end of contents delimiter
os << token::END_LIST;
}
......@@ -90,13 +90,13 @@ Foam::Ostream& Foam::operator<<
{
// Write size of list and start contents delimiter
os << nl << DL.size() << nl << token::BEGIN_LIST;
// Write list contents
forAll(DL, i)
{
os << nl << DL[i];
}
// Write end of contents delimiter
os << nl << token::END_LIST << nl;
}
......@@ -110,26 +110,26 @@ Foam::Ostream& Foam::operator<<
label currBlock(0);
label currPos(0);
while( currPos < DL.nextFree_ )
{
const label bs = Foam::min(DL.nextFree_ - currPos, blockSize);
os.write
(
reinterpret_cast<const char*>(DL.dataPtr_[currBlock]),
bs * sizeof(T)
);
currPos += bs;
++currBlock;
}
}
}
// Check state of IOstream
os.check("Ostream& operator<<(Ostream&, const LongList&)");
return os;
}
......@@ -159,9 +159,43 @@ Foam::Istream& Foam::operator>>
// Set list length to that read
DL.setSize(size);
if( size == 0 )
{
char listDelimiter = is.readBeginList("List");
if( listDelimiter != token::BEGIN_LIST )
{
WarningIn
(
"template<class T, Foam::label Offset>"
"Foam::Istream& Foam::operator>>"
"("
"Foam::Istream& ,"
"Foam::LongList<T, Offset>& DL"
")"
) << "Missing ( after 0" << endl;
return is;
}
listDelimiter = is.readEndList("List");
if( listDelimiter != token::END_LIST )
{
WarningIn
(
"template<class T, Foam::label Offset>"
"Foam::Istream& Foam::operator>>"
"("
"Foam::Istream& ,"
"Foam::LongList<T, Offset>& DL"
")"
) << "Missing ) after 0(" << endl;
}
return is;
}
// Read list contents depending on data format
if( (is.format() == IOstream::ASCII) || !contiguous<T>() )
......@@ -197,27 +231,27 @@ Foam::Istream& Foam::operator>>
DL[i] = element;
}
}
// Read end of contents
is.readEndList("List");
}
else
{
const label blockSize = (1<<DL.shift_);
label currBlock(0);
label currPos(0);
while( currPos < size )
{
const label bs = Foam::min(size - currPos, blockSize);
is.read
(
reinterpret_cast<char*>(DL.dataPtr_[currBlock]),
bs * sizeof(T)
);
currPos += bs;
++currBlock;
}
......@@ -255,13 +289,13 @@ void Foam::LongList<T, Offset>::appendFromStream(Istream& is)
if( firstToken.isLabel() )
{
const label size = firstToken.labelToken();
if( size == 0 )
{
Pout << "Appending empty stream" << endl;
return;
}
label origSize(this->size());
// Set list length to that read
......@@ -303,7 +337,7 @@ void Foam::LongList<T, Offset>::appendFromStream(Istream& is)
++origSize;
}
}
// Read end of contents
is.readEndList("List");
}
......@@ -311,31 +345,31 @@ void Foam::LongList<T, Offset>::appendFromStream(Istream& is)
{
List<T> buf(size);
is.read(reinterpret_cast<char*>(buf.begin()), size * sizeof(T));
forAll(buf, i)
this->operator[](origSize++) = buf[i];
/*const label blockSize = 1<<shift_;
Info << "nextFree_ " << nextFree_ << endl;
//- append elements by reading binary block
while( origSize < nextFree_ )
{
const label currBlock = origSize >> shift_;
const label currPos = origSize & mask_;
Info << "Orig size " << origSize
<< nl << "currBlock " << currBlock
<< nl << "currPos " << currPos << endl;
T* data = &dataPtr_[currBlock][currPos];
label bs = Foam::min(nextFree_-origSize, blockSize);
bs = Foam::min(blockSize - currPos, bs);
Info << "bs " << bs << endl;
is.read(reinterpret_cast<char*>(data), bs * sizeof(T));
origSize += bs;
} */
......
Markdown is supported
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