Loading...
Searching...
No Matches
int8.C
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2023 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26\*---------------------------------------------------------------------------*/
27
28#include "int8.H"
29#include "IOstreams.H"
30
31// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32
33const char* const Foam::pTraits<int8_t>::typeName = "int8";
34const char* const Foam::pTraits<int8_t>::componentNames[] = { "" };
35
36const int8_t Foam::pTraits<int8_t>::zero = 0;
37const int8_t Foam::pTraits<int8_t>::one = 1;
38const int8_t Foam::pTraits<int8_t>::min = INT8_MIN;
39const int8_t Foam::pTraits<int8_t>::max = INT8_MAX;
40const int8_t Foam::pTraits<int8_t>::rootMin = INT8_MIN;
41const int8_t Foam::pTraits<int8_t>::rootMax = INT8_MAX;
42
43
44// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
45
47{
48 is >> p_;
49}
50
51
52// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
53
54// int8_t Foam::readInt8(Istream& is)
55// {
56// int8_t val(0);
57// is >> val;
58//
59// return val;
60// }
61
62
63Foam::Istream& Foam::operator>>(Istream& is, int8_t& val)
64{
65 token t(is);
66
67 if (!t.good())
68 {
70 << "Bad token - could not get int8"
72 is.setBad();
73 return is;
74 }
75
76 // Accept separated '-' (or '+') while expecting a number.
77 // This can arise during dictionary expansions (Eg, -$value)
78
79 if (t.isLabel())
80 {
81 val = int8_t(t.labelToken());
82 }
83 else
84 {
86 << "Wrong token type - expected label (int8), found "
87 << t.info() << exit(FatalIOError);
88 is.setBad();
89 return is;
90 }
91
93 return is;
94}
95
96
97Foam::Ostream& Foam::operator<<(Ostream& os, const int8_t val)
98{
99 os.write(label(val));
100 os.check(FUNCTION_NAME);
101 return os;
102}
103
104
105// ************************************************************************* //
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
void setBad() noexcept
Set stream state to be 'bad'.
Definition IOstream.H:488
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition IOstream.C:45
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition Istream.H:60
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
A traits class, which is primarily used for primitives and vector-space.
Definition pTraits.H:64
pTraits(const Base &obj)
Copy construct from base class.
Definition pTraits.H:72
A token holds an item read from Istream.
Definition token.H:70
bool isLabel() const noexcept
Integral token is convertible to Foam::label.
Definition tokenI.H:843
bool good() const noexcept
True if token is not UNDEFINED or ERROR.
Definition tokenI.H:584
label labelToken() const
Return integer type as label value or Error.
Definition tokenI.H:869
InfoProxy< token > info() const noexcept
Return info proxy, for printing token information to a stream.
Definition token.H:1253
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition error.H:629
OBJstream os(runTime.globalPath()/outputName)
8bit signed integer
#define FUNCTION_NAME
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces).
Istream & operator>>(Istream &, directionInfo &)
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition errorManip.H:125