mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: ensightFile writeInt() method to replace two-parameter write
- more explicit/transparent handling - avoids compiler warnings about non-virtual methods
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2015 OpenFOAM Foundation
|
||||
Copyright (C) 2016-2023 OpenCFD Ltd.
|
||||
Copyright (C) 2016-2024 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -221,7 +221,7 @@ Foam::Ostream& Foam::ensightFile::write
|
||||
}
|
||||
|
||||
|
||||
Foam::Ostream& Foam::ensightFile::write(const int32_t val)
|
||||
void Foam::ensightFile::writeInt(const int32_t val, const int fieldWidth)
|
||||
{
|
||||
if (format() == IOstreamOption::BINARY)
|
||||
{
|
||||
@ -233,24 +233,22 @@ Foam::Ostream& Foam::ensightFile::write(const int32_t val)
|
||||
}
|
||||
else
|
||||
{
|
||||
stdStream().width(10);
|
||||
stdStream().width(fieldWidth);
|
||||
stdStream() << val;
|
||||
syncState();
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Foam::Ostream& Foam::ensightFile::write(const int64_t val)
|
||||
void Foam::ensightFile::writeInt(const int64_t val, const int fieldWidth)
|
||||
{
|
||||
int32_t ivalue(narrowInt32(val));
|
||||
int32_t work(narrowInt32(val));
|
||||
|
||||
return write(ivalue);
|
||||
writeInt(work, fieldWidth);
|
||||
}
|
||||
|
||||
|
||||
Foam::Ostream& Foam::ensightFile::write(const float val)
|
||||
void Foam::ensightFile::writeFloat(const float val, const int fieldWidth)
|
||||
{
|
||||
if (format() == IOstreamOption::BINARY)
|
||||
{
|
||||
@ -262,40 +260,45 @@ Foam::Ostream& Foam::ensightFile::write(const float val)
|
||||
}
|
||||
else
|
||||
{
|
||||
stdStream().width(12);
|
||||
stdStream().width(fieldWidth);
|
||||
stdStream() << val;
|
||||
syncState();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::ensightFile::writeFloat(const double val, const int fieldWidth)
|
||||
{
|
||||
float work(narrowFloat(val));
|
||||
|
||||
writeFloat(work, fieldWidth);
|
||||
}
|
||||
|
||||
|
||||
Foam::Ostream& Foam::ensightFile::write(const int32_t val)
|
||||
{
|
||||
writeInt(val, 10);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Foam::Ostream& Foam::ensightFile::write(const int64_t val)
|
||||
{
|
||||
writeInt(val, 10);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Foam::Ostream& Foam::ensightFile::write(const float val)
|
||||
{
|
||||
writeFloat(val, 12);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Foam::Ostream& Foam::ensightFile::write(const double val)
|
||||
{
|
||||
float fvalue(narrowFloat(val));
|
||||
|
||||
return write(fvalue);
|
||||
}
|
||||
|
||||
|
||||
Foam::Ostream& Foam::ensightFile::write
|
||||
(
|
||||
const label value,
|
||||
const label fieldWidth
|
||||
)
|
||||
{
|
||||
if (format() == IOstreamOption::BINARY)
|
||||
{
|
||||
write(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
stdStream().width(fieldWidth);
|
||||
stdStream() << value;
|
||||
syncState();
|
||||
}
|
||||
|
||||
writeFloat(val, 12);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@ -376,7 +379,7 @@ void Foam::ensightFile::beginParticleCoordinates(const label nparticles)
|
||||
{
|
||||
writeString("particle coordinates");
|
||||
newline();
|
||||
write(nparticles, 8); // unusual width
|
||||
writeInt(nparticles, 8); // Warning: unusual width
|
||||
newline();
|
||||
}
|
||||
|
||||
|
||||
@ -163,6 +163,18 @@ public:
|
||||
//- Write string as "%79s" or as binary (max 80 chars)
|
||||
void writeString(const std::string& str);
|
||||
|
||||
//- Write integer value with specified width or as binary
|
||||
void writeInt(const int32_t val, const int fieldWidth);
|
||||
|
||||
//- Write (narrowed) integer value with specified width or as binary
|
||||
void writeInt(const int64_t val, const int fieldWidth);
|
||||
|
||||
//- Write floating-point with specified width or as binary
|
||||
void writeFloat(const float val, const int fieldWidth);
|
||||
|
||||
//- Write (narrowed) floating-point with specified width or as binary
|
||||
void writeFloat(const double val, const int fieldWidth);
|
||||
|
||||
//- Write undef value
|
||||
void writeUndef();
|
||||
|
||||
@ -197,15 +209,12 @@ public:
|
||||
//- Write string, uses writeString()
|
||||
virtual Ostream& write(const std::string& str) override;
|
||||
|
||||
//- Write integer as "%10d" or as binary
|
||||
//- Write integer value as "%10d" or as binary
|
||||
virtual Ostream& write(const int32_t val) override;
|
||||
|
||||
//- Write integer as "%10d" or as binary
|
||||
//- Write integer value as "%10d" or as binary (narrowed to int32_t)
|
||||
virtual Ostream& write(const int64_t val) override;
|
||||
|
||||
//- Write integer with specified width or as binary
|
||||
Ostream& write(const label value, const label fieldWidth);
|
||||
|
||||
//- Write floating-point as "%12.5e" or as binary
|
||||
virtual Ostream& write(const float val) override;
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2016-2022 OpenCFD Ltd.
|
||||
Copyright (C) 2016-2024 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -61,7 +61,7 @@ static inline label writeMeasured_ascii
|
||||
{
|
||||
for (const floatVector& p : points)
|
||||
{
|
||||
os.write(++pointId, 8); // 1-index and an unusual width
|
||||
os.writeInt(++pointId, 8); // 1-index and an unusual width
|
||||
os.write(p.x());
|
||||
os.write(p.y());
|
||||
os.write(p.z());
|
||||
|
||||
Reference in New Issue
Block a user