diff --git a/applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK/patchWriterTemplates.C b/applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK/patchWriterTemplates.C index e67aa4c835cd491e9b95f91aa198c71008eea75d..022df6630dd9b531261d30eea95b5a8925460d5f 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK/patchWriterTemplates.C +++ b/applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK/patchWriterTemplates.C @@ -38,7 +38,7 @@ void Foam::patchWriter::write { const GeometricField<Type, fvPatchField, volMesh>& fld = flds[fieldi]; - os_ << fld.name() << ' ' << int(pTraits<Type>::nComponents) << ' ' + os_ << fld.name() << ' ' << pTraits<Type>::nComponents << ' ' << nFaces_ << " float" << std::endl; DynamicList<floatScalar> fField(pTraits<Type>::nComponents*nFaces_); @@ -74,7 +74,7 @@ void Foam::patchWriter::write const GeometricField<Type, pointPatchField, pointMesh>& fld = flds[fieldi]; - os_ << fld.name() << ' ' << int(pTraits<Type>::nComponents) << ' ' + os_ << fld.name() << ' ' << pTraits<Type>::nComponents << ' ' << nPoints_ << " float" << std::endl; DynamicList<floatScalar> fField(pTraits<Type>::nComponents*nPoints_); @@ -103,7 +103,7 @@ void Foam::patchWriter::write { const GeometricField<Type, fvPatchField, volMesh>& fld = flds[fieldi]; - os_ << fld.name() << ' ' << int(pTraits<Type>::nComponents) << ' ' + os_ << fld.name() << ' ' << pTraits<Type>::nComponents << ' ' << nPoints_ << " float" << std::endl; DynamicList<floatScalar> fField(pTraits<Type>::nComponents*nPoints_); diff --git a/applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK/writeFunsTemplates.C b/applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK/writeFunsTemplates.C index 137dc10e9a9148c13ac583a2d41c800f7bb765b9..4dcf09ae2c83e4eed20de0cb2893794333302067 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK/writeFunsTemplates.C +++ b/applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK/writeFunsTemplates.C @@ -74,7 +74,7 @@ void Foam::writeFuns::write label nValues = mesh.nCells() + superCells.size(); - os << vvf.name() << ' ' << int(pTraits<Type>::nComponents) << ' ' + os << vvf.name() << ' ' << pTraits<Type>::nComponents << ' ' << nValues << " float" << std::endl; DynamicList<floatScalar> fField(pTraits<Type>::nComponents*nValues); @@ -106,7 +106,7 @@ void Foam::writeFuns::write const labelList& addPointCellLabels = topo.addPointCellLabels(); const label nTotPoints = mesh.nPoints() + addPointCellLabels.size(); - os << pvf.name() << ' ' << int(pTraits<Type>::nComponents) << ' ' + os << pvf.name() << ' ' << pTraits<Type>::nComponents << ' ' << nTotPoints << " float" << std::endl; DynamicList<floatScalar> fField(pTraits<Type>::nComponents*nTotPoints); @@ -139,7 +139,7 @@ void Foam::writeFuns::write const labelList& addPointCellLabels = topo.addPointCellLabels(); const label nTotPoints = mesh.nPoints() + addPointCellLabels.size(); - os << vvf.name() << ' ' << int(pTraits<Type>::nComponents) << ' ' + os << vvf.name() << ' ' << pTraits<Type>::nComponents << ' ' << nTotPoints << " float" << std::endl; DynamicList<floatScalar> fField(pTraits<Type>::nComponents*nTotPoints); diff --git a/src/OpenFOAM/Make/files b/src/OpenFOAM/Make/files index 34a1300503ce118752cf59d891e3b3ce87cfd57b..a24631da12e1b90372c4e710eeaa974b9fca349f 100644 --- a/src/OpenFOAM/Make/files +++ b/src/OpenFOAM/Make/files @@ -15,6 +15,8 @@ chars = primitives/chars $(chars)/char/charIO.C $(chars)/wchar/wcharIO.C +primitives/direction/directionIO.C + ints = primitives/ints $(ints)/uint32/uint32.C $(ints)/uint32/uint32IO.C diff --git a/src/OpenFOAM/primitives/chars/char/charIO.C b/src/OpenFOAM/primitives/chars/char/charIO.C index 4de84ca9b96ba7ab01ab00d0b810dc2d3f3d7fc6..ca69b91e0598436f36db305ba408aa532fe0883c 100644 --- a/src/OpenFOAM/primitives/chars/char/charIO.C +++ b/src/OpenFOAM/primitives/chars/char/charIO.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -21,20 +21,21 @@ License You should have received a copy of the GNU General Public License along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. -Description - Reads a char from an input stream, for a given version - number and File format. If an ascii File is being read, then the line - numbers are counted and an erroneous read is reported. - \*---------------------------------------------------------------------------*/ -#include "error.H" - #include "char.H" #include "IOstreams.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +char Foam::readChar(Istream& is) +{ + char c; + is.read(c); + return c; +} + + Foam::Istream& Foam::operator>>(Istream& is, char& c) { is.read(c); @@ -51,14 +52,6 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const char c) } -char Foam::readChar(Istream& is) -{ - char c; - is.read(c); - return c; -} - - Foam::Ostream& Foam::operator<<(Ostream& os, const char* s) { os.write(s); diff --git a/src/OpenFOAM/primitives/direction/direction.H b/src/OpenFOAM/primitives/direction/direction.H index a7ca6d3fe22bc61cb72a6efabf908435f130e8ad..459138fc502aff5e0cf3464e31df86c925ea9e3e 100644 --- a/src/OpenFOAM/primitives/direction/direction.H +++ b/src/OpenFOAM/primitives/direction/direction.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -25,23 +25,38 @@ Primitive direction Description - Direction is an integer type used to represent the Cartesian directions - etc. Currently it is a typedef to char which is limited to the range - (0, 255) which should be adequate. + Direction is an 8-bit unsigned integer type used to represent the Cartesian + directions etc. \*---------------------------------------------------------------------------*/ #ifndef direction_H #define direction_H -#include "char.H" +#define __STDC_LIMIT_MACROS +#include <stdint.h> +#include <iostream> // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam { - typedef unsigned char direction; -} + +class Istream; +class Ostream; + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +typedef uint8_t direction; + +direction readDirection(Istream&); +Istream& operator>>(Istream&, direction&); +Ostream& operator<<(Ostream&, const direction); +std::ostream& operator<<(std::ostream&, const direction); + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/primitives/direction/directionIO.C b/src/OpenFOAM/primitives/direction/directionIO.C new file mode 100644 index 0000000000000000000000000000000000000000..f8a8812a01c722b4e8a4ecaa39c42ec89731beb2 --- /dev/null +++ b/src/OpenFOAM/primitives/direction/directionIO.C @@ -0,0 +1,86 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2016 OpenFOAM Foundation + \\/ 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 "direction.H" +#include "IOstreams.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +Foam::direction Foam::readDirection(Istream& is) +{ + direction val; + is >> val; + + return val; +} + + +Foam::Istream& Foam::operator>>(Istream& is, direction& d) +{ + token t(is); + + if (!t.good()) + { + is.setBad(); + return is; + } + + if (t.isLabel()) + { + d = direction(t.labelToken()); + } + else + { + is.setBad(); + FatalIOErrorInFunction(is) + << "wrong token type - expected direction, found " << t.info() + << exit(FatalIOError); + + return is; + } + + // Check state of Istream + is.check("Istream& operator>>(Istream&, direction&)"); + + return is; +} + + +Foam::Ostream& Foam::operator<<(Ostream& os, const direction d) +{ + os.write(label(d)); + os.check("Ostream& operator<<(Ostream&, const direction)"); + return os; +} + + +std::ostream& Foam::operator<<(std::ostream& os, const direction d) +{ + os << int(d); + return os; +} + + +// ************************************************************************* // diff --git a/src/OpenFOAM/primitives/ints/int32/int32IO.C b/src/OpenFOAM/primitives/ints/int32/int32IO.C index 33dd078e3543c5bc8d7066f38437a533bd4fc8c0..4377f95992bba3744353b744cde6cb3d906532e0 100644 --- a/src/OpenFOAM/primitives/ints/int32/int32IO.C +++ b/src/OpenFOAM/primitives/ints/int32/int32IO.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2014-2015 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2014-2016 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -23,8 +23,6 @@ License \*---------------------------------------------------------------------------*/ -#include "error.H" - #include "int32.H" #include "IOstreams.H" diff --git a/src/OpenFOAM/primitives/ints/int64/int64IO.C b/src/OpenFOAM/primitives/ints/int64/int64IO.C index bb897d0d176481ff87266b56650b37d2c7f1c2b2..e9355a30121d4916e893297de733cbe02042e24f 100644 --- a/src/OpenFOAM/primitives/ints/int64/int64IO.C +++ b/src/OpenFOAM/primitives/ints/int64/int64IO.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2014-2015 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2014-2016 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -23,8 +23,6 @@ License \*---------------------------------------------------------------------------*/ -#include "error.H" - #include "int64.H" #include "IOstreams.H" diff --git a/src/OpenFOAM/primitives/ints/uint32/uint32IO.C b/src/OpenFOAM/primitives/ints/uint32/uint32IO.C index a57bcfbd4c2b3f51c071a57fd4a463c8e1def2ea..9111c2d741104b14fda923542f2f2b416957e3be 100644 --- a/src/OpenFOAM/primitives/ints/uint32/uint32IO.C +++ b/src/OpenFOAM/primitives/ints/uint32/uint32IO.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2014-2015 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2014-2016 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -23,8 +23,6 @@ License \*---------------------------------------------------------------------------*/ -#include "error.H" - #include "uint32.H" #include "IOstreams.H" diff --git a/src/OpenFOAM/primitives/ints/uint64/uint64IO.C b/src/OpenFOAM/primitives/ints/uint64/uint64IO.C index d814a9966420a1094651787d1e2240ae5d279b20..dfb7ab4db6b521d375ea5b82cd82dab8862ec885 100644 --- a/src/OpenFOAM/primitives/ints/uint64/uint64IO.C +++ b/src/OpenFOAM/primitives/ints/uint64/uint64IO.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2014-2015 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2014-2016 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -23,8 +23,6 @@ License \*---------------------------------------------------------------------------*/ -#include "error.H" - #include "uint64.H" #include "IOstreams.H"