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 // Forward Declarations
56 class Istream;
57 class Ostream;
58 
59 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
60 
61 //- A word representation of uint32 value
62 inline word name(const uint32_t val)
63 {
64  return word(std::to_string(val), false); // Needs no stripping
65 }
66 
67 //- A word representation of uint32 value
68 template<>
69 struct nameOp<uint32_t>
70 {
71  word operator()(const uint32_t val) const
72  {
73  return word(std::to_string(val), false); // Needs no stripping
74  }
75 };
76 
77 
78 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
79 
80 //- Read uint32_t from stream
81 uint32_t readUint32(Istream& is);
82 
83 //- Parse entire buffer as a uint32_t, skipping leading/trailing whitespace.
84 // \return Parsed value or FatalIOError on any problem
85 uint32_t readUint32(const char* buf);
86 
87 //- Parse entire string as a uint32_t, skipping leading/trailing whitespace.
88 // \return Parsed value or FatalIOError on any problem
89 inline uint32_t readUint32(const std::string& str)
90 {
91  return readUint32(str.c_str());
92 }
93 
94 //- Read entire buffer as a uint32_t, skipping leading/trailing whitespace.
95 // \return True if successful.
96 bool readUint32(const char* buf, uint32_t& val);
97 
98 //- Read entire string as a uint32_t, skipping leading/trailing whitespace.
99 // \return True if successful.
100 inline bool readUint32(const std::string& str, uint32_t& val)
101 {
102  return readUint32(str.c_str(), val);
103 }
104 
105 //- Same as readUint32
106 // \return True if successful.
107 inline bool read(const char* buf, uint32_t& val)
108 {
109  return readUint32(buf, val);
110 }
111 
112 //- Same as readUint32
113 // \return True if successful.
114 inline bool read(const std::string& str, uint32_t& val)
115 {
116  return readUint32(str, val);
117 }
118 
119 
120 Istream& operator>>(Istream& is, uint32_t& val);
121 Ostream& operator<<(Ostream& os, const uint32_t val);
122 
123 //- Template specialization for pTraits<uint32_t>
124 template<>
125 class pTraits<uint32_t>
126 {
127  uint32_t p_;
128 
129 public:
130 
131  // Typedefs
132 
133  //- Component type
134  typedef uint32_t cmptType;
135 
136 
137  // Member Constants
138 
139  //- Dimensionality of space
140  static constexpr direction dim = 3;
141 
142  //- Rank of uint32_t is 0
143  static constexpr direction rank = 0;
144 
145  //- Number of components in uint32_t is 1
146  static constexpr direction nComponents = 1;
148 
149  // Static Data Members
150 
151  static const char* const typeName;
152  static const char* const componentNames[];
153  static const uint32_t zero;
154  static const uint32_t one;
155  static const uint32_t min;
156  static const uint32_t max;
157  static const uint32_t rootMax;
158  static const uint32_t rootMin;
159 
160 
161  // Constructors
162 
163  //- Copy construct from primitive
164  explicit pTraits(uint32_t val) noexcept
165  :
166  p_(val)
167  {}
168 
169  //- Read construct from Istream
170  explicit pTraits(Istream& is);
172 
173  // Member Functions
174 
175  //- Return the value
176  operator uint32_t() const noexcept
177  {
178  return p_;
179  }
180 
181  //- Access the value
182  operator uint32_t&() noexcept
183  {
184  return p_;
185  }
186 };
189 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
190 
191 } // End namespace Foam
192 
193 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
194 
195 #endif
197 // ************************************************************************* //
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.
Definition: pTraits.H:50
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:125
pTraits(const Base &obj)
Copy construct from base class.
Definition: pTraits.H:61
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:52
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:71
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:76
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
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:58
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:57