CompactIOList: Derived from ListCompactIO to reuse the steam IO
This commit is contained in:
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration | Website: https://openfoam.org
|
\\ / O peration | Website: https://openfoam.org
|
||||||
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -24,7 +24,7 @@ License
|
|||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include "CompactIOList.H"
|
#include "CompactIOList.H"
|
||||||
#include "labelList.H"
|
#include "IOList.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||||
|
|
||||||
@ -35,7 +35,7 @@ void Foam::CompactIOList<T, BaseType>::readFromStream()
|
|||||||
|
|
||||||
if (headerClassName() == IOList<T>::typeName)
|
if (headerClassName() == IOList<T>::typeName)
|
||||||
{
|
{
|
||||||
is >> static_cast<List<T>&>(*this);
|
is >> static_cast<ListCompactIO<T, BaseType>&>(*this);
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
else if (headerClassName() == typeName)
|
else if (headerClassName() == typeName)
|
||||||
@ -57,23 +57,6 @@ void Foam::CompactIOList<T, BaseType>::readFromStream()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class T, class BaseType>
|
|
||||||
bool Foam::CompactIOList<T, BaseType>::overflows() const
|
|
||||||
{
|
|
||||||
label size = 0;
|
|
||||||
forAll(*this, i)
|
|
||||||
{
|
|
||||||
label oldSize = size;
|
|
||||||
size += this->operator[](i).size();
|
|
||||||
if (size < oldSize)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
template<class T, class BaseType>
|
template<class T, class BaseType>
|
||||||
@ -111,7 +94,7 @@ Foam::CompactIOList<T, BaseType>::CompactIOList
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
List<T>::setSize(size);
|
this->setSize(size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,7 +118,7 @@ Foam::CompactIOList<T, BaseType>::CompactIOList
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
List<T>::operator=(list);
|
ListCompactIO<T, BaseType>::operator=(list);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,7 +132,7 @@ Foam::CompactIOList<T, BaseType>::CompactIOList
|
|||||||
:
|
:
|
||||||
regIOobject(io)
|
regIOobject(io)
|
||||||
{
|
{
|
||||||
List<T>::transfer(list());
|
this->transfer(list());
|
||||||
|
|
||||||
if
|
if
|
||||||
(
|
(
|
||||||
@ -195,7 +178,7 @@ bool Foam::CompactIOList<T, BaseType>::writeObject
|
|||||||
|
|
||||||
return good;
|
return good;
|
||||||
}
|
}
|
||||||
else if (overflows())
|
else if (this->overflows())
|
||||||
{
|
{
|
||||||
WarningInFunction
|
WarningInFunction
|
||||||
<< "Overall number of elements of CompactIOList of size "
|
<< "Overall number of elements of CompactIOList of size "
|
||||||
@ -236,100 +219,7 @@ void Foam::CompactIOList<T, BaseType>::operator=
|
|||||||
const CompactIOList<T, BaseType>& rhs
|
const CompactIOList<T, BaseType>& rhs
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
List<T>::operator=(rhs);
|
ListCompactIO<T, BaseType>::operator=(rhs);
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<class T, class BaseType>
|
|
||||||
void Foam::CompactIOList<T, BaseType>::operator=(const List<T>& rhs)
|
|
||||||
{
|
|
||||||
List<T>::operator=(rhs);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
template<class T, class BaseType>
|
|
||||||
Foam::Istream& Foam::operator>>
|
|
||||||
(
|
|
||||||
Foam::Istream& is,
|
|
||||||
Foam::CompactIOList<T, BaseType>& L
|
|
||||||
)
|
|
||||||
{
|
|
||||||
// Read compact
|
|
||||||
const labelList start(is);
|
|
||||||
const List<BaseType> elems(is);
|
|
||||||
|
|
||||||
// Convert
|
|
||||||
L.setSize(start.size()-1);
|
|
||||||
|
|
||||||
forAll(L, i)
|
|
||||||
{
|
|
||||||
T& subList = L[i];
|
|
||||||
|
|
||||||
label index = start[i];
|
|
||||||
subList.setSize(start[i+1] - index);
|
|
||||||
|
|
||||||
forAll(subList, j)
|
|
||||||
{
|
|
||||||
subList[j] = elems[index++];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return is;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<class T, class BaseType>
|
|
||||||
Foam::Ostream& Foam::operator<<
|
|
||||||
(
|
|
||||||
Foam::Ostream& os,
|
|
||||||
const Foam::CompactIOList<T, BaseType>& L
|
|
||||||
)
|
|
||||||
{
|
|
||||||
// Keep ascii writing same.
|
|
||||||
if (os.format() == IOstream::ASCII)
|
|
||||||
{
|
|
||||||
os << static_cast<const List<T>&>(L);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Convert to compact format
|
|
||||||
labelList start(L.size()+1);
|
|
||||||
|
|
||||||
start[0] = 0;
|
|
||||||
for (label i = 1; i < start.size(); i++)
|
|
||||||
{
|
|
||||||
label prev = start[i-1];
|
|
||||||
start[i] = prev+L[i-1].size();
|
|
||||||
|
|
||||||
if (start[i] < prev)
|
|
||||||
{
|
|
||||||
FatalIOErrorInFunction(os)
|
|
||||||
<< "Overall number of elements " << start[i]
|
|
||||||
<< " of CompactIOList of size "
|
|
||||||
<< L.size() << " overflows the representation of a label"
|
|
||||||
<< endl << "Please recompile with a larger representation"
|
|
||||||
<< " for label" << exit(FatalIOError);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
List<BaseType> elems(start[start.size()-1]);
|
|
||||||
|
|
||||||
label elemI = 0;
|
|
||||||
forAll(L, i)
|
|
||||||
{
|
|
||||||
const T& subList = L[i];
|
|
||||||
|
|
||||||
forAll(subList, j)
|
|
||||||
{
|
|
||||||
elems[elemI++] = subList[j];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
os << start << elems;
|
|
||||||
}
|
|
||||||
|
|
||||||
return os;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration | Website: https://openfoam.org
|
\\ / O peration | Website: https://openfoam.org
|
||||||
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -39,7 +39,7 @@ SourceFiles
|
|||||||
#ifndef CompactIOList_H
|
#ifndef CompactIOList_H
|
||||||
#define CompactIOList_H
|
#define CompactIOList_H
|
||||||
|
|
||||||
#include "IOList.H"
|
#include "ListCompactIO.H"
|
||||||
#include "regIOobject.H"
|
#include "regIOobject.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
@ -47,23 +47,6 @@ SourceFiles
|
|||||||
namespace Foam
|
namespace Foam
|
||||||
{
|
{
|
||||||
|
|
||||||
class Istream;
|
|
||||||
class Ostream;
|
|
||||||
|
|
||||||
// Forward declaration of friend functions and operators
|
|
||||||
template<class T, class BaseType> class CompactIOList;
|
|
||||||
|
|
||||||
template<class T, class BaseType> Istream& operator>>
|
|
||||||
(
|
|
||||||
Istream&,
|
|
||||||
CompactIOList<T, BaseType>&
|
|
||||||
);
|
|
||||||
template<class T, class BaseType> Ostream& operator<<
|
|
||||||
(
|
|
||||||
Ostream&,
|
|
||||||
const CompactIOList<T, BaseType>&
|
|
||||||
);
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*\
|
/*---------------------------------------------------------------------------*\
|
||||||
Class CompactIOList Declaration
|
Class CompactIOList Declaration
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
@ -72,16 +55,13 @@ template<class T, class BaseType>
|
|||||||
class CompactIOList
|
class CompactIOList
|
||||||
:
|
:
|
||||||
public regIOobject,
|
public regIOobject,
|
||||||
public List<T>
|
public ListCompactIO<T, BaseType>
|
||||||
{
|
{
|
||||||
// Private Member Functions
|
// Private Member Functions
|
||||||
|
|
||||||
//- Read according to header type
|
//- Read according to header type
|
||||||
void readFromStream();
|
void readFromStream();
|
||||||
|
|
||||||
//- Has too many elements in it?
|
|
||||||
bool overflows() const;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
//- Runtime type information
|
//- Runtime type information
|
||||||
@ -124,25 +104,6 @@ public:
|
|||||||
// Member operators
|
// Member operators
|
||||||
|
|
||||||
void operator=(const CompactIOList<T, BaseType>&);
|
void operator=(const CompactIOList<T, BaseType>&);
|
||||||
|
|
||||||
void operator=(const List<T>&);
|
|
||||||
|
|
||||||
|
|
||||||
// IOstream operators
|
|
||||||
|
|
||||||
//- Read List from Istream, discarding contents of existing List.
|
|
||||||
friend Istream& operator>> <T, BaseType>
|
|
||||||
(
|
|
||||||
Istream&,
|
|
||||||
CompactIOList<T, BaseType>&
|
|
||||||
);
|
|
||||||
|
|
||||||
// Write List to Ostream.
|
|
||||||
friend Ostream& operator<< <T, BaseType>
|
|
||||||
(
|
|
||||||
Ostream&,
|
|
||||||
const CompactIOList<T, BaseType>&
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration | Website: https://openfoam.org
|
\\ / O peration | Website: https://openfoam.org
|
||||||
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -33,6 +33,7 @@ Description
|
|||||||
#define faceIOList_H
|
#define faceIOList_H
|
||||||
|
|
||||||
#include "face.H"
|
#include "face.H"
|
||||||
|
#include "IOList.H"
|
||||||
#include "CompactIOList.H"
|
#include "CompactIOList.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|||||||
Reference in New Issue
Block a user