1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
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
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 Reads a long long from an input stream, for a given version
27 number and File format. If an ascii File is being read, then the line
28 numbers are counted and an erroneous read ised.
30 \*---------------------------------------------------------------------------*/
35 #include "IOstreams.H"
39 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 //- Return a string representation of a long long
47 word name(long long l)
49 std::ostringstream osBuffer;
51 return osBuffer.str();
54 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
56 Istream& operator>>(Istream& is, long long& l)
60 // Check state of Istream
61 is.check("Istream& operator>>(Istream&, long long&)");
67 long long readLongLong(Istream& is)
69 register long long result = 0;
73 static const label zeroOffset = int('0');
75 // Get next non-whitespace character
76 while (is.read(c) && isspace(c))
81 if (isspace(c) || c == 0) break;
85 FatalIOErrorIn("readLongLong(ISstream& is)", is)
86 << "Illegal digit: \"" << c << "\""
87 << exit(FatalIOError);
90 result *= 10 + int(c) - zeroOffset;
97 Ostream& operator<<(Ostream& os, const long long l)
101 long long mask = 1000000000000000000LL;
103 bool printZeroes = false;
107 int d = int(val/mask);
119 os.write(char(d+'0'));
125 os.check("Ostream& operator<<(Ostream&, const long long)");
130 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
132 } // End namespace Foam
134 // ************************************************************************* //