WPILibC++ 2027.0.0-alpha-5
Loading...
Searching...
No Matches
FloatArrayTopic.hpp
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// THIS FILE WAS AUTO-GENERATED BY ./ntcore/generate_topics.py. DO NOT MODIFY
6
7#pragma once
8
9#include <stdint.h>
10
11#include <utility>
12#include <span>
13#include <string_view>
14#include <vector>
15
17#include "wpi/nt/Topic.hpp"
18#include "wpi/nt/ntcore_cpp.hpp"
19
20namespace wpi::util {
21template <typename T>
22class SmallVectorImpl;
23class json;
24} // namespace wpi
25
26namespace wpi::nt {
27
28class FloatArrayTopic;
29
30/**
31 * NetworkTables FloatArray subscriber.
32 */
34 public:
36 using ValueType = std::vector<float>;
37 using ParamType = std::span<const float>;
39
40 using SmallRetType = std::span<float>;
41 using SmallElemType = float;
43
44
46
47 /**
48 * Construct from a subscriber handle; recommended to use
49 * FloatArrayTopic::Subscribe() instead.
50 *
51 * @param handle Native handle
52 * @param defaultValue Default value
53 */
55 : Subscriber{handle},
56 m_defaultValue{defaultValue.begin(), defaultValue.end()} {}
57
58 /**
59 * Get the last published value.
60 * If no value has been published, returns the stored default value.
61 *
62 * @return value
63 */
64 ValueType Get() const {
65 return Get(m_defaultValue);
66 }
67
68 /**
69 * Get the last published value.
70 * If no value has been published, returns the passed defaultValue.
71 *
72 * @param defaultValue default value to return if no value has been published
73 * @return value
74 */
75 ValueType Get(ParamType defaultValue) const {
76 return ::wpi::nt::GetFloatArray(m_subHandle, defaultValue);
77 }
78
79 /**
80 * Get the last published value.
81 * If no value has been published, returns the stored default value.
82 *
83 * @param buf storage for returned value
84 * @return value
85 */
87 return Get(buf, m_defaultValue);
88 }
89
90 /**
91 * Get the last published value.
92 * If no value has been published, returns the passed defaultValue.
93 *
94 * @param buf storage for returned value
95 * @param defaultValue default value to return if no value has been published
96 * @return value
97 */
99 return wpi::nt::GetFloatArray(m_subHandle, buf, defaultValue);
100 }
101
102 /**
103 * Get the last published value along with its timestamp
104 * If no value has been published, returns the stored default value and a
105 * timestamp of 0.
106 *
107 * @return timestamped value
108 */
110 return GetAtomic(m_defaultValue);
111 }
112
113 /**
114 * Get the last published value along with its timestamp.
115 * If no value has been published, returns the passed defaultValue and a
116 * timestamp of 0.
117 *
118 * @param defaultValue default value to return if no value has been published
119 * @return timestamped value
120 */
122 return ::wpi::nt::GetAtomicFloatArray(m_subHandle, defaultValue);
123 }
124
125 /**
126 * Get the last published value along with its timestamp.
127 * If no value has been published, returns the stored default value and a
128 * timestamp of 0.
129 *
130 * @param buf storage for returned value
131 * @return timestamped value
132 */
135 return GetAtomic(buf, m_defaultValue);
136 }
137
138 /**
139 * Get the last published value along with its timestamp.
140 * If no value has been published, returns the passed defaultValue and a
141 * timestamp of 0.
142 *
143 * @param buf storage for returned value
144 * @param defaultValue default value to return if no value has been published
145 * @return timestamped value
146 */
152
153 /**
154 * Get an array of all value changes since the last call to ReadQueue.
155 * Also provides a timestamp for each value.
156 *
157 * @note The "poll storage" subscribe option can be used to set the queue
158 * depth.
159 *
160 * @return Array of timestamped values; empty array if no new changes have
161 * been published since the previous call.
162 */
163 std::vector<TimestampedValueType> ReadQueue() {
164 return ::wpi::nt::ReadQueueFloatArray(m_subHandle);
165 }
166
167 /**
168 * Get the corresponding topic.
169 *
170 * @return Topic
171 */
172 TopicType GetTopic() const;
173
174 private:
175 ValueType m_defaultValue;
176};
177
178/**
179 * NetworkTables FloatArray publisher.
180 */
182 public:
184 using ValueType = std::vector<float>;
185 using ParamType = std::span<const float>;
186
187 using SmallRetType = std::span<float>;
188 using SmallElemType = float;
189
191
193
194 /**
195 * Construct from a publisher handle; recommended to use
196 * FloatArrayTopic::Publish() instead.
197 *
198 * @param handle Native handle
199 */
200 explicit FloatArrayPublisher(NT_Publisher handle) : Publisher{handle} {}
201
202 /**
203 * Publish a new value.
204 *
205 * @param value value to publish
206 * @param time timestamp; 0 indicates current NT time should be used
207 */
208 void Set(ParamType value, int64_t time = 0) {
210 }
211
212 /**
213 * Publish a default value.
214 * On reconnect, a default value will never be used in preference to a
215 * published value.
216 *
217 * @param value value
218 */
222
223 /**
224 * Get the corresponding topic.
225 *
226 * @return Topic
227 */
228 TopicType GetTopic() const;
229};
230
231/**
232 * NetworkTables FloatArray entry.
233 *
234 * @note Unlike NetworkTableEntry, the entry goes away when this is destroyed.
235 */
237 public FloatArrayPublisher {
238 public:
242 using ValueType = std::vector<float>;
243 using ParamType = std::span<const float>;
244
245 using SmallRetType = std::span<float>;
246 using SmallElemType = float;
247
249
250 FloatArrayEntry() = default;
251
252 /**
253 * Construct from an entry handle; recommended to use
254 * FloatArrayTopic::GetEntry() instead.
255 *
256 * @param handle Native handle
257 * @param defaultValue Default value
258 */
259 FloatArrayEntry(NT_Entry handle, ParamType defaultValue)
260 : FloatArraySubscriber{handle, defaultValue},
261 FloatArrayPublisher{handle} {}
262
263 /**
264 * Determines if the native handle is valid.
265 *
266 * @return True if the native handle is valid, false otherwise.
267 */
268 explicit operator bool() const { return m_subHandle != 0; }
269
270 /**
271 * Gets the native handle for the entry.
272 *
273 * @return Native handle
274 */
275 NT_Entry GetHandle() const { return m_subHandle; }
276
277 /**
278 * Get the corresponding topic.
279 *
280 * @return Topic
281 */
282 TopicType GetTopic() const;
283
284 /**
285 * Stops publishing the entry if it's published.
286 */
290};
291
292/**
293 * NetworkTables FloatArray topic.
294 */
295class FloatArrayTopic final : public Topic {
296 public:
300 using ValueType = std::vector<float>;
301 using ParamType = std::span<const float>;
303 /** The default type string for this topic type. */
304 static constexpr std::string_view TYPE_STRING = "float[]";
305
306 FloatArrayTopic() = default;
307
308 /**
309 * Construct from a topic handle; recommended to use
310 * NetworkTableInstance::GetFloatArrayTopic() instead.
311 *
312 * @param handle Native handle
313 */
314 explicit FloatArrayTopic(NT_Topic handle) : Topic{handle} {}
315
316 /**
317 * Construct from a generic topic.
318 *
319 * @param topic Topic
320 */
321 explicit FloatArrayTopic(Topic topic) : Topic{topic} {}
322
323 /**
324 * Create a new subscriber to the topic.
325 *
326 * <p>The subscriber is only active as long as the returned object
327 * is not destroyed.
328 *
329 * @note Subscribers that do not match the published data type do not return
330 * any values. To determine if the data type matches, use the appropriate
331 * Topic functions.
332 *
333 * @param defaultValue default value used when a default is not provided to a
334 * getter function
335 * @param options subscribe options
336 * @return subscriber
337 */
338 [[nodiscard]]
340 ParamType defaultValue,
341 const PubSubOptions& options = DEFAULT_PUB_SUB_OPTIONS) {
343 ::wpi::nt::Subscribe(m_handle, NT_FLOAT_ARRAY, "float[]", options),
344 defaultValue};
345 }
346 /**
347 * Create a new subscriber to the topic, with specific type string.
348 *
349 * <p>The subscriber is only active as long as the returned object
350 * is not destroyed.
351 *
352 * @note Subscribers that do not match the published data type do not return
353 * any values. To determine if the data type matches, use the appropriate
354 * Topic functions.
355 *
356 * @param typeString type string
357 * @param defaultValue default value used when a default is not provided to a
358 * getter function
359 * @param options subscribe options
360 * @return subscriber
361 */
362 [[nodiscard]]
364 std::string_view typeString, ParamType defaultValue,
365 const PubSubOptions& options = DEFAULT_PUB_SUB_OPTIONS) {
367 ::wpi::nt::Subscribe(m_handle, NT_FLOAT_ARRAY, typeString, options),
368 defaultValue};
369 }
370
371 /**
372 * Create a new publisher to the topic.
373 *
374 * The publisher is only active as long as the returned object
375 * is not destroyed.
376 *
377 * @note It is not possible to publish two different data types to the same
378 * topic. Conflicts between publishers are typically resolved by the
379 * server on a first-come, first-served basis. Any published values that
380 * do not match the topic's data type are dropped (ignored). To determine
381 * if the data type matches, use the appropriate Topic functions.
382 *
383 * @param options publish options
384 * @return publisher
385 */
386 [[nodiscard]]
391
392 /**
393 * Create a new publisher to the topic, with type string and initial
394 * properties.
395 *
396 * The publisher is only active as long as the returned object
397 * is not destroyed.
398 *
399 * @note It is not possible to publish two different data types to the same
400 * topic. Conflicts between publishers are typically resolved by the
401 * server on a first-come, first-served basis. Any published values that
402 * do not match the topic's data type are dropped (ignored). To determine
403 * if the data type matches, use the appropriate Topic functions.
404 *
405 * @param typeString type string
406 * @param properties JSON properties
407 * @param options publish options
408 * @return publisher
409 */
410 [[nodiscard]]
411 PublisherType PublishEx(std::string_view typeString,
412 const wpi::util::json& properties, const PubSubOptions& options = DEFAULT_PUB_SUB_OPTIONS) {
413 return FloatArrayPublisher{
414 ::wpi::nt::PublishEx(m_handle, NT_FLOAT_ARRAY, typeString, properties, options)};
415 }
416
417 /**
418 * Create a new entry for the topic.
419 *
420 * Entries act as a combination of a subscriber and a weak publisher. The
421 * subscriber is active as long as the entry is not destroyed. The publisher
422 * is created when the entry is first written to, and remains active until
423 * either Unpublish() is called or the entry is destroyed.
424 *
425 * @note It is not possible to use two different data types with the same
426 * topic. Conflicts between publishers are typically resolved by the
427 * server on a first-come, first-served basis. Any published values that
428 * do not match the topic's data type are dropped (ignored), and the entry
429 * will show no new values if the data type does not match. To determine
430 * if the data type matches, use the appropriate Topic functions.
431 *
432 * @param defaultValue default value used when a default is not provided to a
433 * getter function
434 * @param options publish and/or subscribe options
435 * @return entry
436 */
437 [[nodiscard]]
439 const PubSubOptions& options = DEFAULT_PUB_SUB_OPTIONS) {
440 return FloatArrayEntry{
441 ::wpi::nt::GetEntry(m_handle, NT_FLOAT_ARRAY, "float[]", options),
442 defaultValue};
443 }
444 /**
445 * Create a new entry for the topic, with specific type string.
446 *
447 * Entries act as a combination of a subscriber and a weak publisher. The
448 * subscriber is active as long as the entry is not destroyed. The publisher
449 * is created when the entry is first written to, and remains active until
450 * either Unpublish() is called or the entry is destroyed.
451 *
452 * @note It is not possible to use two different data types with the same
453 * topic. Conflicts between publishers are typically resolved by the
454 * server on a first-come, first-served basis. Any published values that
455 * do not match the topic's data type are dropped (ignored), and the entry
456 * will show no new values if the data type does not match. To determine
457 * if the data type matches, use the appropriate Topic functions.
458 *
459 * @param typeString type string
460 * @param defaultValue default value used when a default is not provided to a
461 * getter function
462 * @param options publish and/or subscribe options
463 * @return entry
464 */
465 [[nodiscard]]
466 EntryType GetEntryEx(std::string_view typeString, ParamType defaultValue,
467 const PubSubOptions& options = DEFAULT_PUB_SUB_OPTIONS) {
468 return FloatArrayEntry{
469 ::wpi::nt::GetEntry(m_handle, NT_FLOAT_ARRAY, typeString, options),
470 defaultValue};
471 }
472
473};
474
478
482
486
487} // namespace wpi::nt
NetworkTables FloatArray entry.
Definition FloatArrayTopic.hpp:237
TimestampedFloatArray TimestampedValueType
Definition FloatArrayTopic.hpp:248
FloatArrayTopic TopicType
Definition FloatArrayTopic.hpp:241
void Unpublish()
Stops publishing the entry if it's published.
Definition FloatArrayTopic.hpp:287
FloatArrayPublisher PublisherType
Definition FloatArrayTopic.hpp:240
FloatArrayEntry()=default
std::span< const float > ParamType
Definition FloatArrayTopic.hpp:243
FloatArraySubscriber SubscriberType
Definition FloatArrayTopic.hpp:239
FloatArrayEntry(NT_Entry handle, ParamType defaultValue)
Construct from an entry handle; recommended to use FloatArrayTopic::GetEntry() instead.
Definition FloatArrayTopic.hpp:259
NT_Entry GetHandle() const
Gets the native handle for the entry.
Definition FloatArrayTopic.hpp:275
std::span< float > SmallRetType
Definition FloatArrayTopic.hpp:245
float SmallElemType
Definition FloatArrayTopic.hpp:246
TopicType GetTopic() const
Get the corresponding topic.
Definition FloatArrayTopic.hpp:483
std::vector< float > ValueType
Definition FloatArrayTopic.hpp:242
NetworkTables FloatArray publisher.
Definition FloatArrayTopic.hpp:181
std::vector< float > ValueType
Definition FloatArrayTopic.hpp:184
std::span< const float > ParamType
Definition FloatArrayTopic.hpp:185
void SetDefault(ParamType value)
Publish a default value.
Definition FloatArrayTopic.hpp:219
FloatArrayTopic TopicType
Definition FloatArrayTopic.hpp:183
TopicType GetTopic() const
Get the corresponding topic.
Definition FloatArrayTopic.hpp:479
FloatArrayPublisher(NT_Publisher handle)
Construct from a publisher handle; recommended to use FloatArrayTopic::Publish() instead.
Definition FloatArrayTopic.hpp:200
TimestampedFloatArray TimestampedValueType
Definition FloatArrayTopic.hpp:190
std::span< float > SmallRetType
Definition FloatArrayTopic.hpp:187
void Set(ParamType value, int64_t time=0)
Publish a new value.
Definition FloatArrayTopic.hpp:208
float SmallElemType
Definition FloatArrayTopic.hpp:188
NetworkTables FloatArray subscriber.
Definition FloatArrayTopic.hpp:33
FloatArrayTopic TopicType
Definition FloatArrayTopic.hpp:35
SmallRetType Get(wpi::util::SmallVectorImpl< SmallElemType > &buf, ParamType defaultValue) const
Get the last published value.
Definition FloatArrayTopic.hpp:98
ValueType Get(ParamType defaultValue) const
Get the last published value.
Definition FloatArrayTopic.hpp:75
FloatArraySubscriber(NT_Subscriber handle, ParamType defaultValue)
Construct from a subscriber handle; recommended to use FloatArrayTopic::Subscribe() instead.
Definition FloatArrayTopic.hpp:54
TimestampedValueType GetAtomic(ParamType defaultValue) const
Get the last published value along with its timestamp.
Definition FloatArrayTopic.hpp:121
SmallRetType Get(wpi::util::SmallVectorImpl< SmallElemType > &buf) const
Get the last published value.
Definition FloatArrayTopic.hpp:86
std::vector< TimestampedValueType > ReadQueue()
Get an array of all value changes since the last call to ReadQueue.
Definition FloatArrayTopic.hpp:163
ValueType Get() const
Get the last published value.
Definition FloatArrayTopic.hpp:64
std::span< float > SmallRetType
Definition FloatArrayTopic.hpp:40
TimestampedValueViewType GetAtomic(wpi::util::SmallVectorImpl< SmallElemType > &buf, ParamType defaultValue) const
Get the last published value along with its timestamp.
Definition FloatArrayTopic.hpp:147
float SmallElemType
Definition FloatArrayTopic.hpp:41
std::vector< float > ValueType
Definition FloatArrayTopic.hpp:36
TimestampedFloatArray TimestampedValueType
Definition FloatArrayTopic.hpp:38
TopicType GetTopic() const
Get the corresponding topic.
Definition FloatArrayTopic.hpp:475
TimestampedValueViewType GetAtomic(wpi::util::SmallVectorImpl< SmallElemType > &buf) const
Get the last published value along with its timestamp.
Definition FloatArrayTopic.hpp:133
std::span< const float > ParamType
Definition FloatArrayTopic.hpp:37
TimestampedValueType GetAtomic() const
Get the last published value along with its timestamp If no value has been published,...
Definition FloatArrayTopic.hpp:109
TimestampedFloatArrayView TimestampedValueViewType
Definition FloatArrayTopic.hpp:42
NetworkTables FloatArray topic.
Definition FloatArrayTopic.hpp:295
SubscriberType SubscribeEx(std::string_view typeString, ParamType defaultValue, const PubSubOptions &options=DEFAULT_PUB_SUB_OPTIONS)
Create a new subscriber to the topic, with specific type string.
Definition FloatArrayTopic.hpp:363
FloatArrayPublisher PublisherType
Definition FloatArrayTopic.hpp:298
PublisherType Publish(const PubSubOptions &options=DEFAULT_PUB_SUB_OPTIONS)
Create a new publisher to the topic.
Definition FloatArrayTopic.hpp:387
FloatArrayEntry EntryType
Definition FloatArrayTopic.hpp:299
EntryType GetEntry(ParamType defaultValue, const PubSubOptions &options=DEFAULT_PUB_SUB_OPTIONS)
Create a new entry for the topic.
Definition FloatArrayTopic.hpp:438
FloatArraySubscriber SubscriberType
Definition FloatArrayTopic.hpp:297
FloatArrayTopic(Topic topic)
Construct from a generic topic.
Definition FloatArrayTopic.hpp:321
FloatArrayTopic(NT_Topic handle)
Construct from a topic handle; recommended to use NetworkTableInstance::GetFloatArrayTopic() instead.
Definition FloatArrayTopic.hpp:314
static constexpr std::string_view TYPE_STRING
The default type string for this topic type.
Definition FloatArrayTopic.hpp:304
TimestampedFloatArray TimestampedValueType
Definition FloatArrayTopic.hpp:302
std::vector< float > ValueType
Definition FloatArrayTopic.hpp:300
std::span< const float > ParamType
Definition FloatArrayTopic.hpp:301
PublisherType PublishEx(std::string_view typeString, const wpi::util::json &properties, const PubSubOptions &options=DEFAULT_PUB_SUB_OPTIONS)
Create a new publisher to the topic, with type string and initial properties.
Definition FloatArrayTopic.hpp:411
SubscriberType Subscribe(ParamType defaultValue, const PubSubOptions &options=DEFAULT_PUB_SUB_OPTIONS)
Create a new subscriber to the topic.
Definition FloatArrayTopic.hpp:339
EntryType GetEntryEx(std::string_view typeString, ParamType defaultValue, const PubSubOptions &options=DEFAULT_PUB_SUB_OPTIONS)
Create a new entry for the topic, with specific type string.
Definition FloatArrayTopic.hpp:466
Publisher(const Publisher &)=delete
NT_Publisher m_pubHandle
NetworkTables handle.
Definition Topic.hpp:443
Subscriber(const Subscriber &)=delete
NT_Subscriber m_subHandle
Definition Topic.hpp:388
NT_Topic m_handle
Definition Topic.hpp:319
Topic()=default
Definition BooleanTopic.hpp:22
Definition json.hpp:85
std::vector< float > GetFloatArray(NT_Handle subentry, std::span< const float > defaultValue)
Get the last published value.
TimestampedFloatArray GetAtomicFloatArray(NT_Handle subentry, std::span< const float > defaultValue)
Get the last published value along with its timestamp.
bool SetDefaultFloatArray(NT_Handle pubentry, std::span< const float > defaultValue)
Publish a default value.
bool SetFloatArray(NT_Handle pubentry, std::span< const float > value, int64_t time=0)
Publish a new value.
NT_Handle NT_Topic
Definition ntcore_c.h:42
NT_Handle NT_Subscriber
Definition ntcore_c.h:43
NT_Handle NT_Publisher
Definition ntcore_c.h:44
NT_Handle NT_Entry
Definition ntcore_c.h:37
@ NT_FLOAT_ARRAY
Definition ntcore_c.h:63
constexpr PubSubOptions DEFAULT_PUB_SUB_OPTIONS
Default publish/subscribe options.
Definition ntcore_cpp.hpp:388
Timestamped< std::vector< float > > TimestampedFloatArray
Timestamped FloatArray.
Definition ntcore_cpp_types.hpp:739
Timestamped< std::span< float > > TimestampedFloatArrayView
Timestamped FloatArray view (for wpi::util::SmallVector-taking functions).
Definition ntcore_cpp_types.hpp:745
NT_Entry GetEntry(NT_Inst inst, std::string_view name)
Get Entry Handle.
NT_Topic GetTopicFromHandle(NT_Handle pubsubentry)
Gets the topic handle from an entry/subscriber/publisher handle.
NT_Subscriber Subscribe(NT_Topic topic, NT_Type type, std::string_view typeStr, const PubSubOptions &options=DEFAULT_PUB_SUB_OPTIONS)
Creates a new subscriber to value changes on a topic.
void Unpublish(NT_Handle pubentry)
Stops publisher.
NT_Publisher PublishEx(NT_Topic topic, NT_Type type, std::string_view typeStr, const wpi::util::json &properties, const PubSubOptions &options=DEFAULT_PUB_SUB_OPTIONS)
Creates a new publisher to a topic.
NT_Publisher Publish(NT_Topic topic, NT_Type type, std::string_view typeStr, const PubSubOptions &options=DEFAULT_PUB_SUB_OPTIONS)
Creates a new publisher to a topic.
NetworkTables (ntcore) namespace.
Definition NTSendable.hpp:9
Definition raw_os_ostream.hpp:19
NetworkTables publish/subscribe options.
Definition ntcore_cpp.hpp:303