Loading...
Searching...
No Matches
int32.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 int32_t
29
30Description
31 32bit signed integer
32
33SourceFiles
34 int32.C
35 int32IO.C
36
37\*---------------------------------------------------------------------------*/
38
39#ifndef Foam_primitives_int32_H
40#define Foam_primitives_int32_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 int32 value
58inline word name(const int32_t val)
59{
60 return word(std::to_string(val), false); // Needs no stripping
61}
62
63
64//- A word representation of int32 value
65template<>
66struct nameOp<int32_t>
67{
68 word operator()(const int32_t val) const
69 {
70 return word(std::to_string(val), false); // Needs no stripping
71 }
72};
73
74
75inline int32_t mag(const int32_t val)
76{
77 return ::abs(val);
78}
79
80
81// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
82
83//- Read int32_t from stream
84int32_t readInt32(Istream& is);
85
86//- Parse entire buffer as a int32_t, skipping leading/trailing whitespace.
87// \return Parsed value or FatalIOError on any problem
88int32_t readInt32(const char* buf);
89
90//- Parse entire string as a int32_t, skipping leading/trailing whitespace.
91// \return Parsed value or FatalIOError on any problem
92inline int32_t readInt32(const std::string& str)
93{
94 return readInt32(str.c_str());
95}
96
97//- Read entire buffer as a int32_t, skipping leading/trailing whitespace.
98// \return True if successful.
99bool readInt32(const char* buf, int32_t& val);
101//- Read entire string as a int32_t, skipping leading/trailing whitespace.
102// \return True if successful.
103inline bool readInt32(const std::string& str, int32_t& val)
104{
105 return readInt32(str.c_str(), val);
106}
107
108//- Same as readInt32
109// \return True if successful.
110inline bool read(const char* buf, int32_t& val)
111{
112 return readInt32(buf, val);
113}
114
115//- Same as readInt32
116// \return True if successful.
117inline bool read(const std::string& str, int32_t& val)
118{
119 return readInt32(str, val);
120}
121
122
123Istream& operator>>(Istream& is, int32_t& val);
124Ostream& operator<<(Ostream& os, const int32_t val);
125
126// 32bit compilation with long as int32_t
127// - resolve explicitly for input and output
128//
129// Test works for gcc, icc, llvm.
130#if (__SIZEOF_LONG__ == 4)
131 Istream& operator>>(Istream& is, long& val);
132 Ostream& operator<<(Ostream& os, const long val);
133#endif
134
135
136/*---------------------------------------------------------------------------*\
137 Specialization pTraits<int32_t>
138\*---------------------------------------------------------------------------*/
139
140//- Template specialization for pTraits<int32_t>
141template<>
142class pTraits<int32_t>
143{
144 int32_t p_;
145
146public:
147
148 // Typedefs
149
150 //- Component type
151 typedef int32_t cmptType;
152
153 //- Magnitude type
154 typedef int32_t magType;
155
156
157 // Member Constants
158
159 //- Dimensionality of space
160 static constexpr direction dim = 3;
161
162 //- Rank of int32_t is 0
163 static constexpr direction rank = 0;
165 //- Number of components in int32_t is 1
166 static constexpr direction nComponents = 1;
167
168
169 // Limits
170
171 static constexpr int32_t min_ = INT32_MIN;
172 static constexpr int32_t max_ = INT32_MAX;
173
174
175 // Static Data Members
176
177 static const char* const typeName;
178 static const char* const componentNames[];
179 static const int32_t zero;
180 static const int32_t one;
181 static const int32_t min;
182 static const int32_t max;
183 static const int32_t rootMax;
184 static const int32_t rootMin;
185
186
187 // Constructors
189 //- Copy construct from primitive
190 explicit pTraits(int32_t val) noexcept : p_(val) {}
191
192 //- Read construct from Istream
193 explicit pTraits(Istream& is);
194
195
196 // Member Functions
197
198 //- Return the value
199 operator int32_t() const noexcept { return p_; }
200
201 //- Access the value
202 operator int32_t&() noexcept { return p_; }
205
206// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
207
208} // End namespace Foam
210// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
212#endif
214// ************************************************************************* //
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 int32.H:209
static const char *const componentNames[]
Definition int32.H:26
static const int32_t one
Definition int32.H:212
int32_t cmptType
Component type.
Definition int32.H:175
int32_t magType
Magnitude type.
Definition int32.H:180
static const int32_t rootMax
Definition int32.H:215
static constexpr int32_t max_
Definition int32.H:204
static constexpr direction nComponents
Number of components in int32_t is 1.
Definition int32.H:198
static constexpr direction rank
Rank of int32_t is 0.
Definition int32.H:193
static constexpr direction dim
Dimensionality of space.
Definition int32.H:188
static const int32_t rootMin
Definition int32.H:216
static constexpr int32_t min_
Definition int32.H:203
pTraits(int32_t val) noexcept
Copy construct from primitive.
Definition int32.H:224
static const int32_t min
Definition int32.H:213
static const int32_t zero
Definition int32.H:211
static const int32_t max
Definition int32.H:214
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).
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Istream & operator>>(Istream &, directionInfo &)
int32_t readInt32(Istream &is)
Read int32_t from stream.
Definition int32IO.C:74
uint8_t direction
Definition direction.H:49
const direction noexcept
Definition scalarImpl.H:265
word operator()(const int32_t val) const
Definition int32.H:68
Extract name (as a word) from an object, typically using its name() method.
Definition word.H:341