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 #define __STDC_LIMIT_MACROS
40 #include <stdint.h>
41 #include <climits>
42 #include <cstdlib>
43 
44 #include "word.H"
45 #include "pTraits.H"
46 #include "direction.H"
47 
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 
50 namespace Foam
51 {
52 
53 class Istream;
54 class Ostream;
55 
56 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
57 
58 //- Return a word representation of an int32
59 word name(const int32_t);
60 
61 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
62 
63 int32_t readInt32(Istream&);
64 bool read(const char*, int32_t&);
65 Istream& operator>>(Istream&, int32_t&);
66 Ostream& operator<<(Ostream&, const int32_t);
67 
68 // On 32bit OSs long is not unambiguously int32_t (or int64_t) causing problems
69 // for IO operator resolution.
70 // This problem is avoided by explicitly defining the following operators:
71 #if WM_ARCH_OPTION == 32
72  Istream& operator>>(Istream&, long&);
73  Ostream& operator<<(Ostream&, const long);
74 #endif
75 
76 
77 //- Template specialization for pTraits<int32_t>
78 template<>
79 class pTraits<int32_t>
80 {
81  int32_t p_;
82 
83 public:
84 
85  //- Component type
86  typedef int32_t cmptType;
87 
88 
89  // Member constants
90 
91  //- Dimensionality of space
92  static const direction dim = 3;
93 
94  //- Rank of int32_t is 0
95  static const direction rank = 0;
96 
97  //- Number of components in int32_t is 1
98  static const direction nComponents = 1;
99 
100 
101  // Static data members
102 
103  static const char* const typeName;
104  static const char* const componentNames[];
105  static const int32_t zero;
106  static const int32_t one;
107  static const int32_t min;
108  static const int32_t max;
109  static const int32_t rootMax;
110  static const int32_t rootMin;
111 
112 
113  // Constructors
114 
115  //- Construct from primitive
116  explicit pTraits(const int32_t&);
117 
118  //- Construct from Istream
119  pTraits(Istream&);
120 
121 
122  // Member Functions
123 
124  //- Access to the int32_t value
125  operator int32_t() const
126  {
127  return p_;
128  }
129 
130  //- Access to the int value
131  operator int32_t&()
132  {
133  return p_;
134  }
135 };
136 
137 
138 inline int32_t mag(const int32_t l)
139 {
140  return ::abs(l);
141 }
142 
143 
144 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
145 
146 } // End namespace Foam
147 
148 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
149 
150 #endif
151 
152 // ************************************************************************* //
uint8_t direction
Definition: direction.H:46
static const int32_t min
Definition: int32.H:107
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:109
Traits class for primitives.
Definition: pTraits.H:50
static const char *const typeName
Definition: int32.H:103
static const int32_t one
Definition: int32.H:106
static const int32_t zero
Definition: int32.H:105
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:108
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:86
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:110