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-2015 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 #ifndef UINT32_MIN
49 #define UINT32_MIN 0
50 #endif
51 
52 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
53 
54 namespace Foam
55 {
56 
57 class Istream;
58 class Ostream;
59 
60 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
61 
62 //- Return a word representation of an int32
63 word name(const int32_t);
64 
65 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
66 
67 int32_t readInt32(Istream&);
68 bool read(const char*, int32_t&);
69 Istream& operator>>(Istream&, int32_t&);
70 Ostream& operator<<(Ostream&, const int32_t);
71 
72 // On 32bit OSs long is not unambiguously int32_t (or int64_t) causing problems
73 // for IO operator resolution.
74 // This problem is avoided by explicitly defining the following operators:
75 #if WM_ARCH_OPTION == 32
76  Istream& operator>>(Istream&, long&);
77  Ostream& operator<<(Ostream&, const long);
78 #endif
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  // Member constants
93 
94  enum
95  {
96  dim = 3,
97  rank = 0,
98  nComponents = 1
99  };
100 
101 
102  // Static data members
103 
104  static const char* const typeName;
105  static const char* componentNames[];
106  static const int32_t zero;
107  static const int32_t one;
108  static const int32_t min;
109  static const int32_t max;
110  static const int32_t rootMax;
111  static const int32_t rootMin;
112 
113 
114  // Constructors
115 
116  //- Construct from primitive
117  explicit pTraits(const int32_t&);
118 
119  //- Construct from Istream
120  pTraits(Istream&);
121 
122 
123  // Member Functions
124 
125  //- Access to the int32_t value
126  operator int32_t() const
127  {
128  return p_;
129  }
130 
131  //- Access to the int value
132  operator int32_t&()
133  {
134  return p_;
135  }
136 };
137 
138 
139 inline int32_t mag(const int32_t l)
140 {
141  return ::abs(l);
142 }
143 
144 
145 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
146 
147 } // End namespace Foam
148 
149 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
150 
151 #endif
152 
153 // ************************************************************************* //
Foam::pTraits< int32_t >::p_
int32_t p_
Definition: int32.H:85
Foam::pTraits< int32_t >::zero
static const int32_t zero
Definition: int32.H:106
Foam::read
bool read(const char *, int32_t &)
Definition: int32IO.C:87
Foam::pTraits< int32_t >::min
static const int32_t min
Definition: int32.H:108
Foam::pTraits< int32_t >::max
static const int32_t max
Definition: int32.H:109
Foam::mag
dimensioned< scalar > mag(const dimensioned< Type > &)
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:57
Foam::pTraits::pTraits
pTraits(const PrimitiveType &p)
Construct from primitive.
Definition: pTraits.H:60
Foam::pTraits< int32_t >::cmptType
int32_t cmptType
Component type.
Definition: int32.H:90
Foam::operator<<
Ostream & operator<<(Ostream &, const edgeMesh &)
Definition: edgeMeshIO.C:130
Foam::pTraits< int32_t >::one
static const int32_t one
Definition: int32.H:107
pTraits.H
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
direction.H
Direction is an integer type used to represent the Cartesian directions etc. Currently it is a typede...
Foam::pTraits< int32_t >::typeName
static const char *const typeName
Definition: int32.H:104
Foam::pTraits
Traits class for primitives.
Definition: pTraits.H:50
Foam::operator>>
Istream & operator>>(Istream &, edgeMesh &)
Definition: edgeMeshIO.C:141
Foam::pTraits< int32_t >::rootMin
static const int32_t rootMin
Definition: int32.H:111
word.H
Foam::readInt32
int32_t readInt32(Istream &)
Definition: int32IO.C:78
Foam::pTraits< int32_t >::rootMax
static const int32_t rootMax
Definition: int32.H:110
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47