Loading...
Searching...
No Matches
uint16.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) 2018-2025 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 uint16_t
29Description
30 16bit unsigned integer. I/O is done as an int32.
31
32SourceFiles
33 uint16.C
34
35\*---------------------------------------------------------------------------*/
36
37#ifndef Foam_primitives_uint16_H
38#define Foam_primitives_uint16_H
39
40#include <cstdint>
41
42#include "direction.H"
43#include "pTraits.H"
44#include "word.H"
45
46// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47
48namespace Foam
49{
50
51// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
53//- A word representation of uint16 value
54inline word name(const uint16_t val)
55{
56 return word(std::to_string(int(val)), false); // Needs no stripping
57}
58
59
60//- A word representation of uint16 value
61template<>
62struct nameOp<uint16_t>
63{
64 word operator()(const uint16_t val) const
65 {
66 return word(std::to_string(int(val)), false); // Needs no stripping
67 }
68};
69
70
71// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
72
73Istream& operator>>(Istream& is, uint16_t& val);
74Ostream& operator<<(Ostream& os, const uint16_t val);
75
76
77/*---------------------------------------------------------------------------*\
78 Specialization pTraits<uint16_t>
79\*---------------------------------------------------------------------------*/
80
81//- Template specialization for pTraits<uint16_t>
82template<>
83class pTraits<uint16_t>
84{
85 uint16_t p_;
86
87public:
88
89 // Typedefs
90
91 //- Component type
92 typedef uint16_t cmptType;
93
94
95 // Member Constants
97 //- Dimensionality of space
98 static constexpr direction dim = 3;
99
100 //- Rank of uint16_t is 0
101 static constexpr direction rank = 0;
102
103 //- Number of components in uint16_t is 1
104 static constexpr direction nComponents = 1;
105
106
107 // Limits
108
109 static constexpr uint16_t min_ = 0;
110 static constexpr uint16_t max_ = UINT16_MAX;
111
112
113 // Static Data Members
115 static const char* const typeName;
116 static const char* const componentNames[];
117 static const uint16_t zero;
118 static const uint16_t one;
119 static const uint16_t min;
120 static const uint16_t max;
121 static const uint16_t rootMax;
122 static const uint16_t rootMin;
123
124
125 // Constructors
126
127 //- Copy construct from primitive
128 explicit pTraits(uint16_t val) noexcept : p_(val) {}
130 //- Read construct from Istream
131 explicit pTraits(Istream& is);
133
134 // Member Functions
135
136 //- Return the value
137 operator uint16_t() const noexcept { return p_; }
138
139 //- Access the value
140 operator uint16_t&() noexcept { return p_; }
141};
142
143
144// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
146} // End namespace Foam
147
148// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
149
150#endif
151
152// ************************************************************************* //
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition Istream.H:60
static constexpr uint16_t max_
Definition uint16.H:120
static const char *const componentNames[]
Definition uint16.H:28
static const uint16_t rootMin
Definition uint16.H:132
static const uint16_t zero
Definition uint16.H:127
static const uint16_t max
Definition uint16.H:130
static const uint16_t rootMax
Definition uint16.H:131
static constexpr direction nComponents
Number of components in uint16_t is 1.
Definition uint16.H:114
static constexpr direction rank
Rank of uint16_t is 0.
Definition uint16.H:109
static constexpr direction dim
Dimensionality of space.
Definition uint16.H:104
pTraits(Istream &is)
Read construct from Istream.
static constexpr uint16_t min_
Definition uint16.H:119
static const uint16_t one
Definition uint16.H:128
uint16_t cmptType
Component type.
Definition uint16.H:96
static const uint16_t min
Definition uint16.H:129
pTraits(uint16_t val) noexcept
Copy construct from primitive.
Definition uint16.H:140
static const char *const typeName
Definition uint16.H:125
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 uint16_t val) const
Definition uint16.H:64
Extract name (as a word) from an object, typically using its name() method.
Definition word.H:341