int32.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2014-2019 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Primitive
25  int32
26 
27 Description
28  32bit integer
29 
30 SourceFiles
31  int32.C
32  int32IO.C
33 
34 \*---------------------------------------------------------------------------*/
35 
36 #ifndef int32_H
37 #define int32_H
38 
39 #include <cstdint>
40 #include <climits>
41 #include <cstdlib>
42 
43 #include "word.H"
44 #include "pTraits.H"
45 #include "direction.H"
46 
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48 
49 namespace Foam
50 {
51 
52 class Istream;
53 class Ostream;
54 
55 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
56 
57 //- Return a word representation of an int32
58 word name(const int32_t);
59 
60 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
61 
62 int32_t readInt32(Istream&);
63 bool read(const char*, int32_t&);
64 Istream& operator>>(Istream&, int32_t&);
65 Ostream& operator<<(Ostream&, const int32_t);
66 
67 // On 32bit OSs long is not unambiguously int32_t (or int64_t) causing problems
68 // for IO operator resolution.
69 // This problem is avoided by explicitly defining the following operators:
70 #if WM_ARCH_OPTION == 32
71  Istream& operator>>(Istream&, long&);
72  Ostream& operator<<(Ostream&, const long);
73 #endif
74 
75 inline void writeEntry(Ostream& os, const int32_t value)
76 {
77  os << value;
78 }
79 
80 
81 //- Template specialization for pTraits<int32_t>
82 template<>
83 class pTraits<int32_t>
84 {
85  int32_t p_;
86 
87 public:
88 
89  //- Component type
90  typedef int32_t cmptType;
91 
92 
93  // Member constants
94 
95  //- Dimensionality of space
96  static const direction dim = 3;
97 
98  //- Rank of int32_t is 0
99  static const direction rank = 0;
100 
101  //- Number of components in int32_t is 1
102  static const direction nComponents = 1;
103 
104 
105  // Static Data Members
106 
107  static const char* const typeName;
108  static const char* const componentNames[];
109  static const int32_t zero;
110  static const int32_t one;
111  static const int32_t min;
112  static const int32_t max;
113  static const int32_t rootMax;
114  static const int32_t rootMin;
115 
116 
117  // Constructors
118 
119  //- Construct from primitive
120  explicit pTraits(const int32_t&);
121 
122  //- Construct from Istream
123  pTraits(Istream&);
124 
125 
126  // Member Functions
127 
128  //- Access to the int32_t value
129  operator int32_t() const
130  {
131  return p_;
132  }
133 
134  //- Access to the int value
135  operator int32_t&()
136  {
137  return p_;
138  }
139 };
140 
141 
142 inline int32_t mag(const int32_t l)
143 {
144  return ::abs(l);
145 }
146 
147 
148 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
149 
150 } // End namespace Foam
151 
152 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
153 
154 #endif
155 
156 // ************************************************************************* //
static const int32_t min
Definition: int32.H:111
uint8_t direction
Definition: direction.H:45
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
static const int32_t rootMax
Definition: int32.H:113
Traits class for primitives.
Definition: pTraits.H:50
static const char *const typeName
Definition: int32.H:107
static const int32_t one
Definition: int32.H:110
static const int32_t zero
Definition: int32.H:109
bool read(const char *, int32_t &)
Definition: int32IO.C:85
int32_t readInt32(Istream &)
Definition: int32IO.C:76
Istream & operator>>(Istream &, directionInfo &)
static const int32_t max
Definition: int32.H:112
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
Direction is an 8-bit unsigned integer type used to represent the Cartesian directions etc...
int32_t cmptType
Component type.
Definition: int32.H:90
Ostream & operator<<(Ostream &, const ensightPart &)
pTraits(const PrimitiveType &p)
Construct from primitive.
Definition: pTraits.H:60
dimensioned< scalar > mag(const dimensioned< Type > &)
Namespace for OpenFOAM.
static const int32_t rootMin
Definition: int32.H:114