longLongIO.C
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include "error.H"
00033
00034 #include "longLong.H"
00035 #include "IOstreams.H"
00036
00037 #include <sstream>
00038
00039
00040
00041 Foam::word Foam::name(long long val)
00042 {
00043 std::ostringstream buf;
00044 buf << val;
00045 return buf.str();
00046 }
00047
00048
00049
00050 Foam::Istream& Foam::operator>>(Istream& is, long long& l)
00051 {
00052 l = readLongLong(is);
00053
00054
00055 is.check("Istream& operator>>(Istream&, long long&)");
00056
00057 return is;
00058 }
00059
00060
00061 long long Foam::readLongLong(Istream& is)
00062 {
00063 register long long result = 0;
00064
00065 char c = 0;
00066
00067 static const label zeroOffset = int('0');
00068
00069
00070 while (is.read(c) && isspace(c))
00071 {}
00072
00073 do
00074 {
00075 if (isspace(c) || c == 0) break;
00076
00077 if (!isdigit(c))
00078 {
00079 FatalIOErrorIn("readLongLong(ISstream& is)", is)
00080 << "Illegal digit: \"" << c << "\""
00081 << exit(FatalIOError);
00082 }
00083
00084 result *= 10 + int(c) - zeroOffset;
00085 } while (is.read(c));
00086
00087 return result;
00088 }
00089
00090
00091 Foam::Ostream& Foam::operator<<(Ostream& os, const long long l)
00092 {
00093 long long val = l;
00094
00095 long long mask = 1000000000000000000LL;
00096
00097 bool printZeroes = false;
00098
00099 while (mask > 0)
00100 {
00101 int d = int(val/mask);
00102
00103 if (d == 0)
00104 {
00105 if (printZeroes)
00106 {
00107 os.write('0');
00108 }
00109 }
00110 else
00111 {
00112 printZeroes = true;
00113 os.write(char(d+'0'));
00114 }
00115
00116 val = val % mask;
00117 mask /= 10;
00118 }
00119 os.check("Ostream& operator<<(Ostream&, const long long)");
00120 return os;
00121 }
00122
00123
00124
Copyright © 2000-2009 OpenCFD Ltd