FreeFOAM The Cross-Platform CFD Toolkit
uLabel.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) 1991-2010 OpenCFD Ltd.
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 Typedef
25  Foam::uLabel
26 
27 Description
28  A uLabel is an unsigned label.
29 
30 SeeAlso
31  label.H
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #ifndef uLabel_H
36 #define uLabel_H
37 
38 #include <climits>
39 #include <cstdlib>
40 
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 
43 
44 #if FOAM_LABEL64
45 # define FOAM_ULABEL_MAX 18000000000000000000
46 #else
47 # define FOAM_ULABEL_MAX 4000000000
48 #endif
49 
50 
51 #if UINT_MAX > FOAM_ULABEL_MAX
52 
53 // Define uLabel as an unsigned int
54 
55 # undef FOAM_ULABEL_MAX
56 # define FOAM_ULABEL_MAX UINT_MAX
57 
58 # include <OpenFOAM/uint.H>
59 
60 namespace Foam
61 {
62  typedef unsigned int uLabel;
63 
64  static const uLabel uLabelMin = 0;
65  static const uLabel uLabelMax = UINT_MAX;
66 
67  inline uLabel readULabel(Istream& is)
68  {
69  return readUint(is);
70  }
71 
72 } // End namespace Foam
73 
74 
75 #elif ULONG_MAX > FOAM_ULABEL_MAX
76 
77 // Define uLabel as an unsigned long
78 
79 # undef FOAM_ULABEL_MAX
80 # define FOAM_ULABEL_MAX ULONG_MAX
81 
82 # include <OpenFOAM/uint.H>
83 # include <OpenFOAM/ulong.H>
84 
85 namespace Foam
86 {
87  typedef unsigned long uLabel;
88 
89  static const uLabel uLabelMin = 0;
90  static const uLabel uLabelMax = ULONG_MAX;
91 
92  inline uLabel readULabel(Istream& is)
93  {
94  return readUlong(is);
95  }
96 
97 } // End namespace Foam
98 
99 
100 #elif ULLONG_MAX > FOAM_ULABEL_MAX
101 
102 // Define uLabel as an unsigned long long
103 
104 # undef FOAM_ULABEL_MAX
105 
106 # error "Not implemented yet"
107 
108 #endif
109 
110 
111 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
112 
113 #include <OpenFOAM/pTraits.H>
114 #include <OpenFOAM/direction.H>
115 
116 namespace Foam
117 {
118 
119 //- template specialization for pTraits<uLabel>
120 template<>
121 class pTraits<uLabel>
122 {
123  uLabel p_;
124 
125 public:
126 
127  //- Component type
128  typedef uLabel cmptType;
129 
130  // Member constants
131 
132  enum
133  {
134  dim = 3, // Dimensionality of space
135  rank = 0, // Rank of uLabel is 0
136  nComponents = 1 // Number of components in uLabel is 1
137  };
138 
139 
140  // Static data members
142  static const char* const typeName;
143  static const char* componentNames[];
144  static const uLabel zero;
145  static const uLabel one;
146  static const uLabel max;
147  static const uLabel min;
148 
149 
150  // Constructors
151 
152  //- Construct from uLabel
153  pTraits(const uLabel ul)
154  {
155  p_ = ul;
156  }
157 
158  //- Construct from Istream
159  pTraits(Istream&);
160 
161 
162  // Member Functions
164  operator uLabel() const
165  {
166  return p_;
167  }
169  operator uLabel&()
170  {
171  return p_;
172  }
173 };
174 
175 
176 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
178 inline uLabel& setComponent(uLabel& l, const direction)
179 {
180  return l;
181 }
183 inline uLabel component(const uLabel l, const direction)
184 {
185  return l;
186 }
187 
188 
189 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
190 
191 } // End namespace Foam
192 
193 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
194 
195 #endif
196 
197 // ************************ vim: set sw=4 sts=4 et: ************************ //