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 -------------------------------------------------------------------------------
11 License
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/>.
26 
27 Primitive
28  uint32_t
29 
30 Description
31  32bit unsigned integer
32 
33 SourceFiles
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 
52 namespace Foam
53 {
54 
55 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
56 
57 //- A word representation of uint32 value
58 inline 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
64 template<>
65 struct 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
77 uint32_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
81 uint32_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
85 inline 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.
92 bool readUint32(const char* buf, uint32_t& val);
93 
94 //- Read entire string as a uint32_t, skipping leading/trailing whitespace.
95 // \return True if successful.
96 inline 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.
103 inline 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.
110 inline bool read(const std::string& str, uint32_t& val)
111 {
112  return readUint32(str, val);
113 }
114 
115 
116 Istream& operator>>(Istream& is, uint32_t& val);
117 Ostream& operator<<(Ostream& os, const uint32_t val);
118 
119 
120 /*---------------------------------------------------------------------------*\
121  Specialization pTraits<uint32_t>
122 \*---------------------------------------------------------------------------*/
123 
124 //- Template specialization for pTraits<uint32_t>
125 template<>
126 class pTraits<uint32_t>
127 {
128  uint32_t p_;
129 
130 public:
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  // Static Data Members
151 
152  static const char* const typeName;
153  static const char* const componentNames[];
154  static const uint32_t zero;
155  static const uint32_t one;
156  static const uint32_t min;
157  static const uint32_t max;
158  static const uint32_t rootMax;
159  static const uint32_t rootMin;
160 
161 
162  // Constructors
163 
164  //- Copy construct from primitive
165  explicit pTraits(uint32_t val) noexcept
166  :
167  p_(val)
168  {}
169 
170  //- Read construct from Istream
171  explicit pTraits(Istream& is);
173 
174  // Member Functions
175 
176  //- Return the value
177  operator uint32_t() const noexcept { return p_; }
178 
179  //- Access the value
180  operator uint32_t&() noexcept { return p_; }
181 };
184 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
186 } // End namespace Foam
188 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
190 #endif
191 
192 // ************************************************************************* //
uint8_t direction
Definition: direction.H:46
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:40
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
A traits class, which is primarily used for primitives and vector-space.
Definition: pTraits.H:75
::Foam::direction nComponents(const expressions::valueTypeCode) noexcept
The number of components associated with given valueTypeCode.
Definition: exprTraits.C:40
Extract name (as a word) from an object, typically using its name() method.
Definition: word.H:340
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition: int32.H:127
pTraits(const Base &obj)
Copy construct from base class.
Definition: pTraits.H:86
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
A class for handling words, derived from Foam::string.
Definition: word.H:63
Istream & operator>>(Istream &, directionInfo &)
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:26
word operator()(const uint32_t val) const
Definition: uint32.H:67
const direction noexcept
Definition: Scalar.H:258
OBJstream os(runTime.globalPath()/outputName)
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:77
Direction is an 8-bit unsigned integer type used to represent Cartesian directions, components etc.
uint32_t readUint32(Istream &is)
Read uint32_t from stream.
Definition: uint32IO.C:73
::Foam::direction rank(const expressions::valueTypeCode) noexcept
The vector-space rank associated with given valueTypeCode.
Definition: exprTraits.C:70
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:57
Namespace for OpenFOAM.
A class representing the concept of 1 (one) that can be used to avoid manipulating objects known to b...
Definition: one.H:56