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-2020 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 uint32_H
40 #define uint32_H
41 
42 #include <cstdint>
43 #include <climits>
44 #include <cstdlib>
45 
46 #include "word.H"
47 #include "pTraits.H"
48 #include "direction.H"
49 
50 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
51 
52 namespace Foam
53 {
54 
55 class Istream;
56 class Ostream;
57 
58 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
59 
60 //- A word representation of uint32 value
61 inline word name(const uint32_t val)
62 {
63  return word(std::to_string(val), false); // Needs no stripping
64 }
65 
66 //- A word representation of uint32 value
67 template<>
68 struct nameOp<uint32_t>
69 {
70  inline word operator()(const uint32_t val) const
71  {
72  return word(std::to_string(val), false); // Needs no stripping
73  }
74 };
75 
76 
77 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
78 
79 //- Read uint32_t from stream
80 uint32_t readUint32(Istream& is);
81 
82 //- Parse entire buffer as a uint32_t, skipping leading/trailing whitespace.
83 // \return Parsed value or FatalIOError on any problem
84 uint32_t readUint32(const char* buf);
85 
86 //- Parse entire string as a uint32_t, skipping leading/trailing whitespace.
87 // \return Parsed value or FatalIOError on any problem
88 inline uint32_t readUint32(const std::string& str)
89 {
90  return readUint32(str.c_str());
91 }
92 
93 //- Read entire buffer as a uint32_t, skipping leading/trailing whitespace.
94 // \return True if successful.
95 bool readUint32(const char* buf, uint32_t& val);
96 
97 //- Read entire string as a uint32_t, skipping leading/trailing whitespace.
98 // \return True if successful.
99 inline bool readUint32(const std::string& str, uint32_t& val)
100 {
101  return readUint32(str.c_str(), val);
102 }
103 
104 //- Same as readUint32
105 // \return True if successful.
106 inline bool read(const char* buf, uint32_t& val)
107 {
108  return readUint32(buf, val);
109 }
110 
111 //- Same as readUint32
112 // \return True if successful.
113 inline bool read(const std::string& str, uint32_t& val)
114 {
115  return readUint32(str, val);
116 }
117 
118 
119 Istream& operator>>(Istream& is, uint32_t& val);
120 Ostream& operator<<(Ostream& os, const uint32_t val);
121 
122 //- Template specialization for pTraits<uint32_t>
123 template<>
124 class pTraits<uint32_t>
125 {
126  uint32_t p_;
127 
128 public:
129 
130  // Typedefs
131 
132  //- Component type
133  typedef uint32_t cmptType;
134 
135 
136  // Member Constants
137 
138  //- Dimensionality of space
139  static constexpr direction dim = 3;
140 
141  //- Rank of uint32_t is 0
142  static constexpr direction rank = 0;
143 
144  //- Number of components in uint32_t is 1
145  static constexpr direction nComponents = 1;
146 
147 
148  // Static Data Members
149 
150  static const char* const typeName;
151  static const char* const componentNames[];
152  static const uint32_t zero;
153  static const uint32_t one;
154  static const uint32_t min;
155  static const uint32_t max;
156  static const uint32_t rootMax;
157  static const uint32_t rootMin;
158 
159 
160  // Constructors
161 
162  //- Copy construct from primitive
163  explicit pTraits(const uint32_t& val);
164 
165  //- Read construct from Istream
166  explicit pTraits(Istream& is);
167 
168 
169  // Member Functions
170 
171  //- Access to the value
172  operator uint32_t() const
173  {
174  return p_;
175  }
176 
177  //- Access to the value
178  operator uint32_t&()
179  {
180  return p_;
181  }
182 };
183 
184 
185 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
186 
187 } // End namespace Foam
188 
189 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
190 
191 #endif
192 
193 // ************************************************************************* //
Foam::pTraits< uint32_t >::max
static const uint32_t max
Definition: uint32.H:155
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::read
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition: int32.H:107
Foam::pTraits< uint32_t >::one
static const uint32_t one
Definition: uint32.H:153
Foam::operator>>
Istream & operator>>(Istream &, directionInfo &)
Definition: directionInfo.C:230
Foam::readUint32
uint32_t readUint32(Istream &is)
Read uint32_t from stream.
Definition: uint32IO.C:140
Foam::pTraits< uint32_t >::typeName
static const char *const typeName
Definition: uint32.H:150
Foam::pTraits< uint32_t >::rootMax
static const uint32_t rootMax
Definition: uint32.H:156
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Foam::nameOp< uint32_t >::operator()
word operator()(const uint32_t val) const
Definition: uint32.H:70
Foam::pTraits< uint32_t >::rootMin
static const uint32_t rootMin
Definition: uint32.H:157
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::pTraits::pTraits
pTraits(const PrimitiveType &p)
Copy construct from primitive.
Definition: pTraits.H:63
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::pTraits< uint32_t >::min
static const uint32_t min
Definition: uint32.H:154
Foam::nameOp
Extract name (as a word) from an object, typically using its name() method.
Definition: word.H:238
pTraits.H
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
direction.H
Direction is an 8-bit unsigned integer type used to represent the Cartesian directions etc.
Foam::pTraits< uint32_t >::cmptType
uint32_t cmptType
Component type.
Definition: uint32.H:133
Foam::pTraits
Traits class for primitives.
Definition: pTraits.H:54
Foam::direction
uint8_t direction
Definition: direction.H:47
word.H
Foam::pTraits< uint32_t >::zero
static const uint32_t zero
Definition: uint32.H:152