int32.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 | Copyright (C) 2014-2016 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 
76 //- Template specialization for pTraits<int32_t>
77 template<>
78 class pTraits<int32_t>
79 {
80  int32_t p_;
81 
82 public:
83 
84  //- Component type
85  typedef int32_t cmptType;
86 
87 
88  // Member constants
89 
90  //- Dimensionality of space
91  static const direction dim = 3;
92 
93  //- Rank of int32_t is 0
94  static const direction rank = 0;
95 
96  //- Number of components in int32_t is 1
97  static const direction nComponents = 1;
98 
99 
100  // Static data members
101 
102  static const char* const typeName;
103  static const char* const componentNames[];
104  static const int32_t zero;
105  static const int32_t one;
106  static const int32_t min;
107  static const int32_t max;
108  static const int32_t rootMax;
109  static const int32_t rootMin;
110 
111 
112  // Constructors
113 
114  //- Construct from primitive
115  explicit pTraits(const int32_t&);
116 
117  //- Construct from Istream
118  pTraits(Istream&);
119 
120 
121  // Member Functions
122 
123  //- Access to the int32_t value
124  operator int32_t() const
125  {
126  return p_;
127  }
128 
129  //- Access to the int value
130  operator int32_t&()
131  {
132  return p_;
133  }
134 };
135 
136 
137 inline int32_t mag(const int32_t l)
138 {
139  return ::abs(l);
140 }
141 
142 
143 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
144 
145 } // End namespace Foam
146 
147 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
148 
149 #endif
150 
151 // ************************************************************************* //
static const int32_t min
Definition: int32.H:106
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:108
Traits class for primitives.
Definition: pTraits.H:50
static const char *const typeName
Definition: int32.H:102
static const int32_t one
Definition: int32.H:105
static const int32_t zero
Definition: int32.H:104
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:107
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:85
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:109