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-2019 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 int64_H
40 #define int64_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 int64 value
61 inline word name(const int64_t val)
62 {
63  return word(std::to_string(val), false); // Needs no stripping
64 }
65 
66 
67 //- A word representation of int64 value
68 template<>
69 struct nameOp<int64_t>
70 {
71  inline word operator()(const int64_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 int64_t from stream
81 int64_t readInt64(Istream& is);
82 
83 //- Parse entire buffer as a int64_t, skipping leading/trailing whitespace.
84 // \return Parsed value or FatalIOError on any problem
85 int64_t readInt64(const char* buf);
86 
87 //- Parse entire string as a int64_t, skipping leading/trailing whitespace.
88 // \return Parsed value or FatalIOError on any problem
89 inline int64_t readInt64(const std::string& str)
90 {
91  return readInt64(str.c_str());
92 }
93 
94 //- Read entire buffer as a int64_t, skipping leading/trailing whitespace.
95 // \return True if successful.
96 bool readInt64(const char* buf, int64_t& val);
97 
98 //- Read entire string as a int64_t, skipping leading/trailing whitespace.
99 // \return True if successful.
100 inline bool readInt64(const std::string& str, int64_t& val)
101 {
102  return readInt64(str.c_str(), val);
103 }
104 
105 //- Same as readInt64
106 // \return True if successful.
107 inline bool read(const char* buf, int64_t& val)
108 {
109  return readInt64(buf, val);
110 }
111 
112 //- Same as readInt64
113 // \return True if successful.
114 inline bool read(const std::string& str, int64_t& val)
115 {
116  return readInt64(str, val);
117 }
118 
119 
120 Istream& operator>>(Istream& is, int64_t& val);
121 Ostream& operator<<(Ostream& os, const int64_t val);
122 
123 // On Darwin:
124 // long is not unambiguously (int32_t | int64_t)
125 // - explicitly resolve for input and output
126 #if defined(__APPLE__)
127  Istream& operator>>(Istream& is, long& val);
128  Ostream& operator<<(Ostream& os, const long val);
129 #endif
130 
131 
132 //- Template specialization for pTraits<int64_t>
133 template<>
134 class pTraits<int64_t>
135 {
136  int64_t p_;
137 
138 public:
139 
140  //- Component type
141  typedef int64_t cmptType;
142 
143  //- Magnitude type
144  typedef int64_t magType;
145 
146 
147  // Member constants
148 
149  //- Dimensionality of space
150  static constexpr direction dim = 3;
151 
152  //- Rank of int64_t is 0
153  static constexpr direction rank = 0;
154 
155  //- Number of components in int64_t is 1
156  static constexpr direction nComponents = 1;
157 
158 
159  // Static data members
160 
161  static const char* const typeName;
162  static const char* const componentNames[];
163  static const int64_t zero;
164  static const int64_t one;
165  static const int64_t min;
166  static const int64_t max;
167  static const int64_t rootMax;
168  static const int64_t rootMin;
169 
170 
171  // Constructors
172 
173  //- Copy construct from primitive
174  explicit pTraits(const int64_t& val);
175 
176  //- Read construct from Istream
177  pTraits(Istream& is);
178 
179 
180  // Member Functions
181 
182  //- Access to the value
183  operator int64_t() const
184  {
185  return p_;
186  }
187 
188  //- Access to the value
189  operator int64_t&()
190  {
191  return p_;
192  }
193 };
194 
195 
196 inline int64_t mag(const int64_t val)
197 {
198  return ::labs(val);
199 }
200 
201 
202 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
203 
204 } // End namespace Foam
205 
206 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
207 
208 #endif
209 
210 // ************************************************************************* //
Foam::val
label ListType::const_reference val
Definition: ListOps.H:407
Foam::nameOp< int64_t >::operator()
word operator()(const int64_t val) const
Definition: int64.H:71
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::pTraits< int64_t >::min
static const int64_t min
Definition: int64.H:165
Foam::read
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition: int32.H:108
Foam::pTraits< int64_t >::rootMax
static const int64_t rootMax
Definition: int64.H:167
Foam::operator>>
Istream & operator>>(Istream &, directionInfo &)
Definition: directionInfo.C:228
Foam::pTraits< int64_t >::zero
static const int64_t zero
Definition: int64.H:163
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::pTraits< int64_t >::max
static const int64_t max
Definition: int64.H:166
Foam::pTraits::pTraits
pTraits(const PrimitiveType &p)
Construct from primitive.
Definition: pTraits.H:62
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
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
Traits class for primitives.
Definition: pTraits.H:52
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Foam::pTraits< int64_t >::magType
int64_t magType
Magnitude type.
Definition: int64.H:144
Foam::direction
uint8_t direction
Definition: direction.H:47
Foam::pTraits< int64_t >::rootMin
static const int64_t rootMin
Definition: int64.H:168
Foam::pTraits< int64_t >::one
static const int64_t one
Definition: int64.H:164
word.H
Foam::pTraits< int64_t >::cmptType
int64_t cmptType
Component type.
Definition: int64.H:141
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &)
Definition: boundaryPatch.C:102
Foam::pTraits< int64_t >::typeName
static const char *const typeName
Definition: int64.H:161
Foam::readInt64
int64_t readInt64(Istream &is)
Read int64_t from stream.
Definition: int64IO.C:112