uint8.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2020-2021 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Primitive
27  uint8_t
28 
29 Description
30  8bit unsigned integer
31 
32 SourceFiles
33  uint8.C
34 
35 \*---------------------------------------------------------------------------*/
36 
37 #ifndef Foam_primitives_uint8_H
38 #define Foam_primitives_uint8_H
39 
40 #include <cstdint>
41 #include <climits>
42 #include <cstdlib>
43 
44 #include "direction.H"
45 #include "pTraits.H"
46 #include "word.H"
47 
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 
50 namespace Foam
51 {
52 
53 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
54 
55 //- A word representation of uint8 value
56 inline word name(const uint8_t val)
57 {
58  return word(std::to_string(int(val)), false); // Needs no stripping
59 }
60 
61 
62 //- A word representation of uint8 value
63 template<>
64 struct nameOp<uint8_t>
65 {
66  word operator()(const uint8_t val) const
67  {
68  return word(std::to_string(int(val)), false); // Needs no stripping
69  }
70 };
71 
72 
73 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
74 
75 //- Read uint8_t from stream.
76 uint8_t readUint8(Istream& is);
77 
78 // IO operators are identical to direction, which is uint8_t
79 
80 
81 /*---------------------------------------------------------------------------*\
82  Specialization pTraits<uint8_t>
83 \*---------------------------------------------------------------------------*/
84 
85 //- Template specialization for pTraits<uint8_t>
86 template<>
87 class pTraits<uint8_t>
88 {
89  uint8_t p_;
90 
91 public:
92 
93  // Typedefs
94 
95  //- Component type
96  typedef uint8_t cmptType;
97 
98 
99  // Member Constants
100 
101  //- Dimensionality of space
102  static constexpr direction dim = 3;
103 
104  //- Rank of uint8_t is 0
105  static constexpr direction rank = 0;
106 
107  //- Number of components in uint8_t is 1
108  static constexpr direction nComponents = 1;
109 
111  // Static Data Members
112 
113  static const char* const typeName;
114  static const char* const componentNames[];
115  static const uint8_t zero;
116  static const uint8_t one;
117  static const uint8_t min;
118  static const uint8_t max;
119  static const uint8_t rootMax;
120  static const uint8_t rootMin;
121 
122 
123  // Constructors
124 
125  //- Copy construct from primitive
126  explicit pTraits(uint8_t val) noexcept
127  :
128  p_(val)
129  {}
131  //- Read construct from Istream
132  explicit pTraits(Istream& is);
133 
134 
135  // Member Functions
136 
137  //- Return the value
138  operator uint8_t() const noexcept
139  {
140  return p_;
141  }
142 
143  //- Access the value
144  operator uint8_t&() noexcept
145  {
146  return p_;
147  }
148 };
149 
150 
151 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
152 
153 } // End namespace Foam
154 
155 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
157 #endif
158 
159 // ************************************************************************* //
uint8_t direction
Definition: direction.H:46
uint8_t cmptType
Component type.
Definition: uint8.H:102
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:40
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
::Foam::direction nComponents(const expressions::valueTypeCode) noexcept
The number of components associated with given valueTypeCode.
Definition: exprTraits.C:40
Extract name (as a word) from an object, typically using its name() method.
Definition: word.H:340
pTraits(const Base &obj)
Copy construct from base class.
Definition: pTraits.H:86
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
A class for handling words, derived from Foam::string.
Definition: word.H:63
word operator()(const uint8_t val) const
Definition: uint8.H:66
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:26
const direction noexcept
Definition: Scalar.H:258
Direction is an 8-bit unsigned integer type used to represent Cartesian directions, components etc.
::Foam::direction rank(const expressions::valueTypeCode) noexcept
The vector-space rank associated with given valueTypeCode.
Definition: exprTraits.C:70
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:57
uint8_t readUint8(Istream &is)
Read uint8_t from stream.
Definition: uint8.C:47
Namespace for OpenFOAM.
A class representing the concept of 1 (one) that can be used to avoid manipulating objects known to b...
Definition: one.H:56