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 #include <OpenFOAM/error.H>
00032 
00033 #include "longLong.H"
00034 #include <OpenFOAM/IOstreams.H>
00035 
00036 #include <sstream>
00037 
00038 
00039 
00040 Foam::word Foam::name(long long val)
00041 {
00042     std::ostringstream buf;
00043     buf << val;
00044     return buf.str();
00045 }
00046 
00047 
00048 
00049 Foam::Istream& Foam::operator>>(Istream& is, long long& l)
00050 {
00051     l = readLongLong(is);
00052 
00053     
00054     is.check("Istream& operator>>(Istream&, long long&)");
00055 
00056     return is;
00057 }
00058 
00059 
00060 long long Foam::readLongLong(Istream& is)
00061 {
00062     register long long result = 0;
00063 
00064     char c = 0;
00065 
00066     static const label zeroOffset = int('0');
00067 
00068     
00069     while (is.read(c) && isspace(c))
00070     {}
00071 
00072     do
00073     {
00074         if (isspace(c) || c == 0) break;
00075 
00076         if (!isdigit(c))
00077         {
00078             FatalIOErrorIn("readLongLong(ISstream& is)", is)
00079                 << "Illegal digit: \"" << c << "\""
00080                 << exit(FatalIOError);
00081         }
00082 
00083         result *= 10 + int(c) - zeroOffset;
00084     } while (is.read(c));
00085 
00086     return result;
00087 }
00088 
00089 
00090 Foam::Ostream& Foam::operator<<(Ostream& os, const long long l)
00091 {
00092     long long val = l;
00093 
00094     long long mask = 1000000000000000000LL;
00095 
00096     bool printZeroes = false;
00097 
00098     while (mask > 0)
00099     {
00100         int d = int(val/mask);
00101 
00102         if (d == 0)
00103         {
00104             if (printZeroes)
00105             {
00106                 os.write('0');
00107             }
00108         }
00109         else
00110         {
00111             printZeroes = true;
00112             os.write(char(d+'0'));
00113         }
00114 
00115         val = val % mask;
00116         mask /= 10;
00117     }
00118     os.check("Ostream& operator<<(Ostream&, const long long)");
00119     return os;
00120 }
00121 
00122 
00123