P4C
The P4 Compiler
Loading...
Searching...
No Matches
pointer_wrapper.h
1
19
#ifndef BF_P4C_LIB_POINTER_WRAPPER_H_
20
#define BF_P4C_LIB_POINTER_WRAPPER_H_
21
22
/* a pointer that inherits const-ness from its context (so is a const T * if it is itself
23
* const and is a (non-const) T * if it is not const. It is incidentally non-copyable or movable,
24
* as that would result in losing the const-ness. */
25
template
<
class
T>
26
class
pointer_wrap
{
27
T *ptr;
28
29
public
:
30
pointer_wrap
() : ptr(
nullptr
) {}
31
pointer_wrap
(
pointer_wrap
&a) : ptr(a.ptr) {}
// NOLINT(runtime/explicit)
32
pointer_wrap
(T *p) : ptr(p) {}
// NOLINT(runtime/explicit)
33
pointer_wrap
(
const
pointer_wrap
&) =
delete
;
34
pointer_wrap
(
pointer_wrap
&&) =
delete
;
35
explicit
operator
bool() {
return
ptr !=
nullptr
; }
36
T *operator=(T *p) {
return
ptr = p; }
37
T *operator->() {
return
ptr; }
38
const
T *operator->()
const
{
return
ptr; }
39
T &operator*() {
return
*ptr; }
40
const
T &operator*()
const
{
return
*ptr; }
41
operator
T *() {
return
ptr; }
42
operator
const
T *()
const
{
return
ptr; }
43
};
44
45
#endif
/* BF_P4C_LIB_POINTER_WRAPPER_H_ */
pointer_wrap
Definition
pointer_wrapper.h:26
backends
tofino
bf-p4c
lib
pointer_wrapper.h
Generated by
1.12.0