Loading...
Searching...
No Matches
int8.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) 2023 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
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
26Primitive
27 int8_t
28
29Description
30 8bit signed integer
31
32SourceFiles
33 int8.C
34
35\*---------------------------------------------------------------------------*/
36
37#ifndef Foam_primitives_int8_H
38#define Foam_primitives_int8_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
50namespace Foam
51{
52
53// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
55//- A word representation of uint8 value
56inline word name(const int8_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
63template<>
64struct nameOp<int8_t>
65{
66 word operator()(const int8_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 from stream (as label)
76Istream& operator>>(Istream& is, int8_t& val);
77
78//- Write to stream (as label)
79Ostream& operator<<(Ostream& os, const int8_t val);
80
81
82/*---------------------------------------------------------------------------*\
83 Specialization pTraits<int8_t>
84\*---------------------------------------------------------------------------*/
85
86//- Template specialization for pTraits<int8_t>
87template<>
88class pTraits<int8_t>
89{
90 int8_t p_;
91
92public:
93
94 // Typedefs
95
96 //- Component type
97 typedef int8_t cmptType;
98
99
100 // Member Constants
101
102 //- Dimensionality of space
103 static constexpr direction dim = 3;
104
105 //- Rank of int8_t is 0
106 static constexpr direction rank = 0;
107
108 //- Number of components in int8_t is 1
109 static constexpr direction nComponents = 1;
110
111
112 // Static Data Members
114 static const char* const typeName;
115 static const char* const componentNames[];
116 static const int8_t zero;
117 static const int8_t one;
118 static const int8_t min;
119 static const int8_t max;
120 static const int8_t rootMax;
121 static const int8_t rootMin;
122
124 // Limits
125
126 static constexpr int8_t min_ = INT8_MIN;
127 static constexpr int8_t max_ = INT8_MAX;
129
130 // Constructors
132 //- Copy construct from primitive
133 explicit pTraits(int8_t val) noexcept : p_(val) {}
135 //- Read construct from Istream
136 explicit pTraits(Istream& is);
137
138
139 // Member Functions
141 //- Return the value
142 operator int8_t() const noexcept { return p_; }
143
144 //- Access the value
145 operator int8_t&() noexcept { return p_; }
146};
147
148
149// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
150
151} // End namespace Foam
152
153// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
154
155#endif
156
157// ************************************************************************* //
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition Istream.H:60
static const char *const componentNames[]
Definition int8.H:27
static const int8_t min
Definition int8.H:132
static const int8_t zero
Definition int8.H:130
static constexpr int8_t min_
Definition int8.H:140
static const int8_t one
Definition int8.H:131
static const int8_t rootMin
Definition int8.H:135
static constexpr direction nComponents
Number of components in int8_t is 1.
Definition int8.H:123
static constexpr direction rank
Rank of int8_t is 0.
Definition int8.H:118
static constexpr int8_t max_
Definition int8.H:141
static constexpr direction dim
Dimensionality of space.
Definition int8.H:113
static const int8_t max
Definition int8.H:133
pTraits(int8_t val) noexcept
Copy construct from primitive.
Definition int8.H:149
static const int8_t rootMax
Definition int8.H:134
int8_t cmptType
Component type.
Definition int8.H:105
static const char *const typeName
Definition int8.H:128
pTraits(const Base &obj)
Copy construct from base class.
Definition pTraits.H:72
A class for handling words, derived from Foam::string.
Definition word.H:66
Direction is an 8-bit unsigned integer type used to represent Cartesian directions,...
OBJstream os(runTime.globalPath()/outputName)
auto & name
Namespace for OpenFOAM.
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces).
Istream & operator>>(Istream &, directionInfo &)
uint8_t direction
Definition direction.H:49
const direction noexcept
Definition scalarImpl.H:265
word operator()(const int8_t val) const
Definition int8.H:66
Extract name (as a word) from an object, typically using its name() method.
Definition word.H:341