ENH: primitives: abstract out number parsing

This commit is contained in:
mattijs 2013-08-13 14:33:37 +01:00
parent 8f144c3ab7
commit b2c8377ab1
9 changed files with 67 additions and 9 deletions

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -58,6 +58,14 @@ static const doubleScalar doubleScalarSMALL = 1.0e-15;
static const doubleScalar doubleScalarVSMALL = 1.0e-300;
static const doubleScalar doubleScalarROOTVSMALL = 1.0e-150;
//- Read whole of buf as a scalar. Return true if succesful.
inline bool readScalar(const char* buf, doubleScalar& s)
{
char* endPtr;
s = strtod(buf, &endPtr);
return (*endPtr == '\0');
}
#define Scalar doubleScalar
#define ScalarVGREAT doubleScalarVGREAT

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -58,6 +58,14 @@ static const floatScalar floatScalarSMALL = 1.0e-6;
static const floatScalar floatScalarVSMALL = 1.0e-37;
static const floatScalar floatScalarROOTVSMALL = 1.0e-18;
//- Read whole of buf as a scalar. Return true if succesful.
inline bool readScalar(const char* buf, floatScalar& s)
{
char* endPtr;
s = strtof(buf, &endPtr);
return (*endPtr == '\0');
}
#define Scalar floatScalar
#define ScalarVGREAT floatScalarVGREAT

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -54,6 +54,7 @@ word name(const int);
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
int readInt(Istream&);
bool readInt(const char*, int&);
Istream& operator>>(Istream&, int&);
Ostream& operator<<(Ostream&, const int);

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -88,6 +88,15 @@ int Foam::readInt(Istream& is)
}
bool Foam::readInt(const char* buf, int& s)
{
char *endptr = NULL;
long l = strtol(buf, &endptr, 10);
s = int(l);
return (*endptr == 0);
}
Foam::Ostream& Foam::operator<<(Ostream& os, const int i)
{
os.write(label(i));

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -72,6 +72,11 @@ namespace Foam
return readInt(is);
}
inline bool readLabel(const char* buf, label& s)
{
return readInt(buf, s);
}
} // End namespace Foam
@ -96,6 +101,11 @@ namespace Foam
return readLong(is);
}
inline bool readLabel(const char* buf, label& s)
{
return readLong(buf, s);
}
} // End namespace Foam
@ -122,6 +132,11 @@ namespace Foam
return readLongLong(is);
}
inline bool readLabel(const char* buf, label& s)
{
return readLongLong(buf, s);
}
} // End namespace Foam
#endif

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -53,6 +53,7 @@ word name(const long);
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
long readLong(Istream&);
bool readLong(const char*, long&);
Istream& operator>>(Istream&, long&);
Ostream& operator<<(Ostream&, const long);

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -85,6 +85,13 @@ long Foam::readLong(Istream& is)
return val;
}
bool Foam::readLong(const char* buf, long& s)
{
char *endptr = NULL;
s = strtol(buf, &endptr, 10);
return (*endptr == 0);
}
Foam::Ostream& Foam::operator<<(Ostream& os, const long l)
{

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -53,6 +53,7 @@ word name(long long);
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
long long readLongLong(Istream&);
bool readLongLong(const char*, long long&);
Istream& operator>>(Istream&, long long&);
Ostream& operator<<(Ostream&, const long long);

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -87,6 +87,14 @@ long long Foam::readLongLong(Istream& is)
}
bool Foam::readLongLong(const char* buf, long long& s)
{
char *endptr = NULL;
s = strtoll(buf, &endptr, 10);
return (*endptr == 0);
}
Foam::Ostream& Foam::operator<<(Ostream& os, const long long l)
{
long long val = l;