uint64.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  uint64_t
29 
30 Description
31  64bit unsigned integer
32 
33 SourceFiles
34  uint64.C
35  uint64IO.C
36 
37 \*---------------------------------------------------------------------------*/
38 
39 #ifndef uint64_H
40 #define uint64_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 // Forward Declarations
56 class Istream;
57 class Ostream;
58 
59 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
60 
61 //- A word representation of uint64 value
62 inline word name(const uint64_t val)
63 {
64  return word(std::to_string(val), false); // Needs no stripping
65 }
66 
67 
68 //- A word representation of uint64 value
69 template<>
70 struct nameOp<uint64_t>
71 {
72  word operator()(const uint64_t val) const
73  {
74  return word(std::to_string(val), false); // Needs no stripping
75  }
76 };
77 
78 
79 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
80 
81 //- Read uint64_t from stream.
82 uint64_t readUint64(Istream& is);
83 
84 //- Parse entire buffer as uint64_t, skipping leading/trailing whitespace.
85 // \return Parsed value or FatalIOError on any problem
86 uint64_t readUint64(const char* buf);
87 
88 //- Parse entire string as uint64_t, skipping leading/trailing whitespace.
89 // \return Parsed value or FatalIOError on any problem
90 inline uint64_t readUint64(const std::string& str)
91 {
92  return readUint64(str.c_str());
93 }
94 
95 //- Parse entire buffer as uint64_t, skipping leading/trailing whitespace.
96 // \return True if successful.
97 bool readUint64(const char* buf, uint64_t& val);
98 
99 //- Parse entire string as uint64_t, skipping leading/trailing whitespace.
100 // \return True if successful.
101 inline bool readUint64(const std::string& str, uint64_t& val)
102 {
103  return readUint64(str.c_str(), val);
104 }
105 
106 //- Same as readUint64
107 // \return True if successful.
108 inline bool read(const char* buf, uint64_t& val)
109 {
110  return readUint64(buf, val);
111 }
112 
113 //- Same as readUint64
114 // \return True if successful.
115 inline bool read(const std::string& str, uint64_t& val)
116 {
117  return readUint64(str, val);
118 }
119 
120 
121 Istream& operator>>(Istream& is, uint64_t& val);
122 Ostream& operator<<(Ostream& os, const uint64_t val);
123 
124 // On Darwin:
125 // unsigned long is not unambiguously (uint32_t | uint64_t)
126 // - explicitly resolve for output
127 #ifdef __APPLE__
128  Ostream& operator<<(Ostream& os, const unsigned long val);
129 #endif
130 
131 
132 //- Template specialization for pTraits<uint64_t>
133 template<>
134 class pTraits<uint64_t>
135 {
136  uint64_t p_;
137 
138 public:
139 
140  // Typedefs
141 
142  //- Component type
143  typedef uint64_t cmptType;
144 
145 
146  // Member Constants
147 
148  //- Dimensionality of space
149  static constexpr direction dim = 3;
150 
151  //- Rank of uint64_t is 0
152  static constexpr direction rank = 0;
153 
154  //- Number of components in uint64_t is 1
155  static constexpr direction nComponents = 1;
156 
157 
158  // Static Data Members
159 
160  static const char* const typeName;
161  static const char* const componentNames[];
162  static const uint64_t zero;
163  static const uint64_t one;
164  static const uint64_t min;
165  static const uint64_t max;
166  static const uint64_t rootMax;
167  static const uint64_t rootMin;
168 
169 
170  // Constructors
171 
172  //- Copy construct from primitive
173  explicit pTraits(const uint64_t& val) noexcept;
174 
175  //- Read construct from Istream
176  explicit pTraits(Istream& is);
177 
178 
179  // Member Functions
180 
181  //- Access to the value
182  operator uint64_t() const noexcept
183  {
184  return p_;
185  }
186 
187  //- Access to the value
188  operator uint64_t&() noexcept
189  {
190  return p_;
191  }
192 };
193 
194 
195 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
196 
197 } // End namespace Foam
198 
199 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
200 
201 #endif
202 
203 // ************************************************************************* //
Foam::pTraits::pTraits
pTraits(const Base &obj)
Copy construct from base class.
Definition: pTraits.H:65
Foam::readUint64
uint64_t readUint64(Istream &is)
Read uint64_t from stream.
Definition: uint64IO.C:80
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::pTraits< uint64_t >::min
static const uint64_t min
Definition: uint64.H:164
Foam::pTraits< uint64_t >::rootMin
static const uint64_t rootMin
Definition: uint64.H:167
Foam::read
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition: int32.H:108
Foam::operator>>
Istream & operator>>(Istream &, directionInfo &)
Definition: directionInfo.C:230
Foam::pTraits< uint64_t >::cmptType
uint64_t cmptType
Component type.
Definition: uint64.H:143
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::nameOp
Extract name (as a word) from an object, typically using its name() method.
Definition: word.H:237
Foam::pTraits< uint64_t >::one
static const uint64_t one
Definition: uint64.H:163
os
OBJstream os(runTime.globalPath()/outputName)
pTraits.H
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
direction.H
Direction is an 8-bit unsigned integer type used to represent Cartesian directions,...
Foam::pTraits< uint64_t >::rootMax
static const uint64_t rootMax
Definition: uint64.H:166
Foam::pTraits
A traits class, which is primarily used for primitives.
Definition: pTraits.H:56
Foam::direction
uint8_t direction
Definition: direction.H:52
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
word.H
Foam::pTraits< uint64_t >::zero
static const uint64_t zero
Definition: uint64.H:162
Foam::pTraits< uint64_t >::typeName
static const char *const typeName
Definition: uint64.H:160
Foam::nameOp< uint64_t >::operator()
word operator()(const uint64_t val) const
Definition: uint64.H:72
Foam::pTraits< uint64_t >::max
static const uint64_t max
Definition: uint64.H:165