ReadHex.C
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2013-2015 OpenFOAM Foundation
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26Description
27 Read a non-delimited hex label
28
29\*---------------------------------------------------------------------------*/
30
31#include "ReadHex.H"
32#include <cctype>
33
34// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35
36template<class T>
38{
39 // The char '0' == 0
40 static constexpr int offsetZero = int('0');
41
42 // The char 'A' (or 'a') == 10
43 static constexpr int offsetAlpha = int('A') - 10;
44
45 char c = 0;
46
47 // Get next non-whitespace character
48 while (is.get(c) && isspace(c))
49 {}
50
51 T result = 0;
52 do
53 {
54 if (isspace(c) || c == 0) break;
55
56 if (!isxdigit(c))
57 {
59 << "Illegal hex digit: '" << c << "'"
61 }
62
63 result <<= 4;
64
65 if (isdigit(c))
66 {
67 result += int(c) - offsetZero;
68 }
69 else
70 {
71 result += toupper(c) - offsetAlpha;
72 }
73 } while (is.get(c));
74
75 return result;
76}
77
78
79// ************************************************************************* //
Read a hex integer from an input stream.
static constexpr int offsetAlpha
Definition: SHA1Digest.C:43
static constexpr int offsetZero
Definition: SHA1Digest.C:40
Generic input stream using a standard (STL) stream.
Definition: ISstream.H:58
ISstream & get(char &c)
Raw, low-level get character function.
Definition: ISstreamI.H:56
const volScalarField & T
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:473
T ReadHex(ISstream &is)
Read a hex integer from an input stream.
Definition: ReadHex.C:37
bool isspace(char c) noexcept
Test for whitespace (C-locale)
Definition: char.H:65
IOerror FatalIOError
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130