WPILibC++ 2025.2.1
Loading...
Searching...
No Matches
Value.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 "hal/Types.h"
8
9/** HAL data types. */
11 /** Unassigned type. */
13 /** Boolean. */
15 /** Double. */
16 HAL_DOUBLE = 0x02,
17 /** Enum. */
18 HAL_ENUM = 0x04,
19 /** Int. */
20 HAL_INT = 0x08,
21 /** Long. */
22 HAL_LONG = 0x10,
23};
24
25/** HAL Entry Value. Note this is a typed union. */
26struct HAL_Value {
27 union {
29 int32_t v_enum;
30 int32_t v_int;
31 int64_t v_long;
32 double v_double;
35};
36
37#ifdef __cplusplus
38extern "C" {
39#endif
40/**
41 * Build a HAL boolean value.
42 *
43 * @param v value
44 * @return HAL value
45 */
47 struct HAL_Value value;
48 value.type = HAL_BOOLEAN;
49 value.data.v_boolean = v;
50 return value;
51}
52
53/**
54 * Build a HAL enum value.
55 *
56 * @param v value
57 * @return HAL value
58 */
59inline struct HAL_Value HAL_MakeEnum(int v) {
60 struct HAL_Value value;
61 value.type = HAL_ENUM;
62 value.data.v_enum = v;
63 return value;
64}
65
66/**
67 * Build a HAL int value.
68 *
69 * @param v value
70 * @return HAL value
71 */
72inline struct HAL_Value HAL_MakeInt(int v) {
73 struct HAL_Value value;
74 value.type = HAL_INT;
75 value.data.v_int = v;
76 return value;
77}
78
79/**
80 * Build a HAL long value.
81 *
82 * @param v value
83 * @return HAL value
84 */
85inline struct HAL_Value HAL_MakeLong(int64_t v) {
86 struct HAL_Value value;
87 value.type = HAL_LONG;
88 value.data.v_long = v;
89 return value;
90}
91
92/**
93 * Build a HAL double value.
94 *
95 * @param v value
96 * @return HAL value
97 */
98inline struct HAL_Value HAL_MakeDouble(double v) {
99 struct HAL_Value value;
100 value.type = HAL_DOUBLE;
101 value.data.v_double = v;
102 return value;
103}
104
105#ifdef __cplusplus
106} // extern "C"
107#endif
struct HAL_Value HAL_MakeBoolean(HAL_Bool v)
Build a HAL boolean value.
Definition Value.h:46
struct HAL_Value HAL_MakeDouble(double v)
Build a HAL double value.
Definition Value.h:98
struct HAL_Value HAL_MakeEnum(int v)
Build a HAL enum value.
Definition Value.h:59
struct HAL_Value HAL_MakeInt(int v)
Build a HAL int value.
Definition Value.h:72
struct HAL_Value HAL_MakeLong(int64_t v)
Build a HAL long value.
Definition Value.h:85
HAL_Type
HAL data types.
Definition Value.h:10
@ HAL_DOUBLE
Double.
Definition Value.h:16
@ HAL_LONG
Long.
Definition Value.h:22
@ HAL_UNASSIGNED
Unassigned type.
Definition Value.h:12
@ HAL_ENUM
Enum.
Definition Value.h:18
@ HAL_BOOLEAN
Boolean.
Definition Value.h:14
@ HAL_INT
Int.
Definition Value.h:20
int32_t HAL_Bool
Definition Types.h:73
HAL Entry Value.
Definition Value.h:26
union HAL_Value::@76 data
double v_double
Definition Value.h:32
int64_t v_long
Definition Value.h:31
HAL_Bool v_boolean
Definition Value.h:28
int32_t v_int
Definition Value.h:30
enum HAL_Type type
Definition Value.h:34
int32_t v_enum
Definition Value.h:29