Commit f78aa8e3 authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: added Ostream fill() methods and corresponding IOmanip setfill()

- useful when generating formatted output such as tables.
parent d8a55e46
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -22,9 +22,10 @@ License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Application
test
Test-io
Description
Test basic stream functionality
\*---------------------------------------------------------------------------*/
......@@ -51,7 +52,25 @@ int main(void)
Info<< hex << 255 << endl;
Info<< nl << "Formatted fields" << nl;
const char oldfill = static_cast<OSstream&>(Info).fill();
Info<< setfill('-');
Info<< "|" << setf(ios_base::left) << setw(32) << " foo " << "|" << nl;
Info<< "|" << setf(ios_base::left) << setw(10) << " bar " << "|" << nl;
Info<< "|" << setf(ios_base::left) << setw(10) << "" << "|" << nl;
Info<< "resetting fill from (0x" << hex << int(oldfill) << ")" << nl;
Info<< setfill(oldfill);
Info<< "|" << setf(ios_base::left) << setw(10) << " bar " << "|" << nl;
Info<< nl << nl;
Info.operator Foam::OSstream&() << "stop" << endl;
static_cast<OSstream&>(Info) << "\nEnd\n" << nl;
}
// ************************************************************************* //
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -40,7 +40,7 @@ Description
namespace Foam
{
// Forward declaration of friend functions and operators
// Forward declarations
template<class T> class Smanip;
template<class T> class Imanip;
......@@ -160,15 +160,18 @@ inline Ostream& operator<<(Ostream& os, const Omanip<T>& m)
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
inline Smanip<ios_base::fmtflags> setf
(
const ios_base::fmtflags flags
)
inline Smanip<ios_base::fmtflags> setf(const ios_base::fmtflags flags)
{
return Smanip<ios_base::fmtflags>(&IOstream::setf, flags);
}
inline Omanip<char> setfill(char fillch)
{
return Omanip<char>(&Ostream::fill, fillch);
}
inline Omanip<IOstream::streamFormat> setformat
(
const IOstream::streamFormat fmt
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -239,6 +239,12 @@ public:
//- Add newline and flush stream
virtual void endl() = 0;
//- Get padding character
virtual char fill() const = 0;
//- Set padding character for formatted field up to field width
virtual char fill(const char fillch) = 0;
//- Get width of output field
virtual int width() const = 0;
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2017-2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -122,7 +122,7 @@ public:
~UOPstream();
// Member functions
// Member Functions
// Inquiry
......@@ -133,7 +133,7 @@ public:
}
// Write functions
// Write Functions
//- Write given buffer to given processor
static bool write
......@@ -223,13 +223,27 @@ public:
virtual void endl()
{}
//- Get the current padding character
// \return previous padding character
virtual char fill() const
{
return 0;
}
//- Set padding character for formatted field up to field width
virtual char fill(const char)
{
return 0;
}
//- Get width of output field
virtual int width() const
{
return 0;
}
//- Set width of output field (and return old width)
//- Set width of output field
// \return previous width
virtual int width(const int)
{
return 0;
......@@ -241,7 +255,8 @@ public:
return 0;
}
//- Set precision of output field (and return old precision)
//- Set precision of output field
// \return old precision
virtual int precision(const int)
{
return 0;
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2017-2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -289,6 +289,18 @@ std::ios_base::fmtflags Foam::OSstream::flags(const ios_base::fmtflags f)
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
char Foam::OSstream::fill() const
{
return os_.fill();
}
char Foam::OSstream::fill(const char fillch)
{
return os_.fill(fillch);
}
int Foam::OSstream::width() const
{
return os_.width();
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2017-2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -180,18 +180,25 @@ public:
//- Add newline and flush stream
virtual void endl();
//- Get the current padding character
virtual char fill() const;
//- Set padding character for formatted field up to field width
// \return previous padding character
virtual char fill(const char fillch);
//- Get width of output field
virtual int width() const;
//- Set width of output field
// \return previous width
// \return previous width
virtual int width(const int w);
//- Get precision of output field
virtual int precision() const;
//- Set precision of output field
// \return old precision
// \return old precision
virtual int precision(const int p);
......
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