mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
UIndirectList output operator
- TODO: binary output is still a bit silly
This commit is contained in:
@ -28,6 +28,8 @@ Description
|
|||||||
|
|
||||||
#include "UIndirectList.H"
|
#include "UIndirectList.H"
|
||||||
#include "IOstreams.H"
|
#include "IOstreams.H"
|
||||||
|
#include "ListOps.H"
|
||||||
|
#include "OFstream.H"
|
||||||
|
|
||||||
using namespace Foam;
|
using namespace Foam;
|
||||||
|
|
||||||
@ -52,29 +54,32 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
UIndirectList<double> idl(completeList, addresses);
|
UIndirectList<double> idl(completeList, addresses);
|
||||||
|
|
||||||
forAll(idl, i)
|
Info<< idl << "\n";
|
||||||
{
|
|
||||||
Info<< idl[i] << token::SPACE;
|
|
||||||
}
|
|
||||||
|
|
||||||
Info<< endl;
|
|
||||||
|
|
||||||
idl[1] = -666;
|
idl[1] = -666;
|
||||||
|
|
||||||
Info<< "idl[1] changed:" << idl() << endl;
|
Info<< "idl[1] changed:" << idl << endl;
|
||||||
|
|
||||||
idl = -999;
|
idl = -999;
|
||||||
|
|
||||||
Info<< "idl changed:" << idl() << endl;
|
Info<< "idl changed:" << idl << endl;
|
||||||
|
|
||||||
UIndirectList<double> idl2(idl);
|
UIndirectList<double> idl2(idl);
|
||||||
|
|
||||||
Info<< "idl2:" << idl2() << endl;
|
Info<< "idl2: " << idl2 << endl;
|
||||||
|
|
||||||
idl = idl2();
|
|
||||||
|
|
||||||
Info<< "idl assigned from UList:" << idl() << endl;
|
{
|
||||||
|
List<double> ident(idl.size());
|
||||||
|
|
||||||
|
forAll(ident, i)
|
||||||
|
{
|
||||||
|
ident[i] = ident.size() - i;
|
||||||
|
}
|
||||||
|
idl = ident;
|
||||||
|
}
|
||||||
|
|
||||||
|
Info<< "idl assigned from UList:" << idl << endl;
|
||||||
|
|
||||||
List<double> realList = UIndirectList<double>(completeList, addresses);
|
List<double> realList = UIndirectList<double>(completeList, addresses);
|
||||||
|
|
||||||
|
|||||||
@ -26,8 +26,8 @@ Class
|
|||||||
Foam::UIndirectList
|
Foam::UIndirectList
|
||||||
|
|
||||||
Description
|
Description
|
||||||
A List with indirect addressing. Like IndirectList but does not store
|
A List with indirect addressing.
|
||||||
addressing.
|
Like IndirectList but does not store addressing.
|
||||||
|
|
||||||
SourceFiles
|
SourceFiles
|
||||||
UIndirectListI.H
|
UIndirectListI.H
|
||||||
@ -44,8 +44,12 @@ SourceFiles
|
|||||||
namespace Foam
|
namespace Foam
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// Forward declaration of friend functions and operators
|
||||||
|
template<class T> class UIndirectList;
|
||||||
|
template<class T> Ostream& operator<<(Ostream&, const UIndirectList<T>&);
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*\
|
/*---------------------------------------------------------------------------*\
|
||||||
Class UIndirectList Declaration
|
Class UIndirectList Declaration
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
@ -92,6 +96,17 @@ public:
|
|||||||
|
|
||||||
//- Assignment of all entries to the given value
|
//- Assignment of all entries to the given value
|
||||||
inline void operator=(const T&);
|
inline void operator=(const T&);
|
||||||
|
|
||||||
|
// Ostream operator
|
||||||
|
|
||||||
|
//- Write UIndirectList to Ostream
|
||||||
|
// Binary output is currently still a bit of a problem
|
||||||
|
friend Ostream& operator<<
|
||||||
|
#ifndef __CINT__
|
||||||
|
<T>
|
||||||
|
#endif
|
||||||
|
(Ostream&, const UIndirectList<T>&);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -103,6 +118,10 @@ public:
|
|||||||
|
|
||||||
#include "UIndirectListI.H"
|
#include "UIndirectListI.H"
|
||||||
|
|
||||||
|
#ifdef NoRepository
|
||||||
|
# include "UIndirectListIO.C"
|
||||||
|
#endif
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
126
src/OpenFOAM/containers/Lists/UIndirectList/UIndirectListIO.C
Normal file
126
src/OpenFOAM/containers/Lists/UIndirectList/UIndirectListIO.C
Normal file
@ -0,0 +1,126 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
|
||||||
|
\\/ M anipulation |
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
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 2 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, write to the Free Software Foundation,
|
||||||
|
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#include "UIndirectList.H"
|
||||||
|
#include "Ostream.H"
|
||||||
|
#include "token.H"
|
||||||
|
#include "contiguous.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
Foam::Ostream& Foam::operator<<
|
||||||
|
(
|
||||||
|
Foam::Ostream& os,
|
||||||
|
const Foam::UIndirectList<T>& L
|
||||||
|
)
|
||||||
|
{
|
||||||
|
// Write list contents depending on data format
|
||||||
|
if (os.format() == IOstream::ASCII || !contiguous<T>())
|
||||||
|
{
|
||||||
|
bool uniform = false;
|
||||||
|
|
||||||
|
if (L.size() > 1 && contiguous<T>())
|
||||||
|
{
|
||||||
|
uniform = true;
|
||||||
|
|
||||||
|
forAll(L, i)
|
||||||
|
{
|
||||||
|
if (L[i] != L[0])
|
||||||
|
{
|
||||||
|
uniform = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (uniform)
|
||||||
|
{
|
||||||
|
// Write size and start delimiter
|
||||||
|
os << L.size() << token::BEGIN_BLOCK;
|
||||||
|
|
||||||
|
// Write contents
|
||||||
|
os << L[0];
|
||||||
|
|
||||||
|
// Write end delimiter
|
||||||
|
os << token::END_BLOCK;
|
||||||
|
}
|
||||||
|
else if (L.size() < 11 && contiguous<T>())
|
||||||
|
{
|
||||||
|
// Write size and start delimiter
|
||||||
|
os << L.size() << token::BEGIN_LIST;
|
||||||
|
|
||||||
|
// Write contents
|
||||||
|
forAll(L, i)
|
||||||
|
{
|
||||||
|
if (i) os << token::SPACE;
|
||||||
|
os << L[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write end delimiter
|
||||||
|
os << token::END_LIST;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Write size and start delimiter
|
||||||
|
os << nl << L.size() << nl << token::BEGIN_LIST;
|
||||||
|
|
||||||
|
// Write contents
|
||||||
|
forAll(L, i)
|
||||||
|
{
|
||||||
|
os << nl << L[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write end delimiter
|
||||||
|
os << nl << token::END_LIST << nl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// this is annoying, and wasteful, but there's currently no alternative
|
||||||
|
|
||||||
|
os << nl << L.size() << nl;
|
||||||
|
|
||||||
|
if (L.size())
|
||||||
|
{
|
||||||
|
List<T> lst = L();
|
||||||
|
|
||||||
|
os.write
|
||||||
|
(
|
||||||
|
reinterpret_cast<const char*>(lst.cdata()),
|
||||||
|
lst.byteSize()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check state of IOstream
|
||||||
|
os.check("Ostream& operator<<(Ostream&, const UIndirectList&)");
|
||||||
|
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
Reference in New Issue
Block a user