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 -------------------------------------------------------------------------------
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  int64_t
29 
30 Description
31  64bit signed integer
32 
33 SourceFiles
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 
52 namespace Foam
53 {
54 
55 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
56 
57 //- A word representation of int64 value
58 inline 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
65 template<>
66 struct 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 
75 inline 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
84 int64_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
88 int64_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
92 inline 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.
99 bool readInt64(const char* buf, int64_t& val);
101 //- Read entire string as a int64_t, skipping leading/trailing whitespace.
102 // \return True if successful.
103 inline 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.
110 inline 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.
117 inline bool read(const std::string& str, int64_t& val)
118 {
119  return readInt64(str, val);
120 }
121 
122 
123 Istream& operator>>(Istream& is, int64_t& val);
124 Ostream& 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 #if defined(__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>
140 template<>
141 class pTraits<int64_t>
142 {
143  int64_t p_;
144 
145 public:
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  // Static Data Members
169 
170  static const char* const typeName;
171  static const char* const componentNames[];
172  static const int64_t zero;
173  static const int64_t one;
174  static const int64_t min;
175  static const int64_t max;
176  static const int64_t rootMax;
177  static const int64_t rootMin;
178 
180  // Constructors
181 
182  //- Copy construct from primitive
183  explicit pTraits(int64_t val) noexcept
184  :
185  p_(val)
186  {}
188  //- Read construct from Istream
189  explicit pTraits(Istream& is);
190 
191 
192  // Member Functions
193 
194  //- Return the value
195  operator int64_t() const noexcept { return p_; }
196 
197  //- Access the value
198  operator int64_t&() noexcept { return p_; }
199 };
200 
201 
202 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
204 } // End namespace Foam
206 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
208 #endif
210 // ************************************************************************* //
uint8_t direction
Definition: direction.H:46
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
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
int64_t readInt64(Istream &is)
Read int64_t from stream.
Definition: int64IO.C:74
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
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
const direction noexcept
Definition: Scalar.H:258
OBJstream os(runTime.globalPath()/outputName)
word operator()(const int64_t val) const
Definition: int64.H:68
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.
::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