mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
Merge branch 'feature-string-parsing' into 'develop'
improve consistency in parsing primitives from strings See merge request !146
This commit is contained in:
3
applications/test/argList/Make/files
Normal file
3
applications/test/argList/Make/files
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
Test-argList.C
|
||||||
|
|
||||||
|
EXE = $(FOAM_USER_APPBIN)/Test-argList
|
||||||
2
applications/test/argList/Make/options
Normal file
2
applications/test/argList/Make/options
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
/* EXE_INC = -I$(LIB_SRC)/cfdTools/include */
|
||||||
|
/* EXE_LIBS = -lfiniteVolume */
|
||||||
80
applications/test/argList/Test-argList.C
Normal file
80
applications/test/argList/Test-argList.C
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
|
||||||
|
\\/ M anipulation |
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
License
|
||||||
|
This file is part of OpenFOAM.
|
||||||
|
|
||||||
|
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||||
|
under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Description
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#include "argList.H"
|
||||||
|
#include "IOstreams.H"
|
||||||
|
#include "StringStream.H"
|
||||||
|
|
||||||
|
using namespace Foam;
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
// Main program:
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
argList::noBanner();
|
||||||
|
argList::noParallel();
|
||||||
|
argList::noFunctionObjects();
|
||||||
|
argList::removeOption("case");
|
||||||
|
|
||||||
|
argList::addOption("label", "value", "Test parsing of label");
|
||||||
|
argList::addOption("scalar", "value", "Test parsing of scalar");
|
||||||
|
|
||||||
|
argList args(argc, argv);
|
||||||
|
|
||||||
|
label ival;
|
||||||
|
scalar sval;
|
||||||
|
|
||||||
|
Info<< nl;
|
||||||
|
|
||||||
|
Info<< "-label = " << flush;
|
||||||
|
if (args.optionReadIfPresent("label", ival))
|
||||||
|
{
|
||||||
|
Info<< ival << endl;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Info<< "not specified" << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
Info<< "-scalar = " << flush;
|
||||||
|
if (args.optionReadIfPresent("scalar", sval))
|
||||||
|
{
|
||||||
|
Info<< sval << endl;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Info<< "not specified" << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
Info<< "\nEnd\n" << endl;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
3
applications/test/primitives/Make/files
Normal file
3
applications/test/primitives/Make/files
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
Test-primitives.C
|
||||||
|
|
||||||
|
EXE = $(FOAM_USER_APPBIN)/Test-primitives
|
||||||
5
applications/test/primitives/Make/options
Normal file
5
applications/test/primitives/Make/options
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
EXE_INC = \
|
||||||
|
-I$(LIB_SRC)/fileFormats/lnInclude
|
||||||
|
|
||||||
|
EXE_LIBS = \
|
||||||
|
-lfileFormats
|
||||||
198
applications/test/primitives/Test-primitives.C
Normal file
198
applications/test/primitives/Test-primitives.C
Normal file
@ -0,0 +1,198 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
|
||||||
|
\\/ M anipulation |
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
License
|
||||||
|
This file is part of OpenFOAM.
|
||||||
|
|
||||||
|
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||||
|
under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Application
|
||||||
|
Test-primitives
|
||||||
|
|
||||||
|
Description
|
||||||
|
Parsing etc for primitives.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#include "scalar.H"
|
||||||
|
#include "label.H"
|
||||||
|
#include "StringStream.H"
|
||||||
|
#include "NASCore.H"
|
||||||
|
#include "parsing.H"
|
||||||
|
#include "Tuple2.H"
|
||||||
|
|
||||||
|
using namespace Foam;
|
||||||
|
|
||||||
|
// Shadow fileFormats::NASCore::readNasScalar
|
||||||
|
inline scalar readNasScalar(const std::string& str)
|
||||||
|
{
|
||||||
|
return fileFormats::NASCore::readNasScalar(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
template<class TYPE>
|
||||||
|
unsigned testParsing
|
||||||
|
(
|
||||||
|
TYPE (*function)(const std::string&),
|
||||||
|
const List<Tuple2<std::string, bool>>& tests
|
||||||
|
)
|
||||||
|
{
|
||||||
|
unsigned nFail = 0;
|
||||||
|
|
||||||
|
// Expect some failures
|
||||||
|
const bool prev = FatalIOError.throwExceptions();
|
||||||
|
|
||||||
|
for (const Tuple2<std::string, bool>& test : tests)
|
||||||
|
{
|
||||||
|
const std::string& str = test.first();
|
||||||
|
const bool expected = test.second();
|
||||||
|
|
||||||
|
bool parsed = true;
|
||||||
|
|
||||||
|
TYPE val;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
val = function (str);
|
||||||
|
}
|
||||||
|
catch (Foam::error& err)
|
||||||
|
{
|
||||||
|
parsed = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parsed)
|
||||||
|
{
|
||||||
|
if (expected)
|
||||||
|
{
|
||||||
|
Info<< "(pass) parsed " << str << " = " << val << nl;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
++nFail;
|
||||||
|
Info<< "(fail) unexpected success for " << str << nl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (expected)
|
||||||
|
{
|
||||||
|
++nFail;
|
||||||
|
Info<< "(fail) unexpected failure " << str << nl;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Info<< "(pass) expected failure " << str << nl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
FatalIOError.throwExceptions(prev);
|
||||||
|
|
||||||
|
return nFail;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
unsigned nFail = 0;
|
||||||
|
|
||||||
|
{
|
||||||
|
Info<< nl << "Test readDouble:" << nl;
|
||||||
|
nFail += testParsing
|
||||||
|
(
|
||||||
|
&readDouble,
|
||||||
|
{
|
||||||
|
{ "", false },
|
||||||
|
{ " ", false },
|
||||||
|
{ " xxx ", false },
|
||||||
|
{ " 1234E-", false },
|
||||||
|
{ " 1234E junk", false },
|
||||||
|
{ " 3.14159 ", true },
|
||||||
|
{ " 31.4159E-1 " , true },
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
Info<< nl << "Test readFloat:" << nl;
|
||||||
|
nFail += testParsing
|
||||||
|
(
|
||||||
|
&readFloat,
|
||||||
|
{
|
||||||
|
{ " 3.14159 ", true },
|
||||||
|
{ " 31.4159E-1 " , true },
|
||||||
|
{ " 31.4159E200 " , false },
|
||||||
|
{ " 31.4159E20 " , true },
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
Info<< nl << "Test readNasScalar:" << nl;
|
||||||
|
nFail += testParsing
|
||||||
|
(
|
||||||
|
&readNasScalar,
|
||||||
|
{
|
||||||
|
{ " 3.14159 ", true },
|
||||||
|
{ " 31.4159E-1 " , true },
|
||||||
|
{ " 314.159-2 " , true },
|
||||||
|
{ " 31.4159E200 " , true },
|
||||||
|
{ " 31.4159E20 " , true },
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
Info<< nl << "Test readInt32 (max= " << INT32_MAX << "):" << nl;
|
||||||
|
nFail += testParsing
|
||||||
|
(
|
||||||
|
&readInt32,
|
||||||
|
{
|
||||||
|
{ " 3.14159 ", false },
|
||||||
|
{ " 31.4159E-1 " , false },
|
||||||
|
{ "100" , true },
|
||||||
|
{ " 2147483644" , true },
|
||||||
|
{ " 2147483700 " , false },
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
Info<< nl << "Test readUint32 (max= " << INT32_MAX << "):" << nl;
|
||||||
|
nFail += testParsing
|
||||||
|
(
|
||||||
|
&readUint32,
|
||||||
|
{
|
||||||
|
{ " 2147483644" , true },
|
||||||
|
{ " 2147483700 " , true },
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nFail)
|
||||||
|
{
|
||||||
|
Info<< nl << "failed " << nFail << " tests" << nl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
Info<< nl << "passed all tests" << nl;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
@ -93,8 +93,8 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
const scalar scaleFactor = args.optionLookupOrDefault("scale", 1.0);
|
const scalar scaleFactor = args.optionLookupOrDefault("scale", 1.0);
|
||||||
|
|
||||||
bool readBlank = !args.optionFound("noBlank");
|
const bool readBlank = !args.optionFound("noBlank");
|
||||||
bool singleBlock = args.optionFound("singleBlock");
|
const bool singleBlock = args.optionFound("singleBlock");
|
||||||
scalar twoDThickness = -1;
|
scalar twoDThickness = -1;
|
||||||
if (args.optionReadIfPresent("2D", twoDThickness))
|
if (args.optionReadIfPresent("2D", twoDThickness))
|
||||||
{
|
{
|
||||||
|
|||||||
@ -28,7 +28,7 @@ License
|
|||||||
#include "IFstream.H"
|
#include "IFstream.H"
|
||||||
#include "StringStream.H"
|
#include "StringStream.H"
|
||||||
|
|
||||||
#include <inttypes.h>
|
#include <cinttypes>
|
||||||
#include <cxxabi.h>
|
#include <cxxabi.h>
|
||||||
#include <execinfo.h>
|
#include <execinfo.h>
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
|
|||||||
@ -114,6 +114,7 @@ $(strings)/wordRe/wordRe.C
|
|||||||
$(strings)/wordRes/wordRes.C
|
$(strings)/wordRes/wordRes.C
|
||||||
$(strings)/lists/hashedWordList.C
|
$(strings)/lists/hashedWordList.C
|
||||||
$(strings)/stringOps/stringOps.C
|
$(strings)/stringOps/stringOps.C
|
||||||
|
$(strings)/parsing/parsing.C
|
||||||
|
|
||||||
ops = primitives/ops
|
ops = primitives/ops
|
||||||
$(ops)/flipOp.C
|
$(ops)/flipOp.C
|
||||||
|
|||||||
@ -143,7 +143,7 @@ void Foam::dimensionSet::tokeniser::splitWord(const word& w)
|
|||||||
const word subWord = w.substr(start, i-start);
|
const word subWord = w.substr(start, i-start);
|
||||||
if (isdigit(subWord[0]) || subWord[0] == token::SUBTRACT)
|
if (isdigit(subWord[0]) || subWord[0] == token::SUBTRACT)
|
||||||
{
|
{
|
||||||
push(token(readScalar(IStringStream(subWord)())));
|
push(token(readScalar(subWord)));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -154,7 +154,9 @@ void Foam::dimensionSet::tokeniser::splitWord(const word& w)
|
|||||||
{
|
{
|
||||||
if (isdigit(w[i]))
|
if (isdigit(w[i]))
|
||||||
{
|
{
|
||||||
push(token(readScalar(IStringStream(w[i])())));
|
// Single digit: as scalar value
|
||||||
|
const scalar val = (w[i] - '0');
|
||||||
|
push(token(val));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -169,7 +171,7 @@ void Foam::dimensionSet::tokeniser::splitWord(const word& w)
|
|||||||
const word subWord = w.substr(start);
|
const word subWord = w.substr(start);
|
||||||
if (isdigit(subWord[0]) || subWord[0] == token::SUBTRACT)
|
if (isdigit(subWord[0]) || subWord[0] == token::SUBTRACT)
|
||||||
{
|
{
|
||||||
push(token(readScalar(IStringStream(subWord)())));
|
push(token(readScalar(subWord)));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -539,7 +541,7 @@ Foam::Istream& Foam::dimensionSet::read
|
|||||||
{
|
{
|
||||||
const word symbol = symbolPow.substr(0, index);
|
const word symbol = symbolPow.substr(0, index);
|
||||||
const word exp = symbolPow.substr(index+1);
|
const word exp = symbolPow.substr(index+1);
|
||||||
scalar exponent = readScalar(IStringStream(exp)());
|
scalar exponent = readScalar(exp);
|
||||||
|
|
||||||
dimensionedScalar s;
|
dimensionedScalar s;
|
||||||
s.read(readSet[symbol], readSet);
|
s.read(readSet[symbol], readSet);
|
||||||
|
|||||||
@ -281,10 +281,10 @@ public:
|
|||||||
inline T argRead(const label index) const;
|
inline T argRead(const label index) const;
|
||||||
|
|
||||||
//- Return options
|
//- Return options
|
||||||
inline const Foam::HashTable<string>& options() const;
|
inline const HashTable<string>& options() const;
|
||||||
|
|
||||||
//- Return non-const access to options
|
//- Return non-const access to options
|
||||||
inline Foam::HashTable<string>& options();
|
inline HashTable<string>& options();
|
||||||
|
|
||||||
//- Return the argument string associated with the named option
|
//- Return the argument string associated with the named option
|
||||||
inline const string& option(const word& opt) const;
|
inline const string& option(const word& opt) const;
|
||||||
@ -302,7 +302,7 @@ public:
|
|||||||
//- Read a value from the named option if present.
|
//- Read a value from the named option if present.
|
||||||
// Return true if the named option was found.
|
// Return true if the named option was found.
|
||||||
template<class T>
|
template<class T>
|
||||||
inline bool optionReadIfPresent(const word& opt, T&) const;
|
inline bool optionReadIfPresent(const word& opt, T& val) const;
|
||||||
|
|
||||||
//- Read a value from the named option if present.
|
//- Read a value from the named option if present.
|
||||||
// Return true if the named option was found, otherwise
|
// Return true if the named option was found, otherwise
|
||||||
@ -311,7 +311,7 @@ public:
|
|||||||
inline bool optionReadIfPresent
|
inline bool optionReadIfPresent
|
||||||
(
|
(
|
||||||
const word& opt,
|
const word& opt,
|
||||||
T&,
|
T& val,
|
||||||
const T& deflt
|
const T& deflt
|
||||||
) const;
|
) const;
|
||||||
|
|
||||||
@ -328,7 +328,7 @@ public:
|
|||||||
template<class T>
|
template<class T>
|
||||||
List<T> optionReadList(const word& opt) const
|
List<T> optionReadList(const word& opt) const
|
||||||
{
|
{
|
||||||
return readList<T>(optionLookup(opt)());
|
return Foam::readList<T>(optionLookup(opt)());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -369,7 +369,7 @@ public:
|
|||||||
|
|
||||||
//- Add extra notes for the usage information
|
//- Add extra notes for the usage information
|
||||||
// This string is used "as-is" without additional formatting
|
// This string is used "as-is" without additional formatting
|
||||||
static void addNote(const string&);
|
static void addNote(const string& note);
|
||||||
|
|
||||||
//- Remove option from validOptions and from optionUsage
|
//- Remove option from validOptions and from optionUsage
|
||||||
static void removeOption(const word& opt);
|
static void removeOption(const word& opt);
|
||||||
|
|||||||
@ -127,53 +127,84 @@ inline Foam::IStringStream Foam::argList::optionLookup(const word& opt) const
|
|||||||
|
|
||||||
namespace Foam
|
namespace Foam
|
||||||
{
|
{
|
||||||
// Template specialization for string
|
//
|
||||||
|
// Specializations for argRead
|
||||||
|
//
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
inline Foam::string
|
inline Foam::string
|
||||||
Foam::argList::argRead<Foam::string>(const label index) const
|
argList::argRead<Foam::string>(const label index) const
|
||||||
{
|
{
|
||||||
return args_[index];
|
return args_[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Template specialization for word
|
|
||||||
template<>
|
template<>
|
||||||
inline Foam::word
|
inline Foam::word
|
||||||
Foam::argList::argRead<Foam::word>(const label index) const
|
argList::argRead<Foam::word>(const label index) const
|
||||||
{
|
{
|
||||||
return args_[index];
|
return args_[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Template specialization for fileName
|
|
||||||
template<>
|
template<>
|
||||||
inline Foam::fileName
|
inline Foam::fileName
|
||||||
Foam::argList::argRead<Foam::fileName>(const label index) const
|
argList::argRead<Foam::fileName>(const label index) const
|
||||||
{
|
{
|
||||||
return args_[index];
|
return args_[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Template specialization for string
|
template<>
|
||||||
|
inline Foam::label
|
||||||
|
argList::argRead<Foam::label>(const label index) const
|
||||||
|
{
|
||||||
|
return Foam::readLabel(args_[index]);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<>
|
||||||
|
inline Foam::scalar
|
||||||
|
argList::argRead<Foam::scalar>(const label index) const
|
||||||
|
{
|
||||||
|
return Foam::readScalar(args_[index]);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Specializations for optionRead
|
||||||
|
//
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
inline Foam::string
|
inline Foam::string
|
||||||
Foam::argList::optionRead<Foam::string>(const word& opt) const
|
argList::optionRead<Foam::string>(const word& opt) const
|
||||||
{
|
{
|
||||||
return options_[opt];
|
return options_[opt];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Template specialization for word
|
|
||||||
template<>
|
template<>
|
||||||
inline Foam::word
|
inline Foam::word
|
||||||
Foam::argList::optionRead<Foam::word>(const word& opt) const
|
argList::optionRead<Foam::word>(const word& opt) const
|
||||||
{
|
{
|
||||||
return options_[opt];
|
return options_[opt];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Template specialization for fileName
|
|
||||||
template<>
|
template<>
|
||||||
inline Foam::fileName
|
inline Foam::fileName
|
||||||
Foam::argList::optionRead<Foam::fileName>(const word& opt) const
|
argList::optionRead<Foam::fileName>(const word& opt) const
|
||||||
{
|
{
|
||||||
return options_[opt];
|
return options_[opt];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<>
|
||||||
|
inline Foam::label
|
||||||
|
argList::optionRead<Foam::label>(const word& opt) const
|
||||||
|
{
|
||||||
|
return Foam::readLabel(options_[opt]);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<>
|
||||||
|
inline Foam::scalar
|
||||||
|
argList::optionRead<Foam::scalar>(const word& opt) const
|
||||||
|
{
|
||||||
|
return Foam::readScalar(options_[opt]);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -71,7 +71,7 @@ namespace Foam
|
|||||||
<< exit(FatalError);
|
<< exit(FatalError);
|
||||||
}
|
}
|
||||||
|
|
||||||
return readScalar(IStringStream(splitted[componentColumns_[0]])());
|
return readScalar(splitted[componentColumns_[0]]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -80,7 +80,7 @@ namespace Foam
|
|||||||
{
|
{
|
||||||
Type result;
|
Type result;
|
||||||
|
|
||||||
for(label i = 0;i < pTraits<Type>::nComponents; i++)
|
for (label i = 0; i < pTraits<Type>::nComponents; ++i)
|
||||||
{
|
{
|
||||||
if (componentColumns_[i] >= splitted.size())
|
if (componentColumns_[i] >= splitted.size())
|
||||||
{
|
{
|
||||||
@ -90,10 +90,7 @@ namespace Foam
|
|||||||
<< exit(FatalError);
|
<< exit(FatalError);
|
||||||
}
|
}
|
||||||
|
|
||||||
result[i] = readScalar
|
result[i] = readScalar(splitted[componentColumns_[i]]);
|
||||||
(
|
|
||||||
IStringStream(splitted[componentColumns_[i]])()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@ -150,7 +147,7 @@ void Foam::csvTableReader<Type>::operator()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
scalar time = readScalar(IStringStream(splitted[timeColumn_])());
|
scalar time = readScalar(splitted[timeColumn_]);
|
||||||
Type value = readValue(splitted);
|
Type value = readValue(splitted);
|
||||||
|
|
||||||
values.append(Tuple2<scalar,Type>(time, value));
|
values.append(Tuple2<scalar,Type>(time, value));
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
\\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -42,9 +42,9 @@ const Scalar pTraits<Scalar>::rootMax = ScalarROOTVGREAT;
|
|||||||
|
|
||||||
const char* const pTraits<Scalar>::componentNames[] = { "" };
|
const char* const pTraits<Scalar>::componentNames[] = { "" };
|
||||||
|
|
||||||
pTraits<Scalar>::pTraits(const Scalar& p)
|
pTraits<Scalar>::pTraits(const Scalar& val)
|
||||||
:
|
:
|
||||||
p_(p)
|
p_(val)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
@ -54,7 +54,7 @@ pTraits<Scalar>::pTraits(Istream& is)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * IO/Conversion * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
word name(const Scalar val)
|
word name(const Scalar val)
|
||||||
{
|
{
|
||||||
@ -76,18 +76,59 @@ word name(const std::string& fmt, const Scalar val)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
|
Scalar ScalarRead(const char* buf)
|
||||||
|
|
||||||
Scalar readScalar(Istream& is)
|
|
||||||
{
|
{
|
||||||
Scalar rs;
|
char* endptr = nullptr;
|
||||||
is >> rs;
|
errno = 0;
|
||||||
|
|
||||||
return rs;
|
const Scalar val = ScalarConvert(buf, &endptr);
|
||||||
|
|
||||||
|
const parsing::errorType err = parsing::checkConversion(buf, endptr);
|
||||||
|
if (err != parsing::errorType::NONE)
|
||||||
|
{
|
||||||
|
FatalIOErrorInFunction("unknown")
|
||||||
|
<< parsing::errorNames[err] << " '" << buf << "'"
|
||||||
|
<< exit(FatalIOError);
|
||||||
|
}
|
||||||
|
|
||||||
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Istream& operator>>(Istream& is, Scalar& s)
|
bool readScalar(const char* buf, Scalar& val)
|
||||||
|
{
|
||||||
|
char* endptr = nullptr;
|
||||||
|
errno = 0;
|
||||||
|
|
||||||
|
val = ScalarConvert(buf, &endptr);
|
||||||
|
|
||||||
|
const parsing::errorType err = parsing::checkConversion(buf, endptr);
|
||||||
|
if (err != parsing::errorType::NONE)
|
||||||
|
{
|
||||||
|
#ifdef FULLDEBUG
|
||||||
|
IOWarningInFunction("unknown")
|
||||||
|
<< parsing::errorNames[err] << " '" << buf << "'"
|
||||||
|
<< endl;
|
||||||
|
#endif
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
Scalar ScalarRead(Istream& is)
|
||||||
|
{
|
||||||
|
Scalar val;
|
||||||
|
is >> val;
|
||||||
|
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Istream& operator>>(Istream& is, Scalar& val)
|
||||||
{
|
{
|
||||||
token t(is);
|
token t(is);
|
||||||
|
|
||||||
@ -99,7 +140,7 @@ Istream& operator>>(Istream& is, Scalar& s)
|
|||||||
|
|
||||||
if (t.isNumber())
|
if (t.isNumber())
|
||||||
{
|
{
|
||||||
s = t.number();
|
val = t.number();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -116,9 +157,9 @@ Istream& operator>>(Istream& is, Scalar& s)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Ostream& operator<<(Ostream& os, const Scalar s)
|
Ostream& operator<<(Ostream& os, const Scalar val)
|
||||||
{
|
{
|
||||||
os.write(s);
|
os.write(val);
|
||||||
os.check(FUNCTION_NAME);
|
os.check(FUNCTION_NAME);
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||||
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
\\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -25,7 +25,7 @@ Typedef
|
|||||||
Foam::Scalar
|
Foam::Scalar
|
||||||
|
|
||||||
Description
|
Description
|
||||||
Single floating point number (float or double)
|
Floating-point number (float or double)
|
||||||
|
|
||||||
SourceFiles
|
SourceFiles
|
||||||
Scalar.C
|
Scalar.C
|
||||||
@ -81,10 +81,10 @@ public:
|
|||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
//- Construct from primitive
|
//- Construct from primitive
|
||||||
explicit pTraits(const Scalar&);
|
explicit pTraits(const Scalar& val);
|
||||||
|
|
||||||
//- Construct from Istream
|
//- Construct from Istream
|
||||||
pTraits(Istream&);
|
pTraits(Istream& is);
|
||||||
|
|
||||||
|
|
||||||
// Member Functions
|
// Member Functions
|
||||||
@ -103,21 +103,47 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * IO/Conversion * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
//- Return a string representation of a Scalar
|
//- Return a string representation of a Scalar
|
||||||
word name(const Scalar);
|
word name(const Scalar val);
|
||||||
|
|
||||||
|
|
||||||
//- Return a word representation of a Scalar, using printf-style formatter.
|
//- Return a word representation of a Scalar, using printf-style formatter.
|
||||||
// The representation is not checked for valid word characters.
|
// The representation is not checked for valid word characters.
|
||||||
word name(const char* fmt, const Scalar);
|
word name(const char* fmt, const Scalar val);
|
||||||
|
|
||||||
|
|
||||||
//- Return a word representation of a Scalar, using printf-style formatter.
|
//- Return a word representation of a Scalar, using printf-style formatter.
|
||||||
// The representation is not checked for valid word characters.
|
// The representation is not checked for valid word characters.
|
||||||
word name(const std::string& fmt, const Scalar);
|
word name(const std::string& fmt, const Scalar val);
|
||||||
|
|
||||||
|
//- Parse entire buffer as a float/double, skipping leading/trailing whitespace.
|
||||||
|
// \return Parsed value or FatalIOError on any problem
|
||||||
|
Scalar ScalarRead(const char* buf);
|
||||||
|
|
||||||
|
//- Parse entire string as a float/double, skipping leading/trailing whitespace.
|
||||||
|
// \return Parsed value or FatalIOError on any problem
|
||||||
|
inline Scalar ScalarRead(const std::string& str)
|
||||||
|
{
|
||||||
|
return ScalarRead(str.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
//- Parse entire buffer as a float/double, skipping leading/trailing whitespace.
|
||||||
|
// \return True if successful.
|
||||||
|
bool readScalar(const char* buf, Scalar& val);
|
||||||
|
|
||||||
|
//- Parse entire string as a float/double, skipping leading/trailing whitespace.
|
||||||
|
// \return True if successful.
|
||||||
|
inline bool readScalar(const std::string& str, Scalar& val)
|
||||||
|
{
|
||||||
|
return readScalar(str.c_str(), val);
|
||||||
|
}
|
||||||
|
|
||||||
|
Scalar ScalarRead(Istream& is);
|
||||||
|
Istream& operator>>(Istream& is, Scalar& val);
|
||||||
|
Ostream& operator<<(Ostream& os, const Scalar val);
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
// Standard C++ transcendental functions
|
// Standard C++ transcendental functions
|
||||||
transFunc(sqrt)
|
transFunc(sqrt)
|
||||||
@ -344,8 +370,8 @@ inline Scalar cmptMag(const Scalar s)
|
|||||||
|
|
||||||
inline Scalar sqrtSumSqr(const Scalar a, const Scalar b)
|
inline Scalar sqrtSumSqr(const Scalar a, const Scalar b)
|
||||||
{
|
{
|
||||||
Scalar maga = mag(a);
|
const Scalar maga = mag(a);
|
||||||
Scalar magb = mag(b);
|
const Scalar magb = mag(b);
|
||||||
|
|
||||||
if (maga > magb)
|
if (maga > magb)
|
||||||
{
|
{
|
||||||
@ -372,12 +398,6 @@ inline Scalar stabilise(const Scalar s, const Scalar small)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
Scalar readScalar(Istream&);
|
|
||||||
Istream& operator>>(Istream&, Scalar&);
|
|
||||||
Ostream& operator<<(Ostream&, const Scalar);
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
} // End namespace Foam
|
} // End namespace Foam
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -24,24 +24,32 @@ License
|
|||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include "doubleScalar.H"
|
#include "doubleScalar.H"
|
||||||
|
#include "error.H"
|
||||||
|
#include "parsing.H"
|
||||||
#include "IOstreams.H"
|
#include "IOstreams.H"
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
// Scalar.C is used for template-like substitution
|
||||||
|
|
||||||
#define Scalar doubleScalar
|
#define Scalar doubleScalar
|
||||||
#define ScalarVGREAT doubleScalarVGREAT
|
#define ScalarVGREAT doubleScalarVGREAT
|
||||||
#define ScalarVSMALL doubleScalarVSMALL
|
#define ScalarVSMALL doubleScalarVSMALL
|
||||||
#define ScalarROOTVGREAT doubleScalarROOTVGREAT
|
#define ScalarROOTVGREAT doubleScalarROOTVGREAT
|
||||||
#define ScalarROOTVSMALL doubleScalarROOTVSMALL
|
#define ScalarROOTVSMALL doubleScalarROOTVSMALL
|
||||||
#define readScalar readDoubleScalar
|
#define ScalarRead readDouble
|
||||||
|
#define ScalarConvert ::strtod
|
||||||
|
|
||||||
#include "Scalar.C"
|
#include "Scalar.C"
|
||||||
|
|
||||||
#undef Scalar
|
#undef Scalar
|
||||||
#undef ScalarVGREAT
|
#undef ScalarVGREAT
|
||||||
#undef ScalarVSMALL
|
#undef ScalarVSMALL
|
||||||
#undef ScalarROOTVGREAT
|
#undef ScalarROOTVGREAT
|
||||||
#undef ScalarROOTVSMALL
|
#undef ScalarROOTVSMALL
|
||||||
#undef readScalar
|
#undef ScalarRead
|
||||||
|
#undef ScalarConvert
|
||||||
|
|
||||||
// ************************************************************************* //
|
// ************************************************************************* //
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -25,7 +25,7 @@ Typedef
|
|||||||
Foam::doubleScalar
|
Foam::doubleScalar
|
||||||
|
|
||||||
Description
|
Description
|
||||||
Double precision floating point scalar type.
|
Floating-point double precision scalar type.
|
||||||
|
|
||||||
SourceFiles
|
SourceFiles
|
||||||
doubleScalar.C
|
doubleScalar.C
|
||||||
@ -59,48 +59,20 @@ static const doubleScalar doubleScalarROOTSMALL = 3.0e-8;
|
|||||||
static const doubleScalar doubleScalarVSMALL = 1.0e-300;
|
static const doubleScalar doubleScalarVSMALL = 1.0e-300;
|
||||||
static const doubleScalar doubleScalarROOTVSMALL = 1.0e-150;
|
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 Scalar doubleScalar
|
||||||
#define ScalarVGREAT doubleScalarVGREAT
|
#define ScalarVGREAT doubleScalarVGREAT
|
||||||
#define ScalarVSMALL doubleScalarVSMALL
|
#define ScalarVSMALL doubleScalarVSMALL
|
||||||
#define ScalarROOTVGREAT doubleScalarROOTVGREAT
|
#define ScalarROOTVGREAT doubleScalarROOTVGREAT
|
||||||
#define ScalarROOTVSMALL doubleScalarROOTVSMALL
|
#define ScalarROOTVSMALL doubleScalarROOTVSMALL
|
||||||
#define readScalar readDoubleScalar
|
#define ScalarRead readDouble
|
||||||
|
|
||||||
|
|
||||||
inline Scalar mag(const Scalar s)
|
inline Scalar mag(const Scalar s)
|
||||||
{
|
{
|
||||||
return ::fabs(s);
|
return ::fabs(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define transFunc(func) \
|
|
||||||
inline Scalar func(const Scalar s) \
|
|
||||||
{ \
|
|
||||||
return ::func(s); \
|
|
||||||
}
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
} // End namespace Foam
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
#include "Scalar.H"
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
namespace Foam
|
|
||||||
{
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
inline Scalar hypot(const Scalar x, const Scalar y)
|
inline Scalar hypot(const Scalar x, const Scalar y)
|
||||||
{
|
{
|
||||||
return ::hypot(x, y);
|
return ::hypot(x, y);
|
||||||
@ -121,19 +93,30 @@ inline Scalar yn(const int n, const Scalar s)
|
|||||||
return ::yn(n, s);
|
return ::yn(n, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef Scalar
|
// Normal (double-precision) transcendental functions
|
||||||
#undef ScalarVGREAT
|
#define transFunc(func) \
|
||||||
#undef ScalarVSMALL
|
inline Scalar func(const Scalar s) \
|
||||||
#undef ScalarROOTVGREAT
|
{ \
|
||||||
#undef ScalarROOTVSMALL
|
return ::func(s); \
|
||||||
#undef readScalar
|
}
|
||||||
#undef transFunc
|
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
} // End namespace Foam
|
} // End namespace Foam
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
#include "Scalar.H"
|
||||||
|
|
||||||
|
#undef Scalar
|
||||||
|
#undef ScalarVGREAT
|
||||||
|
#undef ScalarVSMALL
|
||||||
|
#undef ScalarROOTVGREAT
|
||||||
|
#undef ScalarROOTVSMALL
|
||||||
|
#undef ScalarRead
|
||||||
|
#undef transFunc
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -24,24 +24,32 @@ License
|
|||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include "floatScalar.H"
|
#include "floatScalar.H"
|
||||||
|
#include "error.H"
|
||||||
|
#include "parsing.H"
|
||||||
#include "IOstreams.H"
|
#include "IOstreams.H"
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
// Scalar.C is used for template-like substitution
|
||||||
|
|
||||||
#define Scalar floatScalar
|
#define Scalar floatScalar
|
||||||
#define ScalarVGREAT floatScalarVGREAT
|
#define ScalarVGREAT floatScalarVGREAT
|
||||||
#define ScalarVSMALL floatScalarVSMALL
|
#define ScalarVSMALL floatScalarVSMALL
|
||||||
#define ScalarROOTVGREAT floatScalarROOTVGREAT
|
#define ScalarROOTVGREAT floatScalarROOTVGREAT
|
||||||
#define ScalarROOTVSMALL floatScalarROOTVSMALL
|
#define ScalarROOTVSMALL floatScalarROOTVSMALL
|
||||||
#define readScalar readFloatScalar
|
#define ScalarRead readFloat
|
||||||
|
#define ScalarConvert ::strtof
|
||||||
|
|
||||||
#include "Scalar.C"
|
#include "Scalar.C"
|
||||||
|
|
||||||
#undef Scalar
|
#undef Scalar
|
||||||
#undef ScalarVSMALL
|
#undef ScalarVGREAT
|
||||||
#undef ScalarVSMALL
|
#undef ScalarVSMALL
|
||||||
#undef ScalarROOTVGREAT
|
#undef ScalarROOTVGREAT
|
||||||
#undef ScalarROOTVSMALL
|
#undef ScalarROOTVSMALL
|
||||||
#undef readScalar
|
#undef ScalarRead
|
||||||
|
#undef ScalarConvert
|
||||||
|
|
||||||
// ************************************************************************* //
|
// ************************************************************************* //
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -25,7 +25,7 @@ Typedef
|
|||||||
Foam::floatScalar
|
Foam::floatScalar
|
||||||
|
|
||||||
Description
|
Description
|
||||||
Float precision floating point scalar type.
|
Floating-point single precision scalar type.
|
||||||
|
|
||||||
SourceFiles
|
SourceFiles
|
||||||
floatScalar.C
|
floatScalar.C
|
||||||
@ -48,7 +48,7 @@ namespace Foam
|
|||||||
|
|
||||||
typedef float floatScalar;
|
typedef float floatScalar;
|
||||||
|
|
||||||
// Largest and smallest scalar values allowed in certain parts of the code
|
// Largest and smallest scalar values allowed in certain parts of the code.
|
||||||
// (6 is the number of significant figures in an
|
// (6 is the number of significant figures in an
|
||||||
// IEEE single precision number. See limits.h or float.h)
|
// IEEE single precision number. See limits.h or float.h)
|
||||||
static const floatScalar floatScalarGREAT = 1.0e+6;
|
static const floatScalar floatScalarGREAT = 1.0e+6;
|
||||||
@ -59,48 +59,20 @@ static const floatScalar floatScalarROOTSMALL = 1.0e-3;
|
|||||||
static const floatScalar floatScalarVSMALL = 1.0e-37;
|
static const floatScalar floatScalarVSMALL = 1.0e-37;
|
||||||
static const floatScalar floatScalarROOTVSMALL = 1.0e-18;
|
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 Scalar floatScalar
|
||||||
#define ScalarVGREAT floatScalarVGREAT
|
#define ScalarVGREAT floatScalarVGREAT
|
||||||
#define ScalarVSMALL floatScalarVSMALL
|
#define ScalarVSMALL floatScalarVSMALL
|
||||||
#define ScalarROOTVGREAT floatScalarROOTVGREAT
|
#define ScalarROOTVGREAT floatScalarROOTVGREAT
|
||||||
#define ScalarROOTVSMALL floatScalarROOTVSMALL
|
#define ScalarROOTVSMALL floatScalarROOTVSMALL
|
||||||
#define readScalar readFloatScalar
|
#define ScalarRead readFloat
|
||||||
|
|
||||||
|
|
||||||
inline Scalar mag(const Scalar s)
|
inline Scalar mag(const Scalar s)
|
||||||
{
|
{
|
||||||
return ::fabsf(s);
|
return ::fabsf(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define transFunc(func) \
|
|
||||||
inline Scalar func(const Scalar s) \
|
|
||||||
{ \
|
|
||||||
return ::func##f(s); \
|
|
||||||
}
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
} // End namespace Foam
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
#include "Scalar.H"
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
namespace Foam
|
|
||||||
{
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
inline Scalar hypot(const Scalar x, const Scalar y)
|
inline Scalar hypot(const Scalar x, const Scalar y)
|
||||||
{
|
{
|
||||||
return ::hypotf(x, y);
|
return ::hypotf(x, y);
|
||||||
@ -121,19 +93,30 @@ inline Scalar yn(const int n, const Scalar s)
|
|||||||
return ::ynf(n, s);
|
return ::ynf(n, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef Scalar
|
// Single-precision transcendental functions (with 'f' appended to the name)
|
||||||
#undef ScalarVGREAT
|
#define transFunc(func) \
|
||||||
#undef ScalarVSMALL
|
inline Scalar func(const Scalar s) \
|
||||||
#undef ScalarROOTVGREAT
|
{ \
|
||||||
#undef ScalarROOTVSMALL
|
return ::func##f(s); \
|
||||||
#undef readScalar
|
}
|
||||||
#undef transFunc
|
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
} // End namespace Foam
|
} // End namespace Foam
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
#include "Scalar.H"
|
||||||
|
|
||||||
|
#undef Scalar
|
||||||
|
#undef ScalarVGREAT
|
||||||
|
#undef ScalarVSMALL
|
||||||
|
#undef ScalarROOTVGREAT
|
||||||
|
#undef ScalarROOTVSMALL
|
||||||
|
#undef ScalarRead
|
||||||
|
#undef transFunc
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -24,24 +24,17 @@ License
|
|||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include "scalar.H"
|
#include "scalar.H"
|
||||||
|
#include "IOstreams.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
|
||||||
|
|
||||||
namespace Foam
|
Foam::scalar Foam::readScalar(Istream& is)
|
||||||
{
|
{
|
||||||
|
scalar val;
|
||||||
|
is >> val;
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
return val;
|
||||||
|
|
||||||
scalar readScalar(Istream& is)
|
|
||||||
{
|
|
||||||
scalar rs;
|
|
||||||
is >> rs;
|
|
||||||
|
|
||||||
return rs;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
} // End namespace Foam
|
|
||||||
|
|
||||||
// ************************************************************************* //
|
// ************************************************************************* //
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -25,7 +25,7 @@ Typedef
|
|||||||
Foam::scalar
|
Foam::scalar
|
||||||
|
|
||||||
Description
|
Description
|
||||||
Single floating point number identical to float or double depending on
|
A floating-point number identical to float or double depending on
|
||||||
whether WM_SP or WM_DP is defined.
|
whether WM_SP or WM_DP is defined.
|
||||||
|
|
||||||
SourceFiles
|
SourceFiles
|
||||||
@ -58,6 +58,11 @@ namespace Foam
|
|||||||
static const scalar ROOTVSMALL = floatScalarROOTVSMALL;
|
static const scalar ROOTVSMALL = floatScalarROOTVSMALL;
|
||||||
|
|
||||||
scalar readScalar(Istream& is);
|
scalar readScalar(Istream& is);
|
||||||
|
|
||||||
|
inline scalar readScalar(const std::string& str)
|
||||||
|
{
|
||||||
|
return readFloat(str);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif defined(WM_DP)
|
#elif defined(WM_DP)
|
||||||
@ -77,6 +82,11 @@ namespace Foam
|
|||||||
static const scalar ROOTVSMALL = doubleScalarROOTVSMALL;
|
static const scalar ROOTVSMALL = doubleScalarROOTVSMALL;
|
||||||
|
|
||||||
scalar readScalar(Istream& is);
|
scalar readScalar(Istream& is);
|
||||||
|
|
||||||
|
inline scalar readScalar(const std::string& str)
|
||||||
|
{
|
||||||
|
return readDouble(str);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -43,7 +43,7 @@ Foam::label Foam::Function1Types::CSV<Foam::label>::readValue
|
|||||||
<< exit(FatalError);
|
<< exit(FatalError);
|
||||||
}
|
}
|
||||||
|
|
||||||
return readLabel(IStringStream(splitted[componentColumns_[0]])());
|
return readLabel(splitted[componentColumns_[0]]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -61,7 +61,7 @@ Foam::scalar Foam::Function1Types::CSV<Foam::scalar>::readValue
|
|||||||
<< exit(FatalError);
|
<< exit(FatalError);
|
||||||
}
|
}
|
||||||
|
|
||||||
return readScalar(IStringStream(splitted[componentColumns_[0]])());
|
return readScalar(splitted[componentColumns_[0]]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -70,7 +70,7 @@ Type Foam::Function1Types::CSV<Type>::readValue(const List<string>& splitted)
|
|||||||
{
|
{
|
||||||
Type result;
|
Type result;
|
||||||
|
|
||||||
for (label i = 0; i < pTraits<Type>::nComponents; i++)
|
for (label i = 0; i < pTraits<Type>::nComponents; ++i)
|
||||||
{
|
{
|
||||||
if (componentColumns_[i] >= splitted.size())
|
if (componentColumns_[i] >= splitted.size())
|
||||||
{
|
{
|
||||||
@ -80,8 +80,7 @@ Type Foam::Function1Types::CSV<Type>::readValue(const List<string>& splitted)
|
|||||||
<< exit(FatalError);
|
<< exit(FatalError);
|
||||||
}
|
}
|
||||||
|
|
||||||
result[i] =
|
result[i] = readScalar(splitted[componentColumns_[i]]);
|
||||||
readScalar(IStringStream(splitted[componentColumns_[i]])());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@ -189,7 +188,7 @@ void Foam::Function1Types::CSV<Type>::read()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
scalar x = readScalar(IStringStream(splitted[refColumn_])());
|
scalar x = readScalar(splitted[refColumn_]);
|
||||||
Type value = readValue(splitted);
|
Type value = readValue(splitted);
|
||||||
|
|
||||||
values.append(Tuple2<scalar,Type>(x, value));
|
values.append(Tuple2<scalar,Type>(x, value));
|
||||||
|
|||||||
@ -25,7 +25,7 @@ Primitive
|
|||||||
int
|
int
|
||||||
|
|
||||||
Description
|
Description
|
||||||
System integer
|
System signed integer
|
||||||
|
|
||||||
SourceFiles
|
SourceFiles
|
||||||
intIO.C
|
intIO.C
|
||||||
@ -67,7 +67,30 @@ MAXMIN(int64_t, int64_t, int64_t)
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
|
||||||
|
|
||||||
int readInt(Istream&);
|
//- Read int from stream
|
||||||
|
int readInt(Istream& is);
|
||||||
|
|
||||||
|
//- Parse entire buffer as an int, skipping leading/trailing whitespace.
|
||||||
|
// \return Parsed value or FatalIOError on any problem
|
||||||
|
int readInt(const char* buf);
|
||||||
|
|
||||||
|
//- Parse entire string as an int, skipping leading/trailing whitespace.
|
||||||
|
// \return Parsed value or FatalIOError on any problem
|
||||||
|
inline int readInt(const std::string& str)
|
||||||
|
{
|
||||||
|
return readInt(str.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
//- Read entire buffer as an int, skipping leading/trailing whitespace.
|
||||||
|
// \return True if successful.
|
||||||
|
bool readInt(const char* buf, int& val);
|
||||||
|
|
||||||
|
//- Read entire string as an int32_t, skipping leading/trailing whitespace.
|
||||||
|
// \return True if successful.
|
||||||
|
inline bool readInt(const std::string& str, int& val)
|
||||||
|
{
|
||||||
|
return readInt(str.c_str(), val);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -24,10 +24,68 @@ License
|
|||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include "int.H"
|
#include "int.H"
|
||||||
|
#include "error.H"
|
||||||
|
#include "parsing.H"
|
||||||
#include "IOstreams.H"
|
#include "IOstreams.H"
|
||||||
|
#include <cinttypes>
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
int Foam::readInt(const char* buf)
|
||||||
|
{
|
||||||
|
char *endptr = nullptr;
|
||||||
|
errno = 0;
|
||||||
|
const intmax_t parsed = ::strtoimax(buf, &endptr, 10);
|
||||||
|
|
||||||
|
const int val = int(parsed);
|
||||||
|
|
||||||
|
if (parsed < INT_MIN || parsed > INT_MAX)
|
||||||
|
{
|
||||||
|
// Range error
|
||||||
|
errno = ERANGE;
|
||||||
|
}
|
||||||
|
|
||||||
|
const parsing::errorType err = parsing::checkConversion(buf, endptr);
|
||||||
|
if (err != parsing::errorType::NONE)
|
||||||
|
{
|
||||||
|
FatalIOErrorInFunction("unknown")
|
||||||
|
<< parsing::errorNames[err] << " '" << buf << "'"
|
||||||
|
<< exit(FatalIOError);
|
||||||
|
}
|
||||||
|
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Foam::readInt(const char* buf, int& val)
|
||||||
|
{
|
||||||
|
char *endptr = nullptr;
|
||||||
|
errno = 0;
|
||||||
|
const intmax_t parsed = ::strtoimax(buf, &endptr, 10);
|
||||||
|
|
||||||
|
val = int(parsed);
|
||||||
|
|
||||||
|
if (parsed < INT_MIN || parsed > INT_MAX)
|
||||||
|
{
|
||||||
|
// Range error
|
||||||
|
errno = ERANGE;
|
||||||
|
}
|
||||||
|
|
||||||
|
const parsing::errorType err = parsing::checkConversion(buf, endptr);
|
||||||
|
if (err != parsing::errorType::NONE)
|
||||||
|
{
|
||||||
|
#ifdef FULLDEBUG
|
||||||
|
IOWarningInFunction("unknown")
|
||||||
|
<< parsing::errorNames[err] << " '" << buf << "'"
|
||||||
|
<< endl;
|
||||||
|
#endif
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int Foam::readInt(Istream& is)
|
int Foam::readInt(Istream& is)
|
||||||
{
|
{
|
||||||
int val;
|
int val;
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2014-2016 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2014-2016 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -24,6 +24,21 @@ License
|
|||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include "int32.H"
|
#include "int32.H"
|
||||||
|
#include "stringOps.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
Foam::word Foam::name(const char* fmt, const int32_t val)
|
||||||
|
{
|
||||||
|
return stringOps::name(fmt, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::word Foam::name(const std::string& fmt, const int32_t val)
|
||||||
|
{
|
||||||
|
return stringOps::name(fmt, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
@ -36,9 +51,9 @@ const int32_t Foam::pTraits<int32_t>::rootMax = pTraits<int32_t>::max;
|
|||||||
|
|
||||||
const char* const Foam::pTraits<int32_t>::componentNames[] = { "" };
|
const char* const Foam::pTraits<int32_t>::componentNames[] = { "" };
|
||||||
|
|
||||||
Foam::pTraits<int32_t>::pTraits(const int32_t& p)
|
Foam::pTraits<int32_t>::pTraits(const int32_t& val)
|
||||||
:
|
:
|
||||||
p_(p)
|
p_(val)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
Foam::pTraits<int32_t>::pTraits(Istream& is)
|
Foam::pTraits<int32_t>::pTraits(Istream& is)
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2014-2016 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2014-2016 OpenFOAM Foundation
|
||||||
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
\\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -22,10 +22,10 @@ License
|
|||||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
Primitive
|
Primitive
|
||||||
int32
|
int32_t
|
||||||
|
|
||||||
Description
|
Description
|
||||||
32bit integer
|
32bit signed integer
|
||||||
|
|
||||||
SourceFiles
|
SourceFiles
|
||||||
int32.C
|
int32.C
|
||||||
@ -57,34 +57,72 @@ class Ostream;
|
|||||||
//- Return a word representation of an int32
|
//- Return a word representation of an int32
|
||||||
inline word name(const int32_t val)
|
inline word name(const int32_t val)
|
||||||
{
|
{
|
||||||
// no stripping required
|
// No stripping required
|
||||||
return word(std::to_string(val), false);
|
return word(std::to_string(val), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//- Return a word representation of an int32, using printf-style formatter.
|
//- Return a word representation of an int32, using printf-style formatter.
|
||||||
// The representation is not checked for valid word characters.
|
// The representation is not checked for valid word characters.
|
||||||
word name(const char* fmt, const int32_t);
|
word name(const char* fmt, const int32_t val);
|
||||||
|
|
||||||
|
|
||||||
//- Return a word representation of an int32, using printf-style formatter.
|
//- Return a word representation of an int32, using printf-style formatter.
|
||||||
// The representation is not checked for valid word characters.
|
// The representation is not checked for valid word characters.
|
||||||
word name(const std::string&, const int32_t);
|
word name(const std::string&, const int32_t val);
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
|
||||||
|
|
||||||
int32_t readInt32(Istream&);
|
//- Read int32_t from stream
|
||||||
bool read(const char*, int32_t&);
|
int32_t readInt32(Istream& is);
|
||||||
Istream& operator>>(Istream&, int32_t&);
|
|
||||||
Ostream& operator<<(Ostream&, const int32_t);
|
//- Parse entire buffer as a int32_t, skipping leading/trailing whitespace.
|
||||||
|
// \return Parsed value or FatalIOError on any problem
|
||||||
|
int32_t readInt32(const char* buf);
|
||||||
|
|
||||||
|
//- Parse entire string as a int32_t, skipping leading/trailing whitespace.
|
||||||
|
// \return Parsed value or FatalIOError on any problem
|
||||||
|
inline int32_t readInt32(const std::string& str)
|
||||||
|
{
|
||||||
|
return readInt32(str.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
//- Read entire buffer as a int32_t, skipping leading/trailing whitespace.
|
||||||
|
// \return True if successful.
|
||||||
|
bool readInt32(const char* buf, int32_t& val);
|
||||||
|
|
||||||
|
//- Read entire string as a int32_t, skipping leading/trailing whitespace.
|
||||||
|
// \return True if successful.
|
||||||
|
inline bool readInt32(const std::string& str, int32_t& val)
|
||||||
|
{
|
||||||
|
return readInt32(str.c_str(), val);
|
||||||
|
}
|
||||||
|
|
||||||
|
//- Same as readInt32
|
||||||
|
// \return True if successful.
|
||||||
|
inline bool read(const char* buf, int32_t& val)
|
||||||
|
{
|
||||||
|
return readInt32(buf, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
//- Same as readInt32
|
||||||
|
// \return True if successful.
|
||||||
|
inline bool read(const std::string& str, int32_t& val)
|
||||||
|
{
|
||||||
|
return readInt32(str, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Istream& operator>>(Istream& is, int32_t& val);
|
||||||
|
Ostream& operator<<(Ostream& os, const int32_t val);
|
||||||
|
|
||||||
// On 32bit OSs long is not unambiguously int32_t (or int64_t) causing problems
|
// On 32bit OSs long is not unambiguously int32_t (or int64_t) causing problems
|
||||||
// for IO operator resolution.
|
// for IO operator resolution.
|
||||||
// This problem is avoided by explicitly defining the following operators:
|
// This problem is avoided by explicitly defining the following operators:
|
||||||
#if WM_ARCH_OPTION == 32
|
#if WM_ARCH_OPTION == 32
|
||||||
Istream& operator>>(Istream&, long&);
|
Istream& operator>>(Istream& is, long& val);
|
||||||
Ostream& operator<<(Ostream&, const long);
|
Ostream& operator<<(Ostream& os, const long val);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@ -127,10 +165,10 @@ public:
|
|||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
//- Construct from primitive
|
//- Construct from primitive
|
||||||
explicit pTraits(const int32_t&);
|
explicit pTraits(const int32_t& val);
|
||||||
|
|
||||||
//- Construct from Istream
|
//- Construct from Istream
|
||||||
pTraits(Istream&);
|
pTraits(Istream& is);
|
||||||
|
|
||||||
|
|
||||||
// Member Functions
|
// Member Functions
|
||||||
@ -149,9 +187,9 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
inline int32_t mag(const int32_t l)
|
inline int32_t mag(const int32_t val)
|
||||||
{
|
{
|
||||||
return ::abs(l);
|
return ::abs(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2014-2016 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2014-2016 OpenFOAM Foundation
|
||||||
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
\\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -24,29 +24,69 @@ License
|
|||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include "int32.H"
|
#include "int32.H"
|
||||||
#include "stringOps.H"
|
#include "error.H"
|
||||||
|
#include "parsing.H"
|
||||||
#include "IOstreams.H"
|
#include "IOstreams.H"
|
||||||
|
#include <cinttypes>
|
||||||
#include <inttypes.h>
|
|
||||||
#include <cerrno>
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
Foam::word Foam::name(const char* fmt, const int32_t val)
|
|
||||||
{
|
|
||||||
return stringOps::name(fmt, val);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Foam::word Foam::name(const std::string& fmt, const int32_t val)
|
|
||||||
{
|
|
||||||
return stringOps::name(fmt, val);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
|
||||||
|
|
||||||
Foam::Istream& Foam::operator>>(Istream& is, int32_t& i)
|
int32_t Foam::readInt32(const char* buf)
|
||||||
|
{
|
||||||
|
char *endptr = nullptr;
|
||||||
|
errno = 0;
|
||||||
|
const intmax_t parsed = ::strtoimax(buf, &endptr, 10);
|
||||||
|
|
||||||
|
const int32_t val = int32_t(parsed);
|
||||||
|
|
||||||
|
if (parsed < INT32_MIN || parsed > INT32_MAX)
|
||||||
|
{
|
||||||
|
// Range error
|
||||||
|
errno = ERANGE;
|
||||||
|
}
|
||||||
|
|
||||||
|
const parsing::errorType err = parsing::checkConversion(buf, endptr);
|
||||||
|
if (err != parsing::errorType::NONE)
|
||||||
|
{
|
||||||
|
FatalIOErrorInFunction("unknown")
|
||||||
|
<< parsing::errorNames[err] << " '" << buf << "'"
|
||||||
|
<< exit(FatalIOError);
|
||||||
|
}
|
||||||
|
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Foam::readInt32(const char* buf, int32_t& val)
|
||||||
|
{
|
||||||
|
char *endptr = nullptr;
|
||||||
|
errno = 0;
|
||||||
|
const intmax_t parsed = ::strtoimax(buf, &endptr, 10);
|
||||||
|
|
||||||
|
val = int32_t(parsed);
|
||||||
|
|
||||||
|
if (parsed < INT32_MIN || parsed > INT32_MAX)
|
||||||
|
{
|
||||||
|
// Range error
|
||||||
|
errno = ERANGE;
|
||||||
|
}
|
||||||
|
|
||||||
|
const parsing::errorType err = parsing::checkConversion(buf, endptr);
|
||||||
|
if (err != parsing::errorType::NONE)
|
||||||
|
{
|
||||||
|
#ifdef FULLDEBUG
|
||||||
|
IOWarningInFunction("unknown")
|
||||||
|
<< parsing::errorNames[err] << " '" << buf << "'"
|
||||||
|
<< endl;
|
||||||
|
#endif
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::Istream& Foam::operator>>(Istream& is, int32_t& val)
|
||||||
{
|
{
|
||||||
token t(is);
|
token t(is);
|
||||||
|
|
||||||
@ -58,7 +98,7 @@ Foam::Istream& Foam::operator>>(Istream& is, int32_t& i)
|
|||||||
|
|
||||||
if (t.isLabel())
|
if (t.isLabel())
|
||||||
{
|
{
|
||||||
i = int32_t(t.labelToken());
|
val = int32_t(t.labelToken());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -84,35 +124,23 @@ int32_t Foam::readInt32(Istream& is)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Foam::read(const char* buf, int32_t& s)
|
Foam::Ostream& Foam::operator<<(Ostream& os, const int32_t val)
|
||||||
{
|
{
|
||||||
char *endptr = nullptr;
|
os.write(label(val));
|
||||||
errno = 0;
|
|
||||||
intmax_t l = strtoimax(buf, &endptr, 10);
|
|
||||||
s = int32_t(l);
|
|
||||||
return
|
|
||||||
(*endptr == 0) && (errno == 0)
|
|
||||||
&& (l >= INT32_MIN) && (l <= INT32_MAX);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Foam::Ostream& Foam::operator<<(Ostream& os, const int32_t i)
|
|
||||||
{
|
|
||||||
os.write(label(i));
|
|
||||||
os.check(FUNCTION_NAME);
|
os.check(FUNCTION_NAME);
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if WM_ARCH_OPTION == 32
|
#if WM_ARCH_OPTION == 32
|
||||||
Foam::Istream& Foam::operator>>(Istream& is, long& i)
|
Foam::Istream& Foam::operator>>(Istream& is, long& val)
|
||||||
{
|
{
|
||||||
return operator>>(is, reinterpret_cast<int32_t&>(i));
|
return operator>>(is, reinterpret_cast<int32_t&>(val));
|
||||||
}
|
}
|
||||||
|
|
||||||
Foam::Ostream& Foam::operator<<(Ostream& os, const long i)
|
Foam::Ostream& Foam::operator<<(Ostream& os, const long val)
|
||||||
{
|
{
|
||||||
os << int32_t(i);
|
os << int32_t(val);
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2014-2016 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2014-2016 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -24,6 +24,21 @@ License
|
|||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include "int64.H"
|
#include "int64.H"
|
||||||
|
#include "stringOps.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
Foam::word Foam::name(const char* fmt, const int64_t val)
|
||||||
|
{
|
||||||
|
return stringOps::name(fmt, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::word Foam::name(const std::string& fmt, const int64_t val)
|
||||||
|
{
|
||||||
|
return stringOps::name(fmt, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
@ -36,9 +51,9 @@ const int64_t Foam::pTraits<int64_t>::rootMax = pTraits<int64_t>::max;
|
|||||||
|
|
||||||
const char* const Foam::pTraits<int64_t>::componentNames[] = { "" };
|
const char* const Foam::pTraits<int64_t>::componentNames[] = { "" };
|
||||||
|
|
||||||
Foam::pTraits<int64_t>::pTraits(const int64_t& p)
|
Foam::pTraits<int64_t>::pTraits(const int64_t& val)
|
||||||
:
|
:
|
||||||
p_(p)
|
p_(val)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
Foam::pTraits<int64_t>::pTraits(Istream& is)
|
Foam::pTraits<int64_t>::pTraits(Istream& is)
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2014-2016 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2014-2016 OpenFOAM Foundation
|
||||||
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
\\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -22,10 +22,10 @@ License
|
|||||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
Primitive
|
Primitive
|
||||||
int64
|
int64_t
|
||||||
|
|
||||||
Description
|
Description
|
||||||
64bit integer
|
64bit signed integer
|
||||||
|
|
||||||
SourceFiles
|
SourceFiles
|
||||||
int64.C
|
int64.C
|
||||||
@ -58,7 +58,7 @@ class Ostream;
|
|||||||
//- Return a word representation of an int64
|
//- Return a word representation of an int64
|
||||||
inline word name(const int64_t val)
|
inline word name(const int64_t val)
|
||||||
{
|
{
|
||||||
// no stripping required
|
// No stripping required
|
||||||
return word(std::to_string(val), false);
|
return word(std::to_string(val), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,10 +75,48 @@ word name(const std::string& fmt, const int64_t);
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
|
||||||
|
|
||||||
int64_t readInt64(Istream&);
|
//- Read int64_t from stream
|
||||||
bool read(const char*, int64_t&);
|
int64_t readInt64(Istream& is);
|
||||||
Istream& operator>>(Istream&, int64_t&);
|
|
||||||
Ostream& operator<<(Ostream&, const int64_t);
|
//- Parse entire buffer as a int64_t, skipping leading/trailing whitespace.
|
||||||
|
// \return Parsed value or FatalIOError on any problem
|
||||||
|
int64_t readInt64(const char* buf);
|
||||||
|
|
||||||
|
//- Parse entire string as a int64_t, skipping leading/trailing whitespace.
|
||||||
|
// \return Parsed value or FatalIOError on any problem
|
||||||
|
inline int64_t readInt64(const std::string& str)
|
||||||
|
{
|
||||||
|
return readInt64(str.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
//- Read entire buffer as a int64_t, skipping leading/trailing whitespace.
|
||||||
|
// \return True if successful.
|
||||||
|
bool readInt64(const char* buf, int64_t& val);
|
||||||
|
|
||||||
|
//- Read entire string as a int64_t, skipping leading/trailing whitespace.
|
||||||
|
// \return True if successful.
|
||||||
|
inline bool readInt64(const std::string& str, int64_t& val)
|
||||||
|
{
|
||||||
|
return readInt64(str.c_str(), val);
|
||||||
|
}
|
||||||
|
|
||||||
|
//- Same as readInt64
|
||||||
|
// \return True if successful.
|
||||||
|
inline bool read(const char* buf, int64_t& val)
|
||||||
|
{
|
||||||
|
return readInt64(buf, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
//- Same as readInt64
|
||||||
|
// \return True if successful.
|
||||||
|
inline bool read(const std::string& str, int64_t& val)
|
||||||
|
{
|
||||||
|
return readInt64(str, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Istream& operator>>(Istream& is, int64_t& val);
|
||||||
|
Ostream& operator<<(Ostream& os, const int64_t val);
|
||||||
|
|
||||||
//- Template specialization for pTraits<int64_t>
|
//- Template specialization for pTraits<int64_t>
|
||||||
template<>
|
template<>
|
||||||
@ -119,10 +157,10 @@ public:
|
|||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
//- Construct from primitive
|
//- Construct from primitive
|
||||||
explicit pTraits(const int64_t&);
|
explicit pTraits(const int64_t& val);
|
||||||
|
|
||||||
//- Construct from Istream
|
//- Construct from Istream
|
||||||
pTraits(Istream&);
|
pTraits(Istream& is);
|
||||||
|
|
||||||
|
|
||||||
// Member Functions
|
// Member Functions
|
||||||
@ -141,9 +179,9 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
inline int64_t mag(const int64_t l)
|
inline int64_t mag(const int64_t val)
|
||||||
{
|
{
|
||||||
return ::labs(l);
|
return ::labs(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2014-2016 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2014-2016 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -24,29 +24,69 @@ License
|
|||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include "int64.H"
|
#include "int64.H"
|
||||||
#include "stringOps.H"
|
#include "error.H"
|
||||||
|
#include "parsing.H"
|
||||||
#include "IOstreams.H"
|
#include "IOstreams.H"
|
||||||
|
#include <cinttypes>
|
||||||
#include <inttypes.h>
|
|
||||||
#include <cerrno>
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
Foam::word Foam::name(const char* fmt, const int64_t val)
|
|
||||||
{
|
|
||||||
return stringOps::name(fmt, val);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Foam::word Foam::name(const std::string& fmt, const int64_t val)
|
|
||||||
{
|
|
||||||
return stringOps::name(fmt, val);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
|
||||||
|
|
||||||
Foam::Istream& Foam::operator>>(Istream& is, int64_t& i)
|
int64_t Foam::readInt64(const char* buf)
|
||||||
|
{
|
||||||
|
char *endptr = nullptr;
|
||||||
|
errno = 0;
|
||||||
|
const intmax_t parsed = ::strtoimax(buf, &endptr, 10);
|
||||||
|
|
||||||
|
const int64_t val = int64_t(parsed);
|
||||||
|
|
||||||
|
if (parsed < INT64_MIN || parsed > INT64_MAX)
|
||||||
|
{
|
||||||
|
// Range error
|
||||||
|
errno = ERANGE;
|
||||||
|
}
|
||||||
|
|
||||||
|
const parsing::errorType err = parsing::checkConversion(buf, endptr);
|
||||||
|
if (err != parsing::errorType::NONE)
|
||||||
|
{
|
||||||
|
FatalIOErrorInFunction("unknown")
|
||||||
|
<< parsing::errorNames[err] << " '" << buf << "'"
|
||||||
|
<< exit(FatalIOError);
|
||||||
|
}
|
||||||
|
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Foam::readInt64(const char* buf, int64_t& val)
|
||||||
|
{
|
||||||
|
char *endptr = nullptr;
|
||||||
|
errno = 0;
|
||||||
|
const intmax_t parsed = ::strtoimax(buf, &endptr, 10);
|
||||||
|
|
||||||
|
val = int64_t(parsed);
|
||||||
|
|
||||||
|
if (parsed < INT64_MIN || parsed > INT64_MAX)
|
||||||
|
{
|
||||||
|
// Range error
|
||||||
|
errno = ERANGE;
|
||||||
|
}
|
||||||
|
|
||||||
|
const parsing::errorType err = parsing::checkConversion(buf, endptr);
|
||||||
|
if (err != parsing::errorType::NONE)
|
||||||
|
{
|
||||||
|
#ifdef FULLDEBUG
|
||||||
|
IOWarningInFunction("unknown")
|
||||||
|
<< parsing::errorNames[err] << " '" << buf << "'"
|
||||||
|
<< endl;
|
||||||
|
#endif
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::Istream& Foam::operator>>(Istream& is, int64_t& val)
|
||||||
{
|
{
|
||||||
token t(is);
|
token t(is);
|
||||||
|
|
||||||
@ -58,7 +98,7 @@ Foam::Istream& Foam::operator>>(Istream& is, int64_t& i)
|
|||||||
|
|
||||||
if (t.isLabel())
|
if (t.isLabel())
|
||||||
{
|
{
|
||||||
i = int64_t(t.labelToken());
|
val = int64_t(t.labelToken());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -84,19 +124,9 @@ int64_t Foam::readInt64(Istream& is)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Foam::read(const char* buf, int64_t& s)
|
Foam::Ostream& Foam::operator<<(Ostream& os, const int64_t val)
|
||||||
{
|
{
|
||||||
char *endptr = nullptr;
|
os.write(label(val));
|
||||||
errno = 0;
|
|
||||||
intmax_t l = strtoimax(buf, &endptr, 10);
|
|
||||||
s = int64_t(l);
|
|
||||||
return (*endptr == 0) && (errno == 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Foam::Ostream& Foam::operator<<(Ostream& os, const int64_t i)
|
|
||||||
{
|
|
||||||
os.write(label(i));
|
|
||||||
os.check(FUNCTION_NAME);
|
os.check(FUNCTION_NAME);
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -61,11 +61,45 @@ typedef INT_SIZE(int, _t) label;
|
|||||||
static const label labelMin = INT_SIZE(INT, _MIN);
|
static const label labelMin = INT_SIZE(INT, _MIN);
|
||||||
static const label labelMax = INT_SIZE(INT, _MAX);
|
static const label labelMax = INT_SIZE(INT, _MAX);
|
||||||
|
|
||||||
|
//- Read label from stream.
|
||||||
|
// Uses readInt32 or readInt64 according to WM_LABEL_SIZE
|
||||||
inline label readLabel(Istream& is)
|
inline label readLabel(Istream& is)
|
||||||
{
|
{
|
||||||
return INT_SIZE(readInt,) (is);
|
return INT_SIZE(readInt,) (is);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//- Parse entire buffer as a label, skipping leading/trailing whitespace.
|
||||||
|
// Uses readInt32 or readInt64 according to WM_LABEL_SIZE
|
||||||
|
// \return Parsed value or FatalIOError on any problem
|
||||||
|
inline label readLabel(const char* buf)
|
||||||
|
{
|
||||||
|
return INT_SIZE(readInt,) (buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
//- Parse entire string as a label, skipping leading/trailing whitespace.
|
||||||
|
// Uses readInt32 or readInt64 according to WM_LABEL_SIZE
|
||||||
|
// \return Parsed value or FatalIOError on any problem
|
||||||
|
inline label readLabel(const std::string& str)
|
||||||
|
{
|
||||||
|
return INT_SIZE(readInt,) (str);
|
||||||
|
}
|
||||||
|
|
||||||
|
//- Parse entire buffer as a label, skipping leading/trailing whitespace.
|
||||||
|
// Uses readInt32 or readInt64 according to WM_LABEL_SIZE
|
||||||
|
// \return True if successful.
|
||||||
|
inline bool readLabel(const char* buf, label& val)
|
||||||
|
{
|
||||||
|
return INT_SIZE(readInt,) (buf, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
//- Parse entire string as a label, skipping leading/trailing whitespace.
|
||||||
|
// Uses readInt32 or readInt64 according to WM_LABEL_SIZE
|
||||||
|
// \return True if successful.
|
||||||
|
inline bool readLabel(const std::string& str, label& val)
|
||||||
|
{
|
||||||
|
return INT_SIZE(readInt,) (str, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -28,7 +28,7 @@ Description
|
|||||||
A uLabel is an uint32_t or uint64_t as specified by the pre-processor macro
|
A uLabel is an uint32_t or uint64_t as specified by the pre-processor macro
|
||||||
WM_LABEL_SIZE.
|
WM_LABEL_SIZE.
|
||||||
|
|
||||||
A readLabel function is defined so that uLabel can be constructed from
|
A readULabel function is defined so that uLabel can be constructed from
|
||||||
Istream.
|
Istream.
|
||||||
|
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
@ -60,11 +60,46 @@ typedef UINT_SIZE(uint, _t) uLabel;
|
|||||||
|
|
||||||
static const uLabel uLabelMax = UINT_SIZE(UINT, _MAX);
|
static const uLabel uLabelMax = UINT_SIZE(UINT, _MAX);
|
||||||
|
|
||||||
|
//- Read uLabel from stream.
|
||||||
|
// Uses readUint32 or readUint64 according to WM_LABEL_SIZE
|
||||||
inline uLabel readULabel(Istream& is)
|
inline uLabel readULabel(Istream& is)
|
||||||
{
|
{
|
||||||
return UINT_SIZE(readUint,) (is);
|
return UINT_SIZE(readUint,) (is);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//- Parse entire buffer as a uLabel, skipping leading/trailing whitespace.
|
||||||
|
// Uses readUint32 or readUint64 according to WM_LABEL_SIZE
|
||||||
|
// \return Parsed value or FatalIOError on any problem
|
||||||
|
inline uLabel readULabel(const char* buf)
|
||||||
|
{
|
||||||
|
return UINT_SIZE(readUint,) (buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
//- Parse entire string as a uLabel, skipping leading/trailing whitespace.
|
||||||
|
// Uses readUint32 or readUint64 according to WM_LABEL_SIZE
|
||||||
|
// \return Parsed value or FatalIOError on any problem
|
||||||
|
inline uLabel readULabel(const std::string& str)
|
||||||
|
{
|
||||||
|
return UINT_SIZE(readUint,) (str);
|
||||||
|
}
|
||||||
|
|
||||||
|
//- Parse entire buffer as a uLabel, skipping leading/trailing whitespace.
|
||||||
|
// Uses readUint32 or readUint64 according to WM_LABEL_SIZE
|
||||||
|
// \return True if successful.
|
||||||
|
inline bool readULabel(const char* buf, uLabel& val)
|
||||||
|
{
|
||||||
|
return UINT_SIZE(readUint,) (buf, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//- Parse entire string as a uLabel, skipping leading/trailing whitespace.
|
||||||
|
// Uses readUint32 or readUint64 according to WM_LABEL_SIZE
|
||||||
|
// \return True if successful.
|
||||||
|
inline bool readULabel(const std::string& str, uLabel& val)
|
||||||
|
{
|
||||||
|
return UINT_SIZE(readUint,) (str, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
|||||||
@ -25,7 +25,7 @@ Primitive
|
|||||||
uint
|
uint
|
||||||
|
|
||||||
Description
|
Description
|
||||||
System uinteger
|
System unsigned integer
|
||||||
|
|
||||||
SourceFiles
|
SourceFiles
|
||||||
uintIO.C
|
uintIO.C
|
||||||
@ -67,7 +67,8 @@ MAXMIN(uint64_t, uint64_t, uint64_t)
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
|
||||||
|
|
||||||
unsigned int readUint(Istream&);
|
//- Read unsigned int from stream
|
||||||
|
unsigned int readUint(Istream& is);
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2014-2016 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2014-2016 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -24,6 +24,21 @@ License
|
|||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include "uint32.H"
|
#include "uint32.H"
|
||||||
|
#include "stringOps.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
Foam::word Foam::name(const char* fmt, const uint32_t val)
|
||||||
|
{
|
||||||
|
return stringOps::name(fmt, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::word Foam::name(const std::string& fmt, const uint32_t val)
|
||||||
|
{
|
||||||
|
return stringOps::name(fmt, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
@ -36,9 +51,9 @@ const uint32_t Foam::pTraits<uint32_t>::rootMax = pTraits<uint32_t>::max;
|
|||||||
|
|
||||||
const char* const Foam::pTraits<uint32_t>::componentNames[] = { "" };
|
const char* const Foam::pTraits<uint32_t>::componentNames[] = { "" };
|
||||||
|
|
||||||
Foam::pTraits<uint32_t>::pTraits(const uint32_t& p)
|
Foam::pTraits<uint32_t>::pTraits(const uint32_t& val)
|
||||||
:
|
:
|
||||||
p_(p)
|
p_(val)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
Foam::pTraits<uint32_t>::pTraits(Istream& is)
|
Foam::pTraits<uint32_t>::pTraits(Istream& is)
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2014-2016 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2014-2016 OpenFOAM Foundation
|
||||||
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
\\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -22,10 +22,10 @@ License
|
|||||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
Primitive
|
Primitive
|
||||||
uint32
|
uint32_t
|
||||||
|
|
||||||
Description
|
Description
|
||||||
32bit uinteger
|
32bit unsigned integer
|
||||||
|
|
||||||
SourceFiles
|
SourceFiles
|
||||||
uint32.C
|
uint32.C
|
||||||
@ -57,7 +57,7 @@ class Ostream;
|
|||||||
//- Return a word representation of a uint32
|
//- Return a word representation of a uint32
|
||||||
inline word name(const uint32_t val)
|
inline word name(const uint32_t val)
|
||||||
{
|
{
|
||||||
// no stripping required
|
// No stripping required
|
||||||
return word(std::to_string(val), false);
|
return word(std::to_string(val), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,10 +74,48 @@ word name(const std::string& fmt, const uint32_t);
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
|
||||||
|
|
||||||
uint32_t readUint32(Istream&);
|
//- Read uint32_t from stream
|
||||||
bool read(const char*, uint32_t&);
|
uint32_t readUint32(Istream& is);
|
||||||
Istream& operator>>(Istream&, uint32_t&);
|
|
||||||
Ostream& operator<<(Ostream&, const uint32_t);
|
//- Parse entire buffer as a uint32_t, skipping leading/trailing whitespace.
|
||||||
|
// \return Parsed value or FatalIOError on any problem
|
||||||
|
uint32_t readUint32(const char* buf);
|
||||||
|
|
||||||
|
//- Parse entire string as a uint32_t, skipping leading/trailing whitespace.
|
||||||
|
// \return Parsed value or FatalIOError on any problem
|
||||||
|
inline uint32_t readUint32(const std::string& str)
|
||||||
|
{
|
||||||
|
return readUint32(str.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
//- Read entire buffer as a uint32_t, skipping leading/trailing whitespace.
|
||||||
|
// \return True if successful.
|
||||||
|
bool readUint32(const char* buf, uint32_t& val);
|
||||||
|
|
||||||
|
//- Read entire string as a uint32_t, skipping leading/trailing whitespace.
|
||||||
|
// \return True if successful.
|
||||||
|
inline bool readUint32(const std::string& str, uint32_t& val)
|
||||||
|
{
|
||||||
|
return readUint32(str.c_str(), val);
|
||||||
|
}
|
||||||
|
|
||||||
|
//- Same as readUint32
|
||||||
|
// \return True if successful.
|
||||||
|
inline bool read(const char* buf, uint32_t& val)
|
||||||
|
{
|
||||||
|
return readUint32(buf, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
//- Same as readUint32
|
||||||
|
// \return True if successful.
|
||||||
|
inline bool read(const std::string& str, uint32_t& val)
|
||||||
|
{
|
||||||
|
return readUint32(str, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Istream& operator>>(Istream& is, uint32_t& val);
|
||||||
|
Ostream& operator<<(Ostream& os, const uint32_t val);
|
||||||
|
|
||||||
//- Template specialization for pTraits<uint32_t>
|
//- Template specialization for pTraits<uint32_t>
|
||||||
template<>
|
template<>
|
||||||
@ -118,10 +156,10 @@ public:
|
|||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
//- Construct from primitive
|
//- Construct from primitive
|
||||||
explicit pTraits(const uint32_t&);
|
explicit pTraits(const uint32_t& val);
|
||||||
|
|
||||||
//- Construct from Istream
|
//- Construct from Istream
|
||||||
pTraits(Istream&);
|
pTraits(Istream& is);
|
||||||
|
|
||||||
|
|
||||||
// Member Functions
|
// Member Functions
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2014-2016 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2014-2016 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -24,26 +24,68 @@ License
|
|||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include "uint32.H"
|
#include "uint32.H"
|
||||||
#include "stringOps.H"
|
#include "parsing.H"
|
||||||
#include "IOstreams.H"
|
#include "IOstreams.H"
|
||||||
|
#include <cinttypes>
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
Foam::word Foam::name(const char* fmt, const uint32_t val)
|
|
||||||
{
|
|
||||||
return stringOps::name(fmt, val);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Foam::word Foam::name(const std::string& fmt, const uint32_t val)
|
|
||||||
{
|
|
||||||
return stringOps::name(fmt, val);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
|
||||||
|
|
||||||
Foam::Istream& Foam::operator>>(Istream& is, uint32_t& i)
|
uint32_t Foam::readUint32(const char* buf)
|
||||||
|
{
|
||||||
|
char *endptr = nullptr;
|
||||||
|
errno = 0;
|
||||||
|
const uintmax_t parsed = ::strtoumax(buf, &endptr, 10);
|
||||||
|
|
||||||
|
const uint32_t val = uint32_t(parsed);
|
||||||
|
|
||||||
|
if (parsed > UINT32_MAX)
|
||||||
|
{
|
||||||
|
// Range error
|
||||||
|
errno = ERANGE;
|
||||||
|
}
|
||||||
|
|
||||||
|
const parsing::errorType err = parsing::checkConversion(buf, endptr);
|
||||||
|
if (err != parsing::errorType::NONE)
|
||||||
|
{
|
||||||
|
FatalIOErrorInFunction("unknown")
|
||||||
|
<< parsing::errorNames[err] << " '" << buf << "'"
|
||||||
|
<< exit(FatalIOError);
|
||||||
|
}
|
||||||
|
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Foam::readUint32(const char* buf, uint32_t& val)
|
||||||
|
{
|
||||||
|
char *endptr = nullptr;
|
||||||
|
errno = 0;
|
||||||
|
const uintmax_t parsed = ::strtoumax(buf, &endptr, 10);
|
||||||
|
|
||||||
|
val = uint32_t(parsed);
|
||||||
|
|
||||||
|
if (parsed > UINT32_MAX)
|
||||||
|
{
|
||||||
|
// Range error
|
||||||
|
errno = ERANGE;
|
||||||
|
}
|
||||||
|
|
||||||
|
const parsing::errorType err = parsing::checkConversion(buf, endptr);
|
||||||
|
if (err != parsing::errorType::NONE)
|
||||||
|
{
|
||||||
|
#ifdef FULLDEBUG
|
||||||
|
IOWarningInFunction("unknown")
|
||||||
|
<< parsing::errorNames[err] << " '" << buf << "'"
|
||||||
|
<< endl;
|
||||||
|
#endif
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::Istream& Foam::operator>>(Istream& is, uint32_t& val)
|
||||||
{
|
{
|
||||||
token t(is);
|
token t(is);
|
||||||
|
|
||||||
@ -55,7 +97,7 @@ Foam::Istream& Foam::operator>>(Istream& is, uint32_t& i)
|
|||||||
|
|
||||||
if (t.isLabel())
|
if (t.isLabel())
|
||||||
{
|
{
|
||||||
i = uint32_t(t.labelToken());
|
val = uint32_t(t.labelToken());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -81,18 +123,9 @@ uint32_t Foam::readUint32(Istream& is)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Foam::read(const char* buf, uint32_t& s)
|
Foam::Ostream& Foam::operator<<(Ostream& os, const uint32_t val)
|
||||||
{
|
{
|
||||||
char *endptr = nullptr;
|
os.write(label(val));
|
||||||
long l = strtol(buf, &endptr, 10);
|
|
||||||
s = uint32_t(l);
|
|
||||||
return (*endptr == 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Foam::Ostream& Foam::operator<<(Ostream& os, const uint32_t i)
|
|
||||||
{
|
|
||||||
os.write(label(i));
|
|
||||||
os.check(FUNCTION_NAME);
|
os.check(FUNCTION_NAME);
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2014-2016 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2014-2016 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -24,6 +24,21 @@ License
|
|||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include "uint64.H"
|
#include "uint64.H"
|
||||||
|
#include "stringOps.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
Foam::word Foam::name(const char* fmt, const uint64_t val)
|
||||||
|
{
|
||||||
|
return stringOps::name(fmt, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::word Foam::name(const std::string& fmt, const uint64_t val)
|
||||||
|
{
|
||||||
|
return stringOps::name(fmt, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
@ -36,9 +51,9 @@ const uint64_t Foam::pTraits<uint64_t>::rootMax = pTraits<uint64_t>::max;
|
|||||||
|
|
||||||
const char* const Foam::pTraits<uint64_t>::componentNames[] = { "" };
|
const char* const Foam::pTraits<uint64_t>::componentNames[] = { "" };
|
||||||
|
|
||||||
Foam::pTraits<uint64_t>::pTraits(const uint64_t& p)
|
Foam::pTraits<uint64_t>::pTraits(const uint64_t& val)
|
||||||
:
|
:
|
||||||
p_(p)
|
p_(val)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
Foam::pTraits<uint64_t>::pTraits(Istream& is)
|
Foam::pTraits<uint64_t>::pTraits(Istream& is)
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2014-2016 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2014-2016 OpenFOAM Foundation
|
||||||
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
\\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -22,10 +22,10 @@ License
|
|||||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
Primitive
|
Primitive
|
||||||
uint64
|
uint64_t
|
||||||
|
|
||||||
Description
|
Description
|
||||||
64bit uinteger
|
64bit unsigned integer
|
||||||
|
|
||||||
SourceFiles
|
SourceFiles
|
||||||
uint64.C
|
uint64.C
|
||||||
@ -44,7 +44,6 @@ SourceFiles
|
|||||||
#include "pTraits.H"
|
#include "pTraits.H"
|
||||||
#include "direction.H"
|
#include "direction.H"
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
namespace Foam
|
namespace Foam
|
||||||
@ -58,7 +57,7 @@ class Ostream;
|
|||||||
//- Return a word representation of a uint64
|
//- Return a word representation of a uint64
|
||||||
inline word name(const uint64_t val)
|
inline word name(const uint64_t val)
|
||||||
{
|
{
|
||||||
// no stripping required
|
// No stripping required
|
||||||
return word(std::to_string(val), false);
|
return word(std::to_string(val), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,10 +74,48 @@ word name(const std::string& fmt, const uint64_t);
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
|
||||||
|
|
||||||
uint64_t readUint64(Istream&);
|
//- Read uint64_t from stream.
|
||||||
bool read(const char*, uint64_t&);
|
uint64_t readUint64(Istream& is);
|
||||||
Istream& operator>>(Istream&, uint64_t&);
|
|
||||||
Ostream& operator<<(Ostream&, const uint64_t);
|
//- Parse entire buffer as uint64_t, skipping leading/trailing whitespace.
|
||||||
|
// \return Parsed value or FatalIOError on any problem
|
||||||
|
uint64_t readUint64(const char* buf);
|
||||||
|
|
||||||
|
//- Parse entire string as uint64_t, skipping leading/trailing whitespace.
|
||||||
|
// \return Parsed value or FatalIOError on any problem
|
||||||
|
inline uint64_t readUint64(const std::string& str)
|
||||||
|
{
|
||||||
|
return readUint64(str.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
//- Parse entire buffer as uint64_t, skipping leading/trailing whitespace.
|
||||||
|
// \return True if successful.
|
||||||
|
bool readUint64(const char* buf, uint64_t& val);
|
||||||
|
|
||||||
|
//- Parse entire string as uint64_t, skipping leading/trailing whitespace.
|
||||||
|
// \return True if successful.
|
||||||
|
inline bool readUint64(const std::string& str, uint64_t& val)
|
||||||
|
{
|
||||||
|
return readUint64(str.c_str(), val);
|
||||||
|
}
|
||||||
|
|
||||||
|
//- Same as readUint64
|
||||||
|
// \return True if successful.
|
||||||
|
inline bool read(const char* buf, uint64_t& val)
|
||||||
|
{
|
||||||
|
return readUint64(buf, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
//- Same as readUint64
|
||||||
|
// \return True if successful.
|
||||||
|
inline bool read(const std::string& str, uint64_t& val)
|
||||||
|
{
|
||||||
|
return readUint64(str, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Istream& operator>>(Istream& is, uint64_t& val);
|
||||||
|
Ostream& operator<<(Ostream& os, const uint64_t val);
|
||||||
|
|
||||||
//- Template specialization for pTraits<uint64_t>
|
//- Template specialization for pTraits<uint64_t>
|
||||||
template<>
|
template<>
|
||||||
@ -119,10 +156,10 @@ public:
|
|||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
//- Construct from primitive
|
//- Construct from primitive
|
||||||
explicit pTraits(const uint64_t&);
|
explicit pTraits(const uint64_t& val);
|
||||||
|
|
||||||
//- Construct from Istream
|
//- Construct from Istream
|
||||||
pTraits(Istream&);
|
pTraits(Istream& is);
|
||||||
|
|
||||||
|
|
||||||
// Member Functions
|
// Member Functions
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2014-2016 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2014-2016 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -24,26 +24,68 @@ License
|
|||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include "uint64.H"
|
#include "uint64.H"
|
||||||
#include "stringOps.H"
|
#include "parsing.H"
|
||||||
#include "IOstreams.H"
|
#include "IOstreams.H"
|
||||||
|
#include <cinttypes>
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
Foam::word Foam::name(const char* fmt, const uint64_t val)
|
|
||||||
{
|
|
||||||
return stringOps::name(fmt, val);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Foam::word Foam::name(const std::string& fmt, const uint64_t val)
|
|
||||||
{
|
|
||||||
return stringOps::name(fmt, val);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
|
||||||
|
|
||||||
Foam::Istream& Foam::operator>>(Istream& is, uint64_t& i)
|
uint64_t Foam::readUint64(const char* buf)
|
||||||
|
{
|
||||||
|
char *endptr = nullptr;
|
||||||
|
errno = 0;
|
||||||
|
const uintmax_t parsed = ::strtoumax(buf, &endptr, 10);
|
||||||
|
|
||||||
|
const uint64_t val = uint64_t(parsed);
|
||||||
|
|
||||||
|
if (parsed > UINT64_MAX)
|
||||||
|
{
|
||||||
|
// Range error
|
||||||
|
errno = ERANGE;
|
||||||
|
}
|
||||||
|
|
||||||
|
const parsing::errorType err = parsing::checkConversion(buf, endptr);
|
||||||
|
if (err != parsing::errorType::NONE)
|
||||||
|
{
|
||||||
|
FatalIOErrorInFunction("unknown")
|
||||||
|
<< parsing::errorNames[err] << " '" << buf << "'"
|
||||||
|
<< exit(FatalIOError);
|
||||||
|
}
|
||||||
|
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Foam::readUint64(const char* buf, uint64_t& val)
|
||||||
|
{
|
||||||
|
char *endptr = nullptr;
|
||||||
|
errno = 0;
|
||||||
|
const uintmax_t parsed = ::strtoumax(buf, &endptr, 10);
|
||||||
|
|
||||||
|
val = uint64_t(parsed);
|
||||||
|
|
||||||
|
if (parsed > UINT64_MAX)
|
||||||
|
{
|
||||||
|
// Range error
|
||||||
|
errno = ERANGE;
|
||||||
|
}
|
||||||
|
|
||||||
|
const parsing::errorType err = parsing::checkConversion(buf, endptr);
|
||||||
|
if (err != parsing::errorType::NONE)
|
||||||
|
{
|
||||||
|
#ifdef FULLDEBUG
|
||||||
|
IOWarningInFunction("unknown")
|
||||||
|
<< parsing::errorNames[err] << " '" << buf << "'"
|
||||||
|
<< endl;
|
||||||
|
#endif
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::Istream& Foam::operator>>(Istream& is, uint64_t& val)
|
||||||
{
|
{
|
||||||
token t(is);
|
token t(is);
|
||||||
|
|
||||||
@ -55,7 +97,7 @@ Foam::Istream& Foam::operator>>(Istream& is, uint64_t& i)
|
|||||||
|
|
||||||
if (t.isLabel())
|
if (t.isLabel())
|
||||||
{
|
{
|
||||||
i = uint64_t(t.labelToken());
|
val = uint64_t(t.labelToken());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -81,18 +123,9 @@ uint64_t Foam::readUint64(Istream& is)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Foam::read(const char* buf, uint64_t& s)
|
Foam::Ostream& Foam::operator<<(Ostream& os, const uint64_t val)
|
||||||
{
|
{
|
||||||
char *endptr = nullptr;
|
os.write(label(val));
|
||||||
long l = strtol(buf, &endptr, 10);
|
|
||||||
s = uint64_t(l);
|
|
||||||
return (*endptr == 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Foam::Ostream& Foam::operator<<(Ostream& os, const uint64_t i)
|
|
||||||
{
|
|
||||||
os.write(label(i));
|
|
||||||
os.check(FUNCTION_NAME);
|
os.check(FUNCTION_NAME);
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|||||||
38
src/OpenFOAM/primitives/strings/parsing/parsing.C
Normal file
38
src/OpenFOAM/primitives/strings/parsing/parsing.C
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
|
||||||
|
\\/ M anipulation |
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
License
|
||||||
|
This file is part of OpenFOAM.
|
||||||
|
|
||||||
|
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||||
|
under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#include "parsing.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * Global Data * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
const Foam::Enum<Foam::parsing::errorType>
|
||||||
|
Foam::parsing::errorNames
|
||||||
|
{
|
||||||
|
{ errorType::GENERAL, "General error parsing" },
|
||||||
|
{ errorType::TRAILING, "Trailing content found parsing" },
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
85
src/OpenFOAM/primitives/strings/parsing/parsing.H
Normal file
85
src/OpenFOAM/primitives/strings/parsing/parsing.H
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
|
||||||
|
\\/ M anipulation |
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
License
|
||||||
|
This file is part of OpenFOAM.
|
||||||
|
|
||||||
|
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||||
|
under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Namespace
|
||||||
|
Foam::parsing
|
||||||
|
|
||||||
|
Description
|
||||||
|
Collection of static functions and data related to parsing
|
||||||
|
|
||||||
|
SourceFiles
|
||||||
|
parsing.C
|
||||||
|
parsingI.H
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
#ifndef parsing_H
|
||||||
|
#define parsing_H
|
||||||
|
|
||||||
|
#include "Enum.H"
|
||||||
|
#include <cerrno>
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
namespace Foam
|
||||||
|
{
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
Namespace parsing Declaration
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
namespace parsing
|
||||||
|
{
|
||||||
|
// Enumerations
|
||||||
|
|
||||||
|
//- Enumeration for possible parsing error
|
||||||
|
enum class errorType
|
||||||
|
{
|
||||||
|
NONE = 0, //!< No error encountered
|
||||||
|
GENERAL = 1, //!< General parsing error
|
||||||
|
TRAILING = 2, //!< Trailing content detected
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
//- Strings corresponding to the errorType
|
||||||
|
extern const Foam::Enum<errorType> errorNames;
|
||||||
|
|
||||||
|
//- Sanity check after strtof, strtod, etc.
|
||||||
|
// Should set errno = 0 prior to the conversion.
|
||||||
|
inline errorType checkConversion(const char* buf, char* endptr);
|
||||||
|
|
||||||
|
|
||||||
|
} // End namespace parsing
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
} // End namespace Foam
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
#include "parsingI.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
55
src/OpenFOAM/primitives/strings/parsing/parsingI.H
Normal file
55
src/OpenFOAM/primitives/strings/parsing/parsingI.H
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
|
||||||
|
\\/ M anipulation |
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
License
|
||||||
|
This file is part of OpenFOAM.
|
||||||
|
|
||||||
|
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||||
|
under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
inline Foam::parsing::errorType Foam::parsing::checkConversion
|
||||||
|
(
|
||||||
|
const char* buf,
|
||||||
|
char* endptr
|
||||||
|
)
|
||||||
|
{
|
||||||
|
if (errno || endptr == buf)
|
||||||
|
{
|
||||||
|
// Some type of error OR no conversion
|
||||||
|
return errorType::GENERAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Trailing spaces are permitted
|
||||||
|
while (isspace(*endptr))
|
||||||
|
{
|
||||||
|
++endptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*endptr != '\0')
|
||||||
|
{
|
||||||
|
// Trailing content
|
||||||
|
return errorType::TRAILING;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Valid conversion
|
||||||
|
return errorType::NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -24,7 +24,55 @@ License
|
|||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include "NASCore.H"
|
#include "NASCore.H"
|
||||||
#include "StringStream.H"
|
#include "parsing.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
Foam::scalar Foam::fileFormats::NASCore::readNasScalar(const string& str)
|
||||||
|
{
|
||||||
|
const auto signPos = str.find_last_of("+-");
|
||||||
|
|
||||||
|
if
|
||||||
|
(
|
||||||
|
signPos == std::string::npos
|
||||||
|
|| signPos == 0
|
||||||
|
|| str[signPos-1] == 'E' || str[signPos-1] == 'e'
|
||||||
|
|| isspace(str[signPos-1])
|
||||||
|
)
|
||||||
|
{
|
||||||
|
// A normal number format
|
||||||
|
return readScalar(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Nastran compact number format.
|
||||||
|
// Eg, "1234-2" instead of "1234E-2"
|
||||||
|
|
||||||
|
scalar value = 0;
|
||||||
|
int exponent = 0; // Any integer
|
||||||
|
|
||||||
|
if
|
||||||
|
(
|
||||||
|
readScalar(str.substr(0, signPos), value) // Mantissa
|
||||||
|
&& readInt(str.substr(signPos), exponent) // Exponent (with sign)
|
||||||
|
)
|
||||||
|
{
|
||||||
|
// Note: this does not catch underflow/overflow
|
||||||
|
// (especially when scalar is a float)
|
||||||
|
value *= ::pow(10, exponent);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
FatalIOErrorInFunction("unknown")
|
||||||
|
<< parsing::errorNames[parsing::errorType::GENERAL] << str
|
||||||
|
<< exit(FatalIOError);
|
||||||
|
|
||||||
|
value = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
@ -32,36 +80,4 @@ Foam::fileFormats::NASCore::NASCore()
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
Foam::scalar Foam::fileFormats::NASCore::parseNASCoord(const string& s)
|
|
||||||
{
|
|
||||||
scalar value = 0;
|
|
||||||
|
|
||||||
const size_t expSign = s.find_last_of("+-");
|
|
||||||
|
|
||||||
if (expSign != std::string::npos && expSign > 0 && !isspace(s[expSign-1]))
|
|
||||||
{
|
|
||||||
scalar exponent = 0;
|
|
||||||
|
|
||||||
// Parse as per strtod/strtof - allowing trailing space or [Ee]
|
|
||||||
readScalar(s.substr(0, expSign).c_str(), value); // mantissa
|
|
||||||
readScalar(s.substr(expSign+1).c_str(), exponent);
|
|
||||||
|
|
||||||
if (s[expSign] == '-')
|
|
||||||
{
|
|
||||||
exponent = -exponent;
|
|
||||||
}
|
|
||||||
|
|
||||||
value *= ::pow(10, exponent);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
readScalar(s.c_str(), value);
|
|
||||||
}
|
|
||||||
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// ************************************************************************* //
|
// ************************************************************************* //
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -56,7 +56,14 @@ public:
|
|||||||
// Public Member Functions
|
// Public Member Functions
|
||||||
|
|
||||||
//- Extract numbers from things like "-2.358-8" (same as "-2.358e-8")
|
//- Extract numbers from things like "-2.358-8" (same as "-2.358e-8")
|
||||||
static scalar parseNASCoord(const string& s);
|
static scalar readNasScalar(const string& str);
|
||||||
|
|
||||||
|
//- Extract numbers from things like "-2.358-8" (same as "-2.358e-8")
|
||||||
|
// \deprecated use readNasScalar instead (deprecated Sep 2017)
|
||||||
|
inline static scalar parseNASCoord(const string& str)
|
||||||
|
{
|
||||||
|
return readNasScalar(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Constructors
|
// Constructors
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -103,9 +103,9 @@ bool Foam::fileFormats::NASedgeFormat::read
|
|||||||
{
|
{
|
||||||
edge e;
|
edge e;
|
||||||
|
|
||||||
// label groupId = readLabel(IStringStream(line.substr(16,8))());
|
// label groupId = readLabel(line.substr(16,8));
|
||||||
e[0] = readLabel(IStringStream(line.substr(24,8))());
|
e[0] = readLabel(line.substr(24,8));
|
||||||
e[1] = readLabel(IStringStream(line.substr(32,8))());
|
e[1] = readLabel(line.substr(32,8));
|
||||||
|
|
||||||
// discard groupID
|
// discard groupID
|
||||||
dynEdges.append(e);
|
dynEdges.append(e);
|
||||||
@ -114,19 +114,19 @@ bool Foam::fileFormats::NASedgeFormat::read
|
|||||||
{
|
{
|
||||||
edge e;
|
edge e;
|
||||||
|
|
||||||
// label groupId = readLabel(IStringStream(line.substr(16,8))());
|
// label groupId = readLabel(line.substr(16,8));
|
||||||
e[0] = readLabel(IStringStream(line.substr(16,8))());
|
e[0] = readLabel(line.substr(16,8));
|
||||||
e[1] = readLabel(IStringStream(line.substr(24,8))());
|
e[1] = readLabel(line.substr(24,8));
|
||||||
|
|
||||||
// discard groupID
|
// discard groupID
|
||||||
dynEdges.append(e);
|
dynEdges.append(e);
|
||||||
}
|
}
|
||||||
else if (cmd == "GRID")
|
else if (cmd == "GRID")
|
||||||
{
|
{
|
||||||
label index = readLabel(IStringStream(line.substr(8,8))());
|
label index = readLabel(line.substr(8,8));
|
||||||
scalar x = parseNASCoord(line.substr(24, 8));
|
scalar x = readNasScalar(line.substr(24, 8));
|
||||||
scalar y = parseNASCoord(line.substr(32, 8));
|
scalar y = readNasScalar(line.substr(32, 8));
|
||||||
scalar z = parseNASCoord(line.substr(40, 8));
|
scalar z = readNasScalar(line.substr(40, 8));
|
||||||
|
|
||||||
pointId.append(index);
|
pointId.append(index);
|
||||||
dynPoints.append(point(x, y, z));
|
dynPoints.append(point(x, y, z));
|
||||||
@ -139,9 +139,9 @@ bool Foam::fileFormats::NASedgeFormat::read
|
|||||||
// GRID* 126 0 -5.55999875E+02 -5.68730474E+02
|
// GRID* 126 0 -5.55999875E+02 -5.68730474E+02
|
||||||
// * 2.14897901E+02
|
// * 2.14897901E+02
|
||||||
|
|
||||||
label index = readLabel(IStringStream(line.substr(8,16))());
|
label index = readLabel(line.substr(8,16));
|
||||||
scalar x = parseNASCoord(line.substr(40, 16));
|
scalar x = readNasScalar(line.substr(40, 16));
|
||||||
scalar y = parseNASCoord(line.substr(56, 16));
|
scalar y = readNasScalar(line.substr(56, 16));
|
||||||
|
|
||||||
is.getLine(line);
|
is.getLine(line);
|
||||||
if (line[0] != '*')
|
if (line[0] != '*')
|
||||||
@ -153,7 +153,7 @@ bool Foam::fileFormats::NASedgeFormat::read
|
|||||||
<< "File:" << is.name() << " line:" << is.lineNumber()
|
<< "File:" << is.name() << " line:" << is.lineNumber()
|
||||||
<< exit(FatalError);
|
<< exit(FatalError);
|
||||||
}
|
}
|
||||||
scalar z = parseNASCoord(line.substr(8, 16));
|
scalar z = readNasScalar(line.substr(8, 16));
|
||||||
|
|
||||||
pointId.append(index);
|
pointId.append(index);
|
||||||
dynPoints.append(point(x, y, z));
|
dynPoints.append(point(x, y, z));
|
||||||
|
|||||||
@ -92,9 +92,9 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read
|
|||||||
// ANSA extension
|
// ANSA extension
|
||||||
if (line.startsWith("$ANSA_NAME"))
|
if (line.startsWith("$ANSA_NAME"))
|
||||||
{
|
{
|
||||||
string::size_type sem0 = line.find(';', 0);
|
const auto sem0 = line.find(';', 0);
|
||||||
string::size_type sem1 = line.find(';', sem0+1);
|
const auto sem1 = line.find(';', sem0+1);
|
||||||
string::size_type sem2 = line.find(';', sem1+1);
|
const auto sem2 = line.find(';', sem1+1);
|
||||||
|
|
||||||
if
|
if
|
||||||
(
|
(
|
||||||
@ -103,10 +103,7 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read
|
|||||||
&& sem2 != string::npos
|
&& sem2 != string::npos
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
ansaId = readLabel
|
ansaId = readLabel(line.substr(sem0+1, sem1-sem0-1));
|
||||||
(
|
|
||||||
IStringStream(line.substr(sem0+1, sem1-sem0-1))()
|
|
||||||
);
|
|
||||||
ansaType = line.substr(sem1+1, sem2-sem1-1);
|
ansaType = line.substr(sem1+1, sem2-sem1-1);
|
||||||
|
|
||||||
string rawName;
|
string rawName;
|
||||||
@ -125,11 +122,7 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read
|
|||||||
// $HMNAME COMP 1"partName"
|
// $HMNAME COMP 1"partName"
|
||||||
if (line.startsWith("$HMNAME COMP") && line.find('"') != string::npos)
|
if (line.startsWith("$HMNAME COMP") && line.find('"') != string::npos)
|
||||||
{
|
{
|
||||||
label groupId = readLabel
|
label groupId = readLabel(line.substr(16, 16));
|
||||||
(
|
|
||||||
IStringStream(line.substr(16, 16))()
|
|
||||||
);
|
|
||||||
|
|
||||||
IStringStream lineStream(line.substr(32));
|
IStringStream lineStream(line.substr(32));
|
||||||
|
|
||||||
string rawName;
|
string rawName;
|
||||||
@ -177,10 +170,10 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read
|
|||||||
|
|
||||||
if (cmd == "CTRIA3")
|
if (cmd == "CTRIA3")
|
||||||
{
|
{
|
||||||
label groupId = readLabel(IStringStream(line.substr(16,8))());
|
label groupId = readLabel(line.substr(16,8));
|
||||||
label a = readLabel(IStringStream(line.substr(24,8))());
|
label a = readLabel(line.substr(24,8));
|
||||||
label b = readLabel(IStringStream(line.substr(32,8))());
|
label b = readLabel(line.substr(32,8));
|
||||||
label c = readLabel(IStringStream(line.substr(40,8))());
|
label c = readLabel(line.substr(40,8));
|
||||||
|
|
||||||
// Convert groupID into zoneId
|
// Convert groupID into zoneId
|
||||||
Map<label>::const_iterator fnd = lookup.find(groupId);
|
Map<label>::const_iterator fnd = lookup.find(groupId);
|
||||||
@ -207,11 +200,11 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read
|
|||||||
}
|
}
|
||||||
else if (cmd == "CQUAD4")
|
else if (cmd == "CQUAD4")
|
||||||
{
|
{
|
||||||
label groupId = readLabel(IStringStream(line.substr(16,8))());
|
label groupId = readLabel(line.substr(16,8));
|
||||||
label a = readLabel(IStringStream(line.substr(24,8))());
|
label a = readLabel(line.substr(24,8));
|
||||||
label b = readLabel(IStringStream(line.substr(32,8))());
|
label b = readLabel(line.substr(32,8));
|
||||||
label c = readLabel(IStringStream(line.substr(40,8))());
|
label c = readLabel(line.substr(40,8));
|
||||||
label d = readLabel(IStringStream(line.substr(48,8))());
|
label d = readLabel(line.substr(48,8));
|
||||||
|
|
||||||
// Convert groupID into zoneId
|
// Convert groupID into zoneId
|
||||||
Map<label>::const_iterator fnd = lookup.find(groupId);
|
Map<label>::const_iterator fnd = lookup.find(groupId);
|
||||||
@ -249,10 +242,10 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read
|
|||||||
}
|
}
|
||||||
else if (cmd == "GRID")
|
else if (cmd == "GRID")
|
||||||
{
|
{
|
||||||
label index = readLabel(IStringStream(line.substr(8,8))());
|
label index = readLabel(line.substr(8,8));
|
||||||
scalar x = parseNASCoord(line.substr(24, 8));
|
scalar x = readNasScalar(line.substr(24, 8));
|
||||||
scalar y = parseNASCoord(line.substr(32, 8));
|
scalar y = readNasScalar(line.substr(32, 8));
|
||||||
scalar z = parseNASCoord(line.substr(40, 8));
|
scalar z = readNasScalar(line.substr(40, 8));
|
||||||
|
|
||||||
pointId.append(index);
|
pointId.append(index);
|
||||||
dynPoints.append(point(x, y, z));
|
dynPoints.append(point(x, y, z));
|
||||||
@ -265,9 +258,9 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read
|
|||||||
// GRID* 126 0 -5.55999875E+02 -5.68730474E+02
|
// GRID* 126 0 -5.55999875E+02 -5.68730474E+02
|
||||||
// * 2.14897901E+02
|
// * 2.14897901E+02
|
||||||
|
|
||||||
label index = readLabel(IStringStream(line.substr(8,16))());
|
label index = readLabel(line.substr(8,16));
|
||||||
scalar x = parseNASCoord(line.substr(40, 16));
|
scalar x = readNasScalar(line.substr(40, 16));
|
||||||
scalar y = parseNASCoord(line.substr(56, 16));
|
scalar y = readNasScalar(line.substr(56, 16));
|
||||||
|
|
||||||
is.getLine(line);
|
is.getLine(line);
|
||||||
if (line[0] != '*')
|
if (line[0] != '*')
|
||||||
@ -279,7 +272,7 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read
|
|||||||
<< "File:" << is.name() << " line:" << is.lineNumber()
|
<< "File:" << is.name() << " line:" << is.lineNumber()
|
||||||
<< exit(FatalError);
|
<< exit(FatalError);
|
||||||
}
|
}
|
||||||
scalar z = parseNASCoord(line.substr(8, 16));
|
scalar z = readNasScalar(line.substr(8, 16));
|
||||||
|
|
||||||
pointId.append(index);
|
pointId.append(index);
|
||||||
dynPoints.append(point(x, y, z));
|
dynPoints.append(point(x, y, z));
|
||||||
@ -287,7 +280,7 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read
|
|||||||
else if (cmd == "PSHELL")
|
else if (cmd == "PSHELL")
|
||||||
{
|
{
|
||||||
// pshell type for zone names with the Ansa extension
|
// pshell type for zone names with the Ansa extension
|
||||||
label groupId = readLabel(IStringStream(line.substr(8,8))());
|
label groupId = readLabel(line.substr(8,8));
|
||||||
|
|
||||||
if (groupId == ansaId && ansaType == "PSHELL")
|
if (groupId == ansaId && ansaType == "PSHELL")
|
||||||
{
|
{
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -47,9 +47,9 @@ namespace Foam
|
|||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
// Do weird things to extract number
|
// Do weird things to extract number
|
||||||
static inline scalar parseNASCoord(const string& s)
|
static inline scalar readNasScalar(const string& s)
|
||||||
{
|
{
|
||||||
return fileFormats::NASCore::parseNASCoord(s);
|
return Foam::fileFormats::NASCore::readNasScalar(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -118,9 +118,9 @@ bool triSurface::readNAS(const fileName& fName)
|
|||||||
// ANSA extension
|
// ANSA extension
|
||||||
if (line.startsWith("$ANSA_NAME"))
|
if (line.startsWith("$ANSA_NAME"))
|
||||||
{
|
{
|
||||||
string::size_type sem0 = line.find(';', 0);
|
const auto sem0 = line.find(';', 0);
|
||||||
string::size_type sem1 = line.find(';', sem0+1);
|
const auto sem1 = line.find(';', sem0+1);
|
||||||
string::size_type sem2 = line.find(';', sem1+1);
|
const auto sem2 = line.find(';', sem1+1);
|
||||||
|
|
||||||
if
|
if
|
||||||
(
|
(
|
||||||
@ -129,10 +129,7 @@ bool triSurface::readNAS(const fileName& fName)
|
|||||||
&& sem2 != string::npos
|
&& sem2 != string::npos
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
ansaId = readLabel
|
ansaId = readLabel(line.substr(sem0+1, sem1-sem0-1));
|
||||||
(
|
|
||||||
IStringStream(line.substr(sem0+1, sem1-sem0-1))()
|
|
||||||
);
|
|
||||||
ansaType = line.substr(sem1+1, sem2-sem1-1);
|
ansaType = line.substr(sem1+1, sem2-sem1-1);
|
||||||
|
|
||||||
string nameString;
|
string nameString;
|
||||||
@ -152,11 +149,7 @@ bool triSurface::readNAS(const fileName& fName)
|
|||||||
// $HMNAME COMP 1"partName"
|
// $HMNAME COMP 1"partName"
|
||||||
if (line.startsWith("$HMNAME COMP") && line.find('"') != string::npos)
|
if (line.startsWith("$HMNAME COMP") && line.find('"') != string::npos)
|
||||||
{
|
{
|
||||||
label groupId = readLabel
|
label groupId = readLabel(line.substr(16, 16));
|
||||||
(
|
|
||||||
IStringStream(line.substr(16, 16))()
|
|
||||||
);
|
|
||||||
|
|
||||||
IStringStream lineStream(line.substr(32));
|
IStringStream lineStream(line.substr(32));
|
||||||
|
|
||||||
string rawName;
|
string rawName;
|
||||||
@ -202,11 +195,10 @@ bool triSurface::readNAS(const fileName& fName)
|
|||||||
if (cmd == "CTRIA3")
|
if (cmd == "CTRIA3")
|
||||||
{
|
{
|
||||||
readNASToken(line, 8, linei);
|
readNASToken(line, 8, linei);
|
||||||
label groupId =
|
label groupId = readLabel(readNASToken(line, 8, linei));
|
||||||
readLabel(IStringStream(readNASToken(line, 8, linei))());
|
label a = readLabel(readNASToken(line, 8, linei));
|
||||||
label a = readLabel(IStringStream(readNASToken(line, 8, linei))());
|
label b = readLabel(readNASToken(line, 8, linei));
|
||||||
label b = readLabel(IStringStream(readNASToken(line, 8, linei))());
|
label c = readLabel(readNASToken(line, 8, linei));
|
||||||
label c = readLabel(IStringStream(readNASToken(line, 8, linei))());
|
|
||||||
|
|
||||||
// Convert group into patch
|
// Convert group into patch
|
||||||
Map<label>::const_iterator iter = groupToPatch.find(groupId);
|
Map<label>::const_iterator iter = groupToPatch.find(groupId);
|
||||||
@ -228,12 +220,11 @@ bool triSurface::readNAS(const fileName& fName)
|
|||||||
else if (cmd == "CQUAD4")
|
else if (cmd == "CQUAD4")
|
||||||
{
|
{
|
||||||
readNASToken(line, 8, linei);
|
readNASToken(line, 8, linei);
|
||||||
label groupId =
|
label groupId = readLabel(readNASToken(line, 8, linei));
|
||||||
readLabel(IStringStream(readNASToken(line, 8, linei))());
|
label a = readLabel(readNASToken(line, 8, linei));
|
||||||
label a = readLabel(IStringStream(readNASToken(line, 8, linei))());
|
label b = readLabel(readNASToken(line, 8, linei));
|
||||||
label b = readLabel(IStringStream(readNASToken(line, 8, linei))());
|
label c = readLabel(readNASToken(line, 8, linei));
|
||||||
label c = readLabel(IStringStream(readNASToken(line, 8, linei))());
|
label d = readLabel(readNASToken(line, 8, linei));
|
||||||
label d = readLabel(IStringStream(readNASToken(line, 8, linei))());
|
|
||||||
|
|
||||||
// Convert group into patch
|
// Convert group into patch
|
||||||
Map<label>::const_iterator iter = groupToPatch.find(groupId);
|
Map<label>::const_iterator iter = groupToPatch.find(groupId);
|
||||||
@ -256,8 +247,7 @@ bool triSurface::readNAS(const fileName& fName)
|
|||||||
else if (cmd == "PSHELL")
|
else if (cmd == "PSHELL")
|
||||||
{
|
{
|
||||||
// Read shell type since group gives patchnames
|
// Read shell type since group gives patchnames
|
||||||
label groupId =
|
label groupId = readLabel(readNASToken(line, 8, linei));
|
||||||
readLabel(IStringStream(readNASToken(line, 8, linei))());
|
|
||||||
if (groupId == ansaId && ansaType == "PSHELL")
|
if (groupId == ansaId && ansaType == "PSHELL")
|
||||||
{
|
{
|
||||||
const word groupName = word::validate(ansaName);
|
const word groupName = word::validate(ansaName);
|
||||||
@ -267,12 +257,11 @@ bool triSurface::readNAS(const fileName& fName)
|
|||||||
}
|
}
|
||||||
else if (cmd == "GRID")
|
else if (cmd == "GRID")
|
||||||
{
|
{
|
||||||
label index =
|
label index = readLabel(readNASToken(line, 8, linei));
|
||||||
readLabel(IStringStream(readNASToken(line, 8, linei))());
|
|
||||||
readNASToken(line, 8, linei);
|
readNASToken(line, 8, linei);
|
||||||
scalar x = parseNASCoord(readNASToken(line, 8, linei));
|
scalar x = readNasScalar(readNASToken(line, 8, linei));
|
||||||
scalar y = parseNASCoord(readNASToken(line, 8, linei));
|
scalar y = readNasScalar(readNASToken(line, 8, linei));
|
||||||
scalar z = parseNASCoord(readNASToken(line, 8, linei));
|
scalar z = readNasScalar(readNASToken(line, 8, linei));
|
||||||
|
|
||||||
indices.append(index);
|
indices.append(index);
|
||||||
points.append(point(x, y, z));
|
points.append(point(x, y, z));
|
||||||
@ -284,11 +273,10 @@ bool triSurface::readNAS(const fileName& fName)
|
|||||||
// Typical line (spaces compacted)
|
// Typical line (spaces compacted)
|
||||||
// GRID* 126 0 -5.55999875E+02 -5.68730474E+02
|
// GRID* 126 0 -5.55999875E+02 -5.68730474E+02
|
||||||
// * 2.14897901E+02
|
// * 2.14897901E+02
|
||||||
label index =
|
label index = readLabel(readNASToken(line, 16, linei));
|
||||||
readLabel(IStringStream(readNASToken(line, 16, linei))());
|
|
||||||
readNASToken(line, 16, linei);
|
readNASToken(line, 16, linei);
|
||||||
scalar x = parseNASCoord(readNASToken(line, 16, linei));
|
scalar x = readNasScalar(readNASToken(line, 16, linei));
|
||||||
scalar y = parseNASCoord(readNASToken(line, 16, linei));
|
scalar y = readNasScalar(readNASToken(line, 16, linei));
|
||||||
|
|
||||||
linei = 0;
|
linei = 0;
|
||||||
is.getLine(line);
|
is.getLine(line);
|
||||||
@ -303,7 +291,7 @@ bool triSurface::readNAS(const fileName& fName)
|
|||||||
<< exit(FatalError);
|
<< exit(FatalError);
|
||||||
}
|
}
|
||||||
readNASToken(line, 8, linei);
|
readNASToken(line, 8, linei);
|
||||||
scalar z = parseNASCoord(readNASToken(line, 16, linei));
|
scalar z = readNasScalar(readNASToken(line, 16, linei));
|
||||||
|
|
||||||
indices.append(index);
|
indices.append(index);
|
||||||
points.append(point(x, y, z));
|
points.append(point(x, y, z));
|
||||||
|
|||||||
@ -531,11 +531,11 @@ void Foam::radiation::fvDOM::setRayIdLambdaId
|
|||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
// assuming name is in the form: CHARS_rayId_lambdaId
|
// assuming name is in the form: CHARS_rayId_lambdaId
|
||||||
const size_type i1 = name.find('_');
|
const auto i1 = name.find('_');
|
||||||
const size_type i2 = name.rfind('_');
|
const auto i2 = name.rfind('_');
|
||||||
|
|
||||||
rayId = readLabel(IStringStream(name.substr(i1+1, i2-1))());
|
rayId = readLabel(name.substr(i1+1, i2-1));
|
||||||
lambdaId = readLabel(IStringStream(name.substr(i2+1))());
|
lambdaId = readLabel(name.substr(i2+1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user