WPILibC++ 2027.0.0-alpha-5
Loading...
Searching...
No Matches
DoubleArrayTopic.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
29
30/**
31 * NetworkTables DoubleArray subscriber.
32 */
34 public:
36 using ValueType = std::vector<double>;
37 using ParamType = std::span<const double>;
39
40 using SmallRetType = std::span<double>;
41 using SmallElemType = double;
43
44
46
47 /**
48 * Construct from a subscriber handle; recommended to use
49 * DoubleArrayTopic::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::GetDoubleArray(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::GetDoubleArray(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::GetAtomicDoubleArray(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::ReadQueueDoubleArray(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 DoubleArray publisher.
180 */
182 public:
184 using ValueType = std::vector<double>;
185 using ParamType = std::span<const double>;
186
187 using SmallRetType = std::span<double>;
188 using SmallElemType = double;
189
191
193
194 /**
195 * Construct from a publisher handle; recommended to use
196 * DoubleArrayTopic::Publish() instead.
197 *
198 * @param handle Native handle
199 */
200 explicit DoubleArrayPublisher(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 DoubleArray entry.
233 *
234 * @note Unlike NetworkTableEntry, the entry goes away when this is destroyed.
235 */
237 public DoubleArrayPublisher {
238 public:
242 using ValueType = std::vector<double>;
243 using ParamType = std::span<const double>;
244
245 using SmallRetType = std::span<double>;
246 using SmallElemType = double;
247
249
250 DoubleArrayEntry() = default;
251
252 /**
253 * Construct from an entry handle; recommended to use
254 * DoubleArrayTopic::GetEntry() instead.
255 *
256 * @param handle Native handle
257 * @param defaultValue Default value
258 */
259 DoubleArrayEntry(NT_Entry handle, ParamType defaultValue)
260 : DoubleArraySubscriber{handle, defaultValue},
261 DoubleArrayPublisher{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 DoubleArray topic.
294 */
295class DoubleArrayTopic final : public Topic {
296 public:
300 using ValueType = std::vector<double>;
301 using ParamType = std::span<const double>;
303 /** The default type string for this topic type. */
304 static constexpr std::string_view TYPE_STRING = "double[]";
305
306 DoubleArrayTopic() = default;
307
308 /**
309 * Construct from a topic handle; recommended to use
310 * NetworkTableInstance::GetDoubleArrayTopic() instead.
311 *
312 * @param handle Native handle
313 */
314 explicit DoubleArrayTopic(NT_Topic handle) : Topic{handle} {}
315
316 /**
317 * Construct from a generic topic.
318 *
319 * @param topic Topic
320 */
321 explicit DoubleArrayTopic(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_DOUBLE_ARRAY, "double[]", 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_DOUBLE_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) {
414 ::wpi::nt::PublishEx(m_handle, NT_DOUBLE_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 DoubleArrayEntry{
441 ::wpi::nt::GetEntry(m_handle, NT_DOUBLE_ARRAY, "double[]", 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 DoubleArrayEntry{
469 ::wpi::nt::GetEntry(m_handle, NT_DOUBLE_ARRAY, typeString, options),
470 defaultValue};
471 }
472
473};
474
478
482
486
487} // namespace wpi::nt
NetworkTables DoubleArray entry.
Definition DoubleArrayTopic.hpp:237
std::span< const double > ParamType
Definition DoubleArrayTopic.hpp:243
NT_Entry GetHandle() const
Gets the native handle for the entry.
Definition DoubleArrayTopic.hpp:275
std::vector< double > ValueType
Definition DoubleArrayTopic.hpp:242
TopicType GetTopic() const
Get the corresponding topic.
Definition DoubleArrayTopic.hpp:483
DoubleArrayTopic TopicType
Definition DoubleArrayTopic.hpp:241
DoubleArraySubscriber SubscriberType
Definition DoubleArrayTopic.hpp:239
DoubleArrayEntry(NT_Entry handle, ParamType defaultValue)
Construct from an entry handle; recommended to use DoubleArrayTopic::GetEntry() instead.
Definition DoubleArrayTopic.hpp:259
std::span< double > SmallRetType
Definition DoubleArrayTopic.hpp:245
void Unpublish()
Stops publishing the entry if it's published.
Definition DoubleArrayTopic.hpp:287
DoubleArrayEntry()=default
double SmallElemType
Definition DoubleArrayTopic.hpp:246
TimestampedDoubleArray TimestampedValueType
Definition DoubleArrayTopic.hpp:248
DoubleArrayPublisher PublisherType
Definition DoubleArrayTopic.hpp:240
NetworkTables DoubleArray publisher.
Definition DoubleArrayTopic.hpp:181
void Set(ParamType value, int64_t time=0)
Publish a new value.
Definition DoubleArrayTopic.hpp:208
TopicType GetTopic() const
Get the corresponding topic.
Definition DoubleArrayTopic.hpp:479
double SmallElemType
Definition DoubleArrayTopic.hpp:188
void SetDefault(ParamType value)
Publish a default value.
Definition DoubleArrayTopic.hpp:219
std::vector< double > ValueType
Definition DoubleArrayTopic.hpp:184
std::span< double > SmallRetType
Definition DoubleArrayTopic.hpp:187
DoubleArrayTopic TopicType
Definition DoubleArrayTopic.hpp:183
DoubleArrayPublisher(NT_Publisher handle)
Construct from a publisher handle; recommended to use DoubleArrayTopic::Publish() instead.
Definition DoubleArrayTopic.hpp:200
TimestampedDoubleArray TimestampedValueType
Definition DoubleArrayTopic.hpp:190
std::span< const double > ParamType
Definition DoubleArrayTopic.hpp:185
NetworkTables DoubleArray subscriber.
Definition DoubleArrayTopic.hpp:33
DoubleArrayTopic TopicType
Definition DoubleArrayTopic.hpp:35
std::vector< TimestampedValueType > ReadQueue()
Get an array of all value changes since the last call to ReadQueue.
Definition DoubleArrayTopic.hpp:163
TimestampedValueViewType GetAtomic(wpi::util::SmallVectorImpl< SmallElemType > &buf) const
Get the last published value along with its timestamp.
Definition DoubleArrayTopic.hpp:133
TimestampedDoubleArray TimestampedValueType
Definition DoubleArrayTopic.hpp:38
DoubleArraySubscriber(NT_Subscriber handle, ParamType defaultValue)
Construct from a subscriber handle; recommended to use DoubleArrayTopic::Subscribe() instead.
Definition DoubleArrayTopic.hpp:54
std::vector< double > ValueType
Definition DoubleArrayTopic.hpp:36
double SmallElemType
Definition DoubleArrayTopic.hpp:41
TimestampedValueType GetAtomic(ParamType defaultValue) const
Get the last published value along with its timestamp.
Definition DoubleArrayTopic.hpp:121
TimestampedValueViewType GetAtomic(wpi::util::SmallVectorImpl< SmallElemType > &buf, ParamType defaultValue) const
Get the last published value along with its timestamp.
Definition DoubleArrayTopic.hpp:147
SmallRetType Get(wpi::util::SmallVectorImpl< SmallElemType > &buf) const
Get the last published value.
Definition DoubleArrayTopic.hpp:86
TimestampedValueType GetAtomic() const
Get the last published value along with its timestamp If no value has been published,...
Definition DoubleArrayTopic.hpp:109
ValueType Get() const
Get the last published value.
Definition DoubleArrayTopic.hpp:64
TopicType GetTopic() const
Get the corresponding topic.
Definition DoubleArrayTopic.hpp:475
ValueType Get(ParamType defaultValue) const
Get the last published value.
Definition DoubleArrayTopic.hpp:75
std::span< const double > ParamType
Definition DoubleArrayTopic.hpp:37
std::span< double > SmallRetType
Definition DoubleArrayTopic.hpp:40
SmallRetType Get(wpi::util::SmallVectorImpl< SmallElemType > &buf, ParamType defaultValue) const
Get the last published value.
Definition DoubleArrayTopic.hpp:98
TimestampedDoubleArrayView TimestampedValueViewType
Definition DoubleArrayTopic.hpp:42
NetworkTables DoubleArray topic.
Definition DoubleArrayTopic.hpp:295
PublisherType Publish(const PubSubOptions &options=DEFAULT_PUB_SUB_OPTIONS)
Create a new publisher to the topic.
Definition DoubleArrayTopic.hpp:387
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 DoubleArrayTopic.hpp:363
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 DoubleArrayTopic.hpp:466
SubscriberType Subscribe(ParamType defaultValue, const PubSubOptions &options=DEFAULT_PUB_SUB_OPTIONS)
Create a new subscriber to the topic.
Definition DoubleArrayTopic.hpp:339
std::span< const double > ParamType
Definition DoubleArrayTopic.hpp:301
DoubleArraySubscriber SubscriberType
Definition DoubleArrayTopic.hpp:297
EntryType GetEntry(ParamType defaultValue, const PubSubOptions &options=DEFAULT_PUB_SUB_OPTIONS)
Create a new entry for the topic.
Definition DoubleArrayTopic.hpp:438
std::vector< double > ValueType
Definition DoubleArrayTopic.hpp:300
DoubleArrayEntry EntryType
Definition DoubleArrayTopic.hpp:299
DoubleArrayTopic(NT_Topic handle)
Construct from a topic handle; recommended to use NetworkTableInstance::GetDoubleArrayTopic() instead...
Definition DoubleArrayTopic.hpp:314
DoubleArrayTopic(Topic topic)
Construct from a generic topic.
Definition DoubleArrayTopic.hpp:321
static constexpr std::string_view TYPE_STRING
The default type string for this topic type.
Definition DoubleArrayTopic.hpp:304
DoubleArrayPublisher PublisherType
Definition DoubleArrayTopic.hpp:298
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 DoubleArrayTopic.hpp:411
TimestampedDoubleArray TimestampedValueType
Definition DoubleArrayTopic.hpp:302
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
TimestampedDoubleArray GetAtomicDoubleArray(NT_Handle subentry, std::span< const double > defaultValue)
Get the last published value along with its timestamp.
bool SetDefaultDoubleArray(NT_Handle pubentry, std::span< const double > defaultValue)
Publish a default value.
std::vector< double > GetDoubleArray(NT_Handle subentry, std::span< const double > defaultValue)
Get the last published value.
bool SetDoubleArray(NT_Handle pubentry, std::span< const double > 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_DOUBLE_ARRAY
Definition ntcore_c.h:57
Timestamped< std::span< double > > TimestampedDoubleArrayView
Timestamped DoubleArray view (for wpi::util::SmallVector-taking functions).
Definition ntcore_cpp_types.hpp:837
constexpr PubSubOptions DEFAULT_PUB_SUB_OPTIONS
Default publish/subscribe options.
Definition ntcore_cpp.hpp:388
Timestamped< std::vector< double > > TimestampedDoubleArray
Timestamped DoubleArray.
Definition ntcore_cpp_types.hpp:831
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