Loading...
Searching...
No Matches
uint32.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 uint32_t
29
30Description
31 32bit unsigned integer
32
33SourceFiles
34 uint32.C
35 uint32IO.C
36
37\*---------------------------------------------------------------------------*/
38
39#ifndef Foam_primitives_uint32_H
40#define Foam_primitives_uint32_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 uint32 value
58inline word name(const uint32_t val)
59{
60 return word(std::to_string(val), false); // Needs no stripping
61}
62
63//- A word representation of uint32 value
64template<>
65struct nameOp<uint32_t>
66{
67 word operator()(const uint32_t val) const
68 {
69 return word(std::to_string(val), false); // Needs no stripping
70 }
71};
72
73
74// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
75
76//- Read uint32_t from stream
77uint32_t readUint32(Istream& is);
78
79//- Parse entire buffer as a uint32_t, skipping leading/trailing whitespace.
80// \return Parsed value or FatalIOError on any problem
81uint32_t readUint32(const char* buf);
82
83//- Parse entire string as a uint32_t, skipping leading/trailing whitespace.
84// \return Parsed value or FatalIOError on any problem
85inline uint32_t readUint32(const std::string& str)
86{
87 return readUint32(str.c_str());
88}
89
90//- Read entire buffer as a uint32_t, skipping leading/trailing whitespace.
91// \return True if successful.
92bool readUint32(const char* buf, uint32_t& val);
94//- Read entire string as a uint32_t, skipping leading/trailing whitespace.
95// \return True if successful.
96inline bool readUint32(const std::string& str, uint32_t& val)
97{
98 return readUint32(str.c_str(), val);
99}
100
101//- Same as readUint32
102// \return True if successful.
103inline bool read(const char* buf, uint32_t& val)
104{
105 return readUint32(buf, val);
106}
107
108//- Same as readUint32
109// \return True if successful.
110inline bool read(const std::string& str, uint32_t& val)
111{
112 return readUint32(str, val);
113}
114
115
116Istream& operator>>(Istream& is, uint32_t& val);
117Ostream& operator<<(Ostream& os, const uint32_t val);
118
119
120/*---------------------------------------------------------------------------*\
121 Specialization pTraits<uint32_t>
122\*---------------------------------------------------------------------------*/
123
124//- Template specialization for pTraits<uint32_t>
125template<>
126class pTraits<uint32_t>
127{
128 uint32_t p_;
129
130public:
131
132 // Typedefs
133
134 //- Component type
135 typedef uint32_t cmptType;
136
137
138 // Member Constants
139
140 //- Dimensionality of space
141 static constexpr direction dim = 3;
142
143 //- Rank of uint32_t is 0
144 static constexpr direction rank = 0;
145
146 //- Number of components in uint32_t is 1
147 static constexpr direction nComponents = 1;
149
150 // Limits
151
152 static constexpr uint32_t min_ = 0;
153 static constexpr uint32_t max_ = UINT32_MAX;
154
155
156 // Static Data Members
157
158 static const char* const typeName;
159 static const char* const componentNames[];
160 static const uint32_t zero;
161 static const uint32_t one;
162 static const uint32_t min;
163 static const uint32_t max;
164 static const uint32_t rootMax;
165 static const uint32_t rootMin;
166
168 // Constructors
169
170 //- Copy construct from primitive
171 explicit pTraits(uint32_t val) noexcept : p_(val) {}
173 //- Read construct from Istream
174 explicit pTraits(Istream& is);
175
176
177 // Member Functions
178
179 //- Return the value
180 operator uint32_t() const noexcept { return p_; }
181
182 //- Access the value
183 operator uint32_t&() noexcept { return p_; }
184};
185
186
187// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
189} // End namespace Foam
191// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
193#endif
195// ************************************************************************* //
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition Istream.H:60
static const char *const typeName
Definition uint32.H:188
uint32_t cmptType
Component type.
Definition uint32.H:159
static const char *const componentNames[]
Definition uint32.H:26
pTraits(uint32_t val) noexcept
Copy construct from primitive.
Definition uint32.H:203
static const uint32_t one
Definition uint32.H:191
static const uint32_t max
Definition uint32.H:193
static const uint32_t zero
Definition uint32.H:190
static constexpr direction nComponents
Number of components in uint32_t is 1.
Definition uint32.H:177
static constexpr direction rank
Rank of uint32_t is 0.
Definition uint32.H:172
static constexpr direction dim
Dimensionality of space.
Definition uint32.H:167
static constexpr uint32_t max_
Definition uint32.H:183
static const uint32_t rootMin
Definition uint32.H:195
static constexpr uint32_t min_
Definition uint32.H:182
static const uint32_t rootMax
Definition uint32.H:194
static const uint32_t min
Definition uint32.H:192
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
uint32_t readUint32(Istream &is)
Read uint32_t from stream.
Definition uint32IO.C:73
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
word operator()(const uint32_t val) const
Definition uint32.H:67
Extract name (as a word) from an object, typically using its name() method.
Definition word.H:341