Loading...
Searching...
No Matches
uint64.H
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) 2014-2016 OpenFOAM Foundation
9 Copyright (C) 2016-2021 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
27Primitive
28 uint64_t
29
30Description
31 64bit unsigned integer
32
33SourceFiles
34 uint64.C
35 uint64IO.C
36
37\*---------------------------------------------------------------------------*/
38
39#ifndef Foam_primitives_uint64_H
40#define Foam_primitives_uint64_H
41
42#include <cstdint>
43#include <climits>
44#include <cstdlib>
45
46#include "direction.H"
47#include "pTraits.H"
48#include "word.H"
49
50// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
51
52namespace Foam
53{
54
55// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
57//- A word representation of uint64 value
58inline word name(const uint64_t val)
59{
60 return word(std::to_string(val), false); // Needs no stripping
61}
62
63
64//- A word representation of uint64 value
65template<>
66struct nameOp<uint64_t>
67{
68 word operator()(const uint64_t val) const
69 {
70 return word(std::to_string(val), false); // Needs no stripping
71 }
72};
73
74
75// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
76
77//- Read uint64_t from stream.
78uint64_t readUint64(Istream& is);
79
80//- Parse entire buffer as uint64_t, skipping leading/trailing whitespace.
81// \return Parsed value or FatalIOError on any problem
82uint64_t readUint64(const char* buf);
83
84//- Parse entire string as uint64_t, skipping leading/trailing whitespace.
85// \return Parsed value or FatalIOError on any problem
86inline uint64_t readUint64(const std::string& str)
87{
88 return readUint64(str.c_str());
89}
90
91//- Parse entire buffer as uint64_t, skipping leading/trailing whitespace.
92// \return True if successful.
93bool readUint64(const char* buf, uint64_t& val);
95//- Parse entire string as uint64_t, skipping leading/trailing whitespace.
96// \return True if successful.
97inline bool readUint64(const std::string& str, uint64_t& val)
98{
99 return readUint64(str.c_str(), val);
100}
101
102//- Same as readUint64
103// \return True if successful.
104inline bool read(const char* buf, uint64_t& val)
105{
106 return readUint64(buf, val);
107}
108
109//- Same as readUint64
110// \return True if successful.
111inline bool read(const std::string& str, uint64_t& val)
112{
113 return readUint64(str, val);
114}
115
116
117Istream& operator>>(Istream& is, uint64_t& val);
118Ostream& operator<<(Ostream& os, const uint64_t val);
119
120// On Darwin:
121// unsigned long is not unambiguously (uint32_t | uint64_t)
122// - explicitly resolve for output
123#ifdef __APPLE__
124 Ostream& operator<<(Ostream& os, const unsigned long val);
125#endif
126
127
128/*---------------------------------------------------------------------------*\
129 Specialization pTraits<uint64_t>
130\*---------------------------------------------------------------------------*/
132//- Template specialization for pTraits<uint64_t>
133template<>
134class pTraits<uint64_t>
135{
136 uint64_t p_;
137
138public:
139
140 // Typedefs
141
142 //- Component type
143 typedef uint64_t cmptType;
144
145
146 // Member Constants
147
148 //- Dimensionality of space
149 static constexpr direction dim = 3;
150
151 //- Rank of uint64_t is 0
152 static constexpr direction rank = 0;
153
154 //- Number of components in uint64_t is 1
155 static constexpr direction nComponents = 1;
157
158 // Limits
159
160 static constexpr uint64_t min_ = 0;
161 static constexpr uint64_t max_ = UINT64_MAX;
162
163
164 // Static Data Members
165
166 static const char* const typeName;
167 static const char* const componentNames[];
168 static const uint64_t zero;
169 static const uint64_t one;
170 static const uint64_t min;
171 static const uint64_t max;
172 static const uint64_t rootMax;
173 static const uint64_t rootMin;
174
176 // Constructors
177
178 //- Copy construct from primitive
179 explicit pTraits(uint64_t val) noexcept : p_(val) {}
181 //- Read construct from Istream
182 explicit pTraits(Istream& is);
183
184
185 // Member Functions
186
187 //- Return the value
188 operator uint64_t() const noexcept { return p_; }
189
190 //- Access the value
191 operator uint64_t&() noexcept { return p_; }
192};
193
194
195#ifdef __APPLE__
196//- On Darwin: unsigned long is not unambiguously (uint64_t)
197template<> class pTraits<unsigned long> : pTraits<uint64_t> {};
198#endif
200// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
202} // End namespace Foam
204// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
205
206#endif
207
208// ************************************************************************* //
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition Istream.H:60
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
static const char *const typeName
Definition uint64.H:196
static const uint64_t min
Definition uint64.H:200
static const char *const componentNames[]
Definition uint64.H:26
uint64_t cmptType
Component type.
Definition uint64.H:167
static const uint64_t one
Definition uint64.H:199
pTraits(uint64_t val) noexcept
Copy construct from primitive.
Definition uint64.H:211
static const uint64_t rootMax
Definition uint64.H:202
static constexpr direction nComponents
Number of components in uint64_t is 1.
Definition uint64.H:185
static constexpr direction rank
Rank of uint64_t is 0.
Definition uint64.H:180
static constexpr direction dim
Dimensionality of space.
Definition uint64.H:175
static const uint64_t max
Definition uint64.H:201
static constexpr uint64_t max_
Definition uint64.H:191
static constexpr uint64_t min_
Definition uint64.H:190
static const uint64_t zero
Definition uint64.H:198
static const uint64_t rootMin
Definition uint64.H:203
A traits class, which is primarily used for primitives and vector-space.
Definition pTraits.H:64
pTraits(const Base &obj)
Copy construct from base class.
Definition pTraits.H:72
A class for handling words, derived from Foam::string.
Definition word.H:66
Direction is an 8-bit unsigned integer type used to represent Cartesian directions,...
OBJstream os(runTime.globalPath()/outputName)
auto & name
Namespace for OpenFOAM.
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition int32.H:127
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces).
Istream & operator>>(Istream &, directionInfo &)
uint8_t direction
Definition direction.H:49
const direction noexcept
Definition scalarImpl.H:265
uint64_t readUint64(Istream &is)
Read uint64_t from stream.
Definition uint64IO.C:73
word operator()(const uint64_t val) const
Definition uint64.H:68
Extract name (as a word) from an object, typically using its name() method.
Definition word.H:341