WPILibC++ 2024.3.2
Types.h
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#pragma once
6
7#include <stdint.h>
8
9/**
10 * @defgroup hal_types Type Definitions
11 * @ingroup hal_capi
12 * @{
13 */
14
15#define HAL_kInvalidHandle 0
16
17typedef int32_t HAL_Handle;
18
20
22
24
26
28
30
32
34
36
38
40
42
44
46
48
50
52
54
56
58
60
62
64
66
68
70
72
73typedef int32_t HAL_Bool;
74
75#ifdef __cplusplus
76#define HAL_ENUM(name) enum name : int32_t
77#elif defined(__clang__)
78#define HAL_ENUM(name) \
79 enum name : int32_t; \
80 typedef enum name name; \
81 enum name : int32_t
82#else
83#define HAL_ENUM(name) \
84 typedef int32_t name; \
85 enum name
86#endif
87
88#ifdef __cplusplus
89namespace hal {
90
91/**
92 * A move-only C++ wrapper around a HAL handle.
93 * Does not ensure destruction.
94 */
95template <typename CType, int32_t CInvalid = HAL_kInvalidHandle>
96class Handle {
97 public:
98 Handle() = default;
99 /*implicit*/ Handle(CType val) : m_handle(val) {} // NOLINT
100
101 Handle(const Handle&) = delete;
102 Handle& operator=(const Handle&) = delete;
103
104 Handle(Handle&& rhs) : m_handle(rhs.m_handle) { rhs.m_handle = CInvalid; }
105
107 m_handle = rhs.m_handle;
108 rhs.m_handle = CInvalid;
109 return *this;
110 }
111
112 operator CType() const { return m_handle; } // NOLINT
113
114 private:
115 CType m_handle = CInvalid;
116};
117
118} // namespace hal
119#endif
120/** @} */
A move-only C++ wrapper around a HAL handle.
Definition: Types.h:96
Handle(Handle &&rhs)
Definition: Types.h:104
Handle & operator=(const Handle &)=delete
Handle(CType val)
Definition: Types.h:99
Handle()=default
Handle & operator=(Handle &&rhs)
Definition: Types.h:106
Handle(const Handle &)=delete
HAL_Handle HAL_CompressorHandle
Definition: Types.h:27
HAL_Handle HAL_CANHandle
Definition: Types.h:51
HAL_Handle HAL_CTREPCMHandle
Definition: Types.h:67
HAL_CANHandle HAL_PDPHandle
Definition: Types.h:63
HAL_Handle HAL_SerialPortHandle
Definition: Types.h:49
int32_t HAL_Bool
Definition: Types.h:73
HAL_Handle HAL_SolenoidHandle
Definition: Types.h:47
int32_t HAL_Handle
Definition: Types.h:17
HAL_Handle HAL_PortHandle
Definition: Types.h:19
HAL_Handle HAL_DMAHandle
Definition: Types.h:57
HAL_Handle HAL_AnalogTriggerHandle
Definition: Types.h:25
HAL_Handle HAL_SimDeviceHandle
Definition: Types.h:53
HAL_Handle HAL_AnalogOutputHandle
Definition: Types.h:23
HAL_Handle HAL_FPGAEncoderHandle
Definition: Types.h:37
HAL_Handle HAL_DigitalPWMHandle
Definition: Types.h:33
HAL_Handle HAL_GyroHandle
Definition: Types.h:39
HAL_Handle HAL_EncoderHandle
Definition: Types.h:35
HAL_Handle HAL_DutyCycleHandle
Definition: Types.h:59
HAL_Handle HAL_PowerDistributionHandle
Definition: Types.h:65
HAL_Handle HAL_InterruptHandle
Definition: Types.h:41
HAL_Handle HAL_DigitalHandle
Definition: Types.h:31
HAL_Handle HAL_CounterHandle
Definition: Types.h:29
HAL_Handle HAL_REVPHHandle
Definition: Types.h:71
HAL_Handle HAL_RelayHandle
Definition: Types.h:45
HAL_Handle HAL_AnalogInputHandle
Definition: Types.h:21
HAL_Handle HAL_NotifierHandle
Definition: Types.h:43
HAL_Handle HAL_REVPDHHandle
Definition: Types.h:69
HAL_Handle HAL_AddressableLEDHandle
Definition: Types.h:61
HAL_Handle HAL_SimValueHandle
Definition: Types.h:55
WPILib Hardware Abstraction Layer (HAL) namespace.
Definition: ChipObject.h:40