P4C
The P4 Compiler
Loading...
Searching...
No Matches
hex.h
1
/*
2
Copyright 2013-present Barefoot Networks, Inc.
3
4
Licensed under the Apache License, Version 2.0 (the "License");
5
you may not use this file except in compliance with the License.
6
You may obtain a copy of the License at
7
8
http://www.apache.org/licenses/LICENSE-2.0
9
10
Unless required by applicable law or agreed to in writing, software
11
distributed under the License is distributed on an "AS IS" BASIS,
12
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
See the License for the specific language governing permissions and
14
limitations under the License.
15
*/
16
17
#ifndef LIB_HEX_H_
18
#define LIB_HEX_H_
19
20
#include <cstdint>
21
#include <iomanip>
22
#include <iostream>
23
#include <vector>
24
25
namespace
P4
{
26
27
class
hex
{
28
std::intmax_t val;
29
int
width;
30
char
fill;
31
32
public
:
33
explicit
hex
(intmax_t v,
int
w = 0,
char
f =
' '
) : val(v), width(w), fill(f) {}
34
explicit
hex
(
void
*v,
int
w = 0,
char
f =
' '
) : val((intmax_t)v), width(w), fill(f) {}
35
friend
std::ostream &operator<<(std::ostream &os,
const
hex
&h);
36
};
37
38
inline
std::ostream &operator<<(std::ostream &os,
const
hex
&h) {
39
auto
save = os.flags();
40
auto
save_fill = os.fill();
41
os << std::hex << std::setw(h.width) << std::setfill(h.fill) << h.val;
42
os.fill(save_fill);
43
os.flags(save);
44
return
os;
45
}
46
47
class
hexvec
{
48
void
*data;
49
size_t
elsize, len;
50
int
width;
51
char
fill;
52
53
public
:
54
template
<
typename
I>
55
hexvec
(I *d,
size_t
l,
int
w = 0,
char
f =
' '
)
56
: data(d), elsize(
sizeof
(I)), len(l), width(w), fill(f) {}
57
template
<
typename
T>
58
explicit
hexvec
(std::vector<T> &d,
int
w = 0,
char
f =
' '
)
59
: data(d.data()), elsize(
sizeof
(T)), len(d.size()), width(w), fill(f) {}
60
friend
std::ostream &operator<<(std::ostream &os,
const
hexvec
&h);
61
};
62
63
std::ostream &operator<<(std::ostream &os,
const
hexvec
&h);
64
65
}
// namespace P4
66
67
#endif
/* LIB_HEX_H_ */
P4::hex
Definition
hex.h:27
P4::hexvec
Definition
hex.h:47
P4
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition
applyOptionsPragmas.cpp:24
lib
hex.h
Generated by
1.12.0