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  uint8IO.C
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #ifndef primitives_uint8_H
39 #define primitives_uint8_H
40 
41 #include <cstdint>
42 #include <climits>
43 #include <cstdlib>
44 
45 #include "direction.H"
46 #include "pTraits.H"
47 #include "word.H"
48 
49 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50 
51 namespace Foam
52 {
53 
54 // Forward Declarations
55 class Istream;
56 class Ostream;
57 
58 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
59 
60 //- A word representation of uint8 value
61 inline word name(const uint8_t val)
62 {
63  return word(std::to_string(int(val)), false); // Needs no stripping
64 }
65 
66 
67 //- A word representation of uint8 value
68 template<>
69 struct nameOp<uint8_t>
70 {
71  word operator()(const uint8_t val) const
72  {
73  return word(std::to_string(int(val)), false); // Needs no stripping
74  }
75 };
76 
77 
78 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
79 
80 //- Read uint8_t from stream.
81 uint8_t readUint8(Istream& is);
82 
83 // IO operators are identical to direction, which is uint8_t
84 
85 
86 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
87 
88 //- Template specialization for pTraits<uint8_t>
89 template<>
90 class pTraits<uint8_t>
91 {
92  uint8_t p_;
93 
94 public:
95 
96  // Typedefs
97 
98  //- Component type
99  typedef uint8_t cmptType;
100 
101 
102  // Member Constants
103 
104  //- Dimensionality of space
105  static constexpr direction dim = 3;
106 
107  //- Rank of uint8_t is 0
108  static constexpr direction rank = 0;
109 
110  //- Number of components in uint8_t is 1
111  static constexpr direction nComponents = 1;
112 
113 
114  // Static Data Members
115 
116  static const char* const typeName;
117  static const char* const componentNames[];
118  static const uint8_t zero;
119  static const uint8_t one;
120  static const uint8_t min;
121  static const uint8_t max;
122  static const uint8_t rootMax;
123  static const uint8_t rootMin;
124 
125 
126  // Constructors
127 
128  //- Copy construct from primitive
129  explicit pTraits(const uint8_t& val) noexcept;
130 
131  //- Read construct from Istream
132  explicit pTraits(Istream& is);
133 
134 
135  // Member Functions
136 
137  //- Access to the value
138  operator uint8_t() const
139  {
140  return p_;
141  }
142 
143  //- Access to the value
144  operator uint8_t&()
145  {
146  return p_;
147  }
148 };
149 
150 
151 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
152 
153 } // End namespace Foam
154 
155 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
156 
157 #endif
158 
159 // ************************************************************************* //
Foam::pTraits::pTraits
pTraits(const Base &obj)
Copy construct from base class.
Definition: pTraits.H:65
Foam::pTraits< uint8_t >::zero
static const uint8_t zero
Definition: uint8.H:118
Foam::pTraits< uint8_t >::cmptType
uint8_t cmptType
Component type.
Definition: uint8.H:99
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::nameOp< uint8_t >::operator()
word operator()(const uint8_t val) const
Definition: uint8.H:71
Foam::readUint8
uint8_t readUint8(Istream &is)
Read uint8_t from stream.
Definition: uint8IO.C:33
Foam::pTraits< uint8_t >::min
static const uint8_t min
Definition: uint8.H:120
Foam::pTraits< uint8_t >::typeName
static const char *const typeName
Definition: uint8.H:116
Foam::pTraits< uint8_t >::one
static const uint8_t one
Definition: uint8.H:119
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::nameOp
Extract name (as a word) from an object, typically using its name() method.
Definition: word.H:237
pTraits.H
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
direction.H
Direction is an 8-bit unsigned integer type used to represent Cartesian directions,...
Foam::pTraits< uint8_t >::rootMin
static const uint8_t rootMin
Definition: uint8.H:123
Foam::pTraits
A traits class, which is primarily used for primitives.
Definition: pTraits.H:56
Foam::pTraits< uint8_t >::rootMax
static const uint8_t rootMax
Definition: uint8.H:122
Foam::direction
uint8_t direction
Definition: direction.H:52
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
word.H
Foam::pTraits< uint8_t >::max
static const uint8_t max
Definition: uint8.H:121