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