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 -------------------------------------------------------------------------------
10 License
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 
33 const char* const Foam::pTraits<int8_t>::typeName = "int8";
34 const char* const Foam::pTraits<int8_t>::componentNames[] = { "" };
35 
36 const int8_t Foam::pTraits<int8_t>::zero = 0;
37 const int8_t Foam::pTraits<int8_t>::one = 1;
38 const int8_t Foam::pTraits<int8_t>::min = INT8_MIN;
39 const int8_t Foam::pTraits<int8_t>::max = INT8_MAX;
40 const int8_t Foam::pTraits<int8_t>::rootMin = INT8_MIN;
41 const 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 
63 Foam::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"
71  << exit(FatalIOError);
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 
92  is.check(FUNCTION_NAME);
93  return is;
94 }
95 
96 
97 Foam::Ostream& Foam::operator<<(Ostream& os, const int8_t val)
98 {
99  os.write(label(val));
101  return os;
102 }
103 
104 
105 // ************************************************************************* //
bool good() const noexcept
True if token is not UNDEFINED or ERROR.
Definition: tokenI.H:507
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
virtual Ostream & write(const char c) override
Write character.
Definition: OBJstream.C:69
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:57
A token holds an item read from Istream.
Definition: token.H:65
A traits class, which is primarily used for primitives and vector-space.
Definition: pTraits.H:75
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
pTraits(const Base &obj)
Copy construct from base class.
Definition: pTraits.H:86
void setBad()
Set stream state to be &#39;bad&#39;.
Definition: IOstream.H:459
8bit signed integer
Istream & operator>>(Istream &, directionInfo &)
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
OBJstream os(runTime.globalPath()/outputName)
#define FUNCTION_NAME
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:77
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:627
label labelToken() const
Return label value.
Definition: tokenI.H:615
bool isLabel() const noexcept
Token is LABEL.
Definition: tokenI.H:599
InfoProxy< token > info() const noexcept
Return info proxy, for printing token information to a stream.
Definition: token.H:1078
IOerror FatalIOError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL IO ERROR&#39; header text and ...