uint64IO.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2014-2018 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "uint64.H"
27 #include "IOstreams.H"
28 
29 #include <sstream>
30 
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 
33 Foam::word Foam::name(const uint64_t val)
34 {
35  std::ostringstream buf;
36  buf << val;
37  return buf.str();
38 }
39 
40 
41 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
42 
44 {
45  token t(is);
46 
47  if (!t.good())
48  {
49  is.setBad();
50  return is;
51  }
52 
53  if (t.isLabel())
54  {
55  i = uint64_t(t.labelToken());
56  }
57  else
58  {
59  is.setBad();
61  << "wrong token type - expected uint64_t, found " << t.info()
62  << exit(FatalIOError);
63 
64  return is;
65  }
66 
67  // Check state of Istream
68  is.check("Istream& operator>>(Istream&, uint64_t&)");
69 
70  return is;
71 }
72 
73 
75 {
76  uint64_t val;
77  is >> val;
78 
79  return val;
80 }
81 
82 
83 bool Foam::read(const char* buf, uint64_t& s)
84 {
85  char *endptr = nullptr;
86  long l = strtol(buf, &endptr, 10);
87  s = uint64_t(l);
88  return (*endptr == 0);
89 }
90 
91 
92 Foam::Ostream& Foam::operator<<(Ostream& os, const uint64_t i)
93 {
94  os.write(label(i));
95  os.check("Ostream& operator<<(Ostream&, const uint64_t)");
96  return os;
97 }
98 
99 
100 // ************************************************************************* //
bool isLabel() const
Definition: tokenI.H:392
virtual Ostream & write(const char)=0
Write character.
FvWallInfoData< WallInfo, label > label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
InfoProxy< token > info() const
Return info proxy.
Definition: token.H:391
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
A token holds items read from Istream.
Definition: token.H:72
64bit uinteger
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
void setBad()
Set stream to be bad.
Definition: IOstream.H:484
bool read(const char *, int32_t &)
Definition: int32IO.C:85
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
A class for handling words, derived from string.
Definition: word.H:59
Istream & operator>>(Istream &, directionInfo &)
bool good() const
Definition: tokenI.H:228
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:318
uint64_t readUint64(Istream &)
Definition: uint64IO.C:74
Ostream & operator<<(Ostream &, const ensightPart &)
label labelToken() const
Definition: tokenI.H:397
IOerror FatalIOError