COMP: fix Darwin size ambiguities

- size ambiguity for Foam::min(string::size_type, label)

- stream operators for int16/uint16 which are needed for mode_t (Darwin)
This commit is contained in:
Mark Olesen 2018-04-24 18:03:42 +02:00
parent 7bb7f1b352
commit 0dfda5f796
15 changed files with 283 additions and 27 deletions

View File

@ -29,11 +29,13 @@ $(chars)/wchar/wcharIO.C
primitives/direction/directionIO.C
ints = primitives/ints
$(ints)/uint16/uint16.C
$(ints)/uint32/uint32.C
$(ints)/uint32/uint32IO.C
$(ints)/uint64/uint64.C
$(ints)/uint64/uint64IO.C
$(ints)/uint/uintIO.C
$(ints)/int16/int16.C
$(ints)/int32/int32.C
$(ints)/int32/int32IO.C
$(ints)/int64/int64.C

View File

@ -35,6 +35,7 @@ SourceFiles
#ifndef int_H
#define int_H
#include "int16.H"
#include "int32.H"
#include "int64.H"

View File

@ -0,0 +1,48 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2018 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 3 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, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "int16.H"
#include "int32.H"
#include "IOstreams.H"
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
Foam::Istream& Foam::operator>>(Istream& is, int16_t& val)
{
int32_t parsed;
is >> parsed;
val = int16_t(parsed); // narrow
return is;
}
Foam::Ostream& Foam::operator<<(Ostream& os, const int16_t val)
{
return (os << int32_t(val)); // widen
}
// ************************************************************************* //

View File

@ -0,0 +1,73 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2018 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 3 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, see <http://www.gnu.org/licenses/>.
Primitive
int16_t
Description
16bit signed integer. I/O is done via an int32.
SourceFiles
int16.C
\*---------------------------------------------------------------------------*/
#ifndef int16_H
#define int16_H
#include <cstdint>
#include "word.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
class Istream;
class Ostream;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
//- Return a word representation of an int16
inline word name(const int16_t val)
{
// No stripping required
return word(std::to_string(int(val)), false);
}
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
Istream& operator>>(Istream& is, int16_t& val);
Ostream& operator<<(Ostream& os, const int16_t val);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -153,10 +153,10 @@ public:
// Constructors
//- Construct from primitive
//- Copy construct from primitive
explicit pTraits(const int32_t& val);
//- Construct from Istream
//- Read construct from Istream
pTraits(Istream& is);

View File

@ -109,8 +109,9 @@ Istream& operator>>(Istream& is, int64_t& val);
Ostream& operator<<(Ostream& os, const int64_t val);
// On Darwin: long is not unambiguously (int32_t | int64_t)
// - explicitly resolve for output
#if WM_ARCH_OPTION == 64 && defined(darwin)
// - explicitly resolve for input and output
#ifdef darwin
Istream& operator>>(Istream& is, long& val);
Ostream& operator<<(Ostream& os, const long val);
#endif
@ -153,10 +154,10 @@ public:
// Constructors
//- Construct from primitive
//- Copy construct from primitive
explicit pTraits(const int64_t& val);
//- Construct from Istream
//- Read construct from Istream
pTraits(Istream& is);

View File

@ -120,11 +120,15 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const int64_t val)
}
#if WM_ARCH_OPTION == 64 && defined(darwin)
#ifdef darwin
Foam::Istream& Foam::operator>>(Istream& is, long& val)
{
return operator>>(is, reinterpret_cast<int64_t&>(val));
}
Foam::Ostream& Foam::operator<<(Ostream& os, const long val)
{
os << int64_t(val);
return os;
return (os << int64_t(val));
}
#endif

View File

@ -35,6 +35,7 @@ SourceFiles
#ifndef uint_H
#define uint_H
#include "uint16.H"
#include "uint32.H"
#include "uint64.H"

View File

@ -0,0 +1,48 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2018 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 3 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, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "uint16.H"
#include "int32.H"
#include "IOstreams.H"
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
Foam::Istream& Foam::operator>>(Istream& is, uint16_t& val)
{
int32_t parsed;
is >> parsed;
val = uint16_t(parsed); // narrow
return is;
}
Foam::Ostream& Foam::operator<<(Ostream& os, const uint16_t val)
{
return (os << int32_t(val)); // widen (fits as int32 without sign problem)
}
// ************************************************************************* //

View File

@ -0,0 +1,73 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2018 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 3 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, see <http://www.gnu.org/licenses/>.
Primitive
uint16_t
Description
16bit unsigned integer. I/O is done via an int32.
SourceFiles
uint16.C
\*---------------------------------------------------------------------------*/
#ifndef uint16_H
#define uint16_H
#include <cstdint>
#include "word.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
class Istream;
class Ostream;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
//- Return a word representation of a uint16
inline word name(const uint16_t val)
{
// No stripping required
return word(std::to_string(int(val)), false);
}
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
Istream& operator>>(Istream& is, uint16_t& val);
Ostream& operator<<(Ostream& os, const uint16_t val);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -145,10 +145,10 @@ public:
// Constructors
//- Construct from primitive
//- Copy construct from primitive
explicit pTraits(const uint32_t& val);
//- Construct from Istream
//- Read construct from Istream
pTraits(Istream& is);

View File

@ -109,7 +109,7 @@ Ostream& operator<<(Ostream& os, const uint64_t val);
// On Darwin: unsigned long is not unambiguously (uint32_t | uint64_t)
// - explicitly resolve for output
#if WM_ARCH_OPTION == 64 && defined(darwin)
#ifdef darwin
Ostream& operator<<(Ostream& os, const unsigned long val);
#endif
@ -152,10 +152,10 @@ public:
// Constructors
//- Construct from primitive
//- Copy construct from primitive
explicit pTraits(const uint64_t& val);
//- Construct from Istream
//- Read construct from Istream
pTraits(Istream& is);

View File

@ -119,7 +119,7 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const uint64_t val)
}
#if WM_ARCH_OPTION == 64 && defined(darwin)
#ifdef darwin
Foam::Ostream& Foam::operator<<(Ostream& os, const unsigned long val)
{
os << uint64_t(val);

View File

@ -45,29 +45,34 @@ void Foam::printTable
Ostream& os
)
{
if (!wll.size()) return;
if (wll.empty()) return;
// Find the maximum word length for each column
columnWidth.setSize(wll[0].size(), string::size_type(0));
forAll(columnWidth, j)
forAll(columnWidth, coli)
{
forAll(wll, i)
forAll(wll, rowi)
{
columnWidth[j] = max(columnWidth[j], wll[i][j].size());
columnWidth[coli] =
std::max
(
columnWidth[coli],
string::size_type(wll[rowi][coli].size())
);
}
}
// Print the rows adding spacing for the columns
forAll(wll, i)
forAll(wll, rowi)
{
forAll(wll[i], j)
forAll(wll[rowi], coli)
{
os << wll[i][j];
os << wll[rowi][coli];
for
(
string::size_type k=0;
k<columnWidth[j] - wll[i][j].size() + 2;
k++
string::size_type space=0;
space < columnWidth[coli] - wll[rowi][coli].size() + 2;
++space
)
{
os << ' ';
@ -75,7 +80,7 @@ void Foam::printTable
}
os << nl;
if (i == 0) os << nl;
if (!rowi) os << nl;
}
}

View File

@ -447,7 +447,7 @@ Foam::wordList Foam::basicThermo::splitThermoName
}
else if ((endc = thermoName.find(',', beg)) != string::npos)
{
end = min(endb, endc);
end = std::min(endb, endc);
}
else
{