WPILibC++ 2024.3.2
DoubleArrayTopic.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// 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
16#include <wpi/json_fwd.h>
17
18#include "networktables/Topic.h"
19
20namespace wpi {
21template <typename T>
22class SmallVectorImpl;
23} // namespace wpi
24
25namespace nt {
26
27class DoubleArrayTopic;
28
29/**
30 * NetworkTables DoubleArray subscriber.
31 */
33 public:
35 using ValueType = std::vector<double>;
36 using ParamType = std::span<const double>;
38
39 using SmallRetType = std::span<double>;
40 using SmallElemType = double;
42
43
45
46 /**
47 * Construct from a subscriber handle; recommended to use
48 * DoubleArrayTopic::Subscribe() instead.
49 *
50 * @param handle Native handle
51 * @param defaultValue Default value
52 */
54
55 /**
56 * Get the last published value.
57 * If no value has been published, returns the stored default value.
58 *
59 * @return value
60 */
61 ValueType Get() const;
62
63 /**
64 * Get the last published value.
65 * If no value has been published, returns the passed defaultValue.
66 *
67 * @param defaultValue default value to return if no value has been published
68 * @return value
69 */
70 ValueType Get(ParamType defaultValue) const;
71
72 /**
73 * Get the last published value.
74 * If no value has been published, returns the stored default value.
75 *
76 * @param buf storage for returned value
77 * @return value
78 */
80
81 /**
82 * Get the last published value.
83 * If no value has been published, returns the passed defaultValue.
84 *
85 * @param buf storage for returned value
86 * @param defaultValue default value to return if no value has been published
87 * @return value
88 */
90
91 /**
92 * Get the last published value along with its timestamp
93 * If no value has been published, returns the stored default value and a
94 * timestamp of 0.
95 *
96 * @return timestamped value
97 */
99
100 /**
101 * Get the last published value along with its timestamp.
102 * If no value has been published, returns the passed defaultValue and a
103 * timestamp of 0.
104 *
105 * @param defaultValue default value to return if no value has been published
106 * @return timestamped value
107 */
109
110 /**
111 * Get the last published value along with its timestamp.
112 * If no value has been published, returns the stored default value and a
113 * timestamp of 0.
114 *
115 * @param buf storage for returned value
116 * @return timestamped value
117 */
120
121 /**
122 * Get the last published value along with its timestamp.
123 * If no value has been published, returns the passed defaultValue and a
124 * timestamp of 0.
125 *
126 * @param buf storage for returned value
127 * @param defaultValue default value to return if no value has been published
128 * @return timestamped value
129 */
132 ParamType defaultValue) const;
133
134 /**
135 * Get an array of all value changes since the last call to ReadQueue.
136 * Also provides a timestamp for each value.
137 *
138 * @note The "poll storage" subscribe option can be used to set the queue
139 * depth.
140 *
141 * @return Array of timestamped values; empty array if no new changes have
142 * been published since the previous call.
143 */
144 std::vector<TimestampedValueType> ReadQueue();
145
146 /**
147 * Get the corresponding topic.
148 *
149 * @return Topic
150 */
151 TopicType GetTopic() const;
152
153 private:
154 ValueType m_defaultValue;
155};
156
157/**
158 * NetworkTables DoubleArray publisher.
159 */
161 public:
163 using ValueType = std::vector<double>;
164 using ParamType = std::span<const double>;
165
166 using SmallRetType = std::span<double>;
167 using SmallElemType = double;
168
170
172
173 /**
174 * Construct from a publisher handle; recommended to use
175 * DoubleArrayTopic::Publish() instead.
176 *
177 * @param handle Native handle
178 */
179 explicit DoubleArrayPublisher(NT_Publisher handle);
180
181 /**
182 * Publish a new value.
183 *
184 * @param value value to publish
185 * @param time timestamp; 0 indicates current NT time should be used
186 */
187 void Set(ParamType value, int64_t time = 0);
188
189 /**
190 * Publish a default value.
191 * On reconnect, a default value will never be used in preference to a
192 * published value.
193 *
194 * @param value value
195 */
196 void SetDefault(ParamType value);
197
198 /**
199 * Get the corresponding topic.
200 *
201 * @return Topic
202 */
203 TopicType GetTopic() const;
204};
205
206/**
207 * NetworkTables DoubleArray entry.
208 *
209 * @note Unlike NetworkTableEntry, the entry goes away when this is destroyed.
210 */
212 public DoubleArrayPublisher {
213 public:
217 using ValueType = std::vector<double>;
218 using ParamType = std::span<const double>;
219
220 using SmallRetType = std::span<double>;
221 using SmallElemType = double;
222
224
225 DoubleArrayEntry() = default;
226
227 /**
228 * Construct from an entry handle; recommended to use
229 * DoubleArrayTopic::GetEntry() instead.
230 *
231 * @param handle Native handle
232 * @param defaultValue Default value
233 */
234 DoubleArrayEntry(NT_Entry handle, ParamType defaultValue);
235
236 /**
237 * Determines if the native handle is valid.
238 *
239 * @return True if the native handle is valid, false otherwise.
240 */
241 explicit operator bool() const { return m_subHandle != 0; }
242
243 /**
244 * Gets the native handle for the entry.
245 *
246 * @return Native handle
247 */
248 NT_Entry GetHandle() const { return m_subHandle; }
249
250 /**
251 * Get the corresponding topic.
252 *
253 * @return Topic
254 */
255 TopicType GetTopic() const;
256
257 /**
258 * Stops publishing the entry if it's published.
259 */
260 void Unpublish();
261};
262
263/**
264 * NetworkTables DoubleArray topic.
265 */
266class DoubleArrayTopic final : public Topic {
267 public:
271 using ValueType = std::vector<double>;
272 using ParamType = std::span<const double>;
274 /** The default type string for this topic type. */
275 static constexpr std::string_view kTypeString = "double[]";
276
277 DoubleArrayTopic() = default;
278
279 /**
280 * Construct from a topic handle; recommended to use
281 * NetworkTableInstance::GetDoubleArrayTopic() instead.
282 *
283 * @param handle Native handle
284 */
285 explicit DoubleArrayTopic(NT_Topic handle) : Topic{handle} {}
286
287 /**
288 * Construct from a generic topic.
289 *
290 * @param topic Topic
291 */
292 explicit DoubleArrayTopic(Topic topic) : Topic{topic} {}
293
294 /**
295 * Create a new subscriber to the topic.
296 *
297 * <p>The subscriber is only active as long as the returned object
298 * is not destroyed.
299 *
300 * @note Subscribers that do not match the published data type do not return
301 * any values. To determine if the data type matches, use the appropriate
302 * Topic functions.
303 *
304 * @param defaultValue default value used when a default is not provided to a
305 * getter function
306 * @param options subscribe options
307 * @return subscriber
308 */
309 [[nodiscard]]
311 ParamType defaultValue,
312 const PubSubOptions& options = kDefaultPubSubOptions);
313 /**
314 * Create a new subscriber to the topic, with specific type string.
315 *
316 * <p>The subscriber is only active as long as the returned object
317 * is not destroyed.
318 *
319 * @note Subscribers that do not match the published data type do not return
320 * any values. To determine if the data type matches, use the appropriate
321 * Topic functions.
322 *
323 * @param typeString type string
324 * @param defaultValue default value used when a default is not provided to a
325 * getter function
326 * @param options subscribe options
327 * @return subscriber
328 */
329 [[nodiscard]]
331 std::string_view typeString, ParamType defaultValue,
332 const PubSubOptions& options = kDefaultPubSubOptions);
333
334 /**
335 * Create a new publisher to the topic.
336 *
337 * The publisher is only active as long as the returned object
338 * is not destroyed.
339 *
340 * @note It is not possible to publish two different data types to the same
341 * topic. Conflicts between publishers are typically resolved by the
342 * server on a first-come, first-served basis. Any published values that
343 * do not match the topic's data type are dropped (ignored). To determine
344 * if the data type matches, use the appropriate Topic functions.
345 *
346 * @param options publish options
347 * @return publisher
348 */
349 [[nodiscard]]
351
352 /**
353 * Create a new publisher to the topic, with type string and initial
354 * properties.
355 *
356 * The publisher is only active as long as the returned object
357 * is not destroyed.
358 *
359 * @note It is not possible to publish two different data types to the same
360 * topic. Conflicts between publishers are typically resolved by the
361 * server on a first-come, first-served basis. Any published values that
362 * do not match the topic's data type are dropped (ignored). To determine
363 * if the data type matches, use the appropriate Topic functions.
364 *
365 * @param typeString type string
366 * @param properties JSON properties
367 * @param options publish options
368 * @return publisher
369 */
370 [[nodiscard]]
372 const wpi::json& properties, const PubSubOptions& options = kDefaultPubSubOptions);
373
374 /**
375 * Create a new entry for the topic.
376 *
377 * Entries act as a combination of a subscriber and a weak publisher. The
378 * subscriber is active as long as the entry is not destroyed. The publisher
379 * is created when the entry is first written to, and remains active until
380 * either Unpublish() is called or the entry is destroyed.
381 *
382 * @note It is not possible to use two different data types with the same
383 * topic. Conflicts between publishers are typically resolved by the
384 * server on a first-come, first-served basis. Any published values that
385 * do not match the topic's data type are dropped (ignored), and the entry
386 * will show no new values if the data type does not match. To determine
387 * if the data type matches, use the appropriate Topic functions.
388 *
389 * @param defaultValue default value used when a default is not provided to a
390 * getter function
391 * @param options publish and/or subscribe options
392 * @return entry
393 */
394 [[nodiscard]]
395 EntryType GetEntry(ParamType defaultValue,
396 const PubSubOptions& options = kDefaultPubSubOptions);
397 /**
398 * Create a new entry for the topic, with specific type string.
399 *
400 * Entries act as a combination of a subscriber and a weak publisher. The
401 * subscriber is active as long as the entry is not destroyed. The publisher
402 * is created when the entry is first written to, and remains active until
403 * either Unpublish() is called or the entry is destroyed.
404 *
405 * @note It is not possible to use two different data types with the same
406 * topic. Conflicts between publishers are typically resolved by the
407 * server on a first-come, first-served basis. Any published values that
408 * do not match the topic's data type are dropped (ignored), and the entry
409 * will show no new values if the data type does not match. To determine
410 * if the data type matches, use the appropriate Topic functions.
411 *
412 * @param typeString type string
413 * @param defaultValue default value used when a default is not provided to a
414 * getter function
415 * @param options publish and/or subscribe options
416 * @return entry
417 */
418 [[nodiscard]]
419 EntryType GetEntryEx(std::string_view typeString, ParamType defaultValue,
420 const PubSubOptions& options = kDefaultPubSubOptions);
421
422};
423
424} // namespace nt
425
NetworkTables DoubleArray entry.
Definition: DoubleArrayTopic.h:212
DoubleArrayEntry()=default
DoubleArrayTopic TopicType
Definition: DoubleArrayTopic.h:216
TopicType GetTopic() const
Get the corresponding topic.
Definition: DoubleArrayTopic.inc:86
void Unpublish()
Stops publishing the entry if it's published.
Definition: DoubleArrayTopic.inc:90
NT_Entry GetHandle() const
Gets the native handle for the entry.
Definition: DoubleArrayTopic.h:248
DoubleArrayEntry(NT_Entry handle, ParamType defaultValue)
Construct from an entry handle; recommended to use DoubleArrayTopic::GetEntry() instead.
NetworkTables DoubleArray publisher.
Definition: DoubleArrayTopic.h:160
TopicType GetTopic() const
Get the corresponding topic.
Definition: DoubleArrayTopic.inc:77
void Set(ParamType value, int64_t time=0)
Publish a new value.
Definition: DoubleArrayTopic.inc:68
std::span< double > SmallRetType
Definition: DoubleArrayTopic.h:166
double SmallElemType
Definition: DoubleArrayTopic.h:167
void SetDefault(ParamType value)
Publish a default value.
Definition: DoubleArrayTopic.inc:73
std::vector< double > ValueType
Definition: DoubleArrayTopic.h:163
std::span< const double > ParamType
Definition: DoubleArrayTopic.h:164
NetworkTables DoubleArray subscriber.
Definition: DoubleArrayTopic.h:32
std::vector< double > ValueType
Definition: DoubleArrayTopic.h:35
TimestampedValueViewType GetAtomic(wpi::SmallVectorImpl< SmallElemType > &buf, ParamType defaultValue) const
Get the last published value along with its timestamp.
ValueType Get() const
Get the last published value.
Definition: DoubleArrayTopic.inc:22
ValueType Get(ParamType defaultValue) const
Get the last published value.
std::vector< TimestampedValueType > ReadQueue()
Get an array of all value changes since the last call to ReadQueue.
Definition: DoubleArrayTopic.inc:57
TopicType GetTopic() const
Get the corresponding topic.
Definition: DoubleArrayTopic.inc:61
DoubleArraySubscriber(NT_Subscriber handle, ParamType defaultValue)
Construct from a subscriber handle; recommended to use DoubleArrayTopic::Subscribe() instead.
SmallRetType Get(wpi::SmallVectorImpl< SmallElemType > &buf, ParamType defaultValue) const
Get the last published value.
double SmallElemType
Definition: DoubleArrayTopic.h:40
std::span< double > SmallRetType
Definition: DoubleArrayTopic.h:39
std::span< const double > ParamType
Definition: DoubleArrayTopic.h:36
TimestampedValueType GetAtomic(ParamType defaultValue) const
Get the last published value along with its timestamp.
TimestampedValueType GetAtomic() const
Get the last published value along with its timestamp If no value has been published,...
Definition: DoubleArrayTopic.inc:39
NetworkTables DoubleArray topic.
Definition: DoubleArrayTopic.h:266
EntryType GetEntryEx(std::string_view typeString, ParamType defaultValue, const PubSubOptions &options=kDefaultPubSubOptions)
Create a new entry for the topic, with specific type string.
Definition: DoubleArrayTopic.inc:129
EntryType GetEntry(ParamType defaultValue, const PubSubOptions &options=kDefaultPubSubOptions)
Create a new entry for the topic.
Definition: DoubleArrayTopic.inc:122
DoubleArrayEntry EntryType
Definition: DoubleArrayTopic.h:270
static constexpr std::string_view kTypeString
The default type string for this topic type.
Definition: DoubleArrayTopic.h:275
SubscriberType Subscribe(ParamType defaultValue, const PubSubOptions &options=kDefaultPubSubOptions)
Create a new subscriber to the topic.
Definition: DoubleArrayTopic.inc:94
std::span< const double > ParamType
Definition: DoubleArrayTopic.h:272
DoubleArrayTopic(Topic topic)
Construct from a generic topic.
Definition: DoubleArrayTopic.h:292
SubscriberType SubscribeEx(std::string_view typeString, ParamType defaultValue, const PubSubOptions &options=kDefaultPubSubOptions)
Create a new subscriber to the topic, with specific type string.
Definition: DoubleArrayTopic.inc:101
DoubleArrayTopic()=default
PublisherType PublishEx(std::string_view typeString, const wpi::json &properties, const PubSubOptions &options=kDefaultPubSubOptions)
Create a new publisher to the topic, with type string and initial properties.
Definition: DoubleArrayTopic.inc:115
PublisherType Publish(const PubSubOptions &options=kDefaultPubSubOptions)
Create a new publisher to the topic.
Definition: DoubleArrayTopic.inc:109
DoubleArrayPublisher PublisherType
Definition: DoubleArrayTopic.h:269
std::vector< double > ValueType
Definition: DoubleArrayTopic.h:271
DoubleArraySubscriber SubscriberType
Definition: DoubleArrayTopic.h:268
DoubleArrayTopic(NT_Topic handle)
Construct from a topic handle; recommended to use NetworkTableInstance::GetDoubleArrayTopic() instead...
Definition: DoubleArrayTopic.h:285
NetworkTables publisher.
Definition: Topic.h:364
NetworkTables subscriber.
Definition: Topic.h:309
NT_Subscriber m_subHandle
Definition: Topic.h:360
NetworkTables Topic.
Definition: Topic.h:28
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:579
basic_string_view< char > string_view
Definition: core.h:501
NT_Handle NT_Topic
Definition: ntcore_c.h:40
NT_Handle NT_Subscriber
Definition: ntcore_c.h:41
NT_Handle NT_Publisher
Definition: ntcore_c.h:42
NT_Handle NT_Entry
Definition: ntcore_c.h:35
Timestamped< std::vector< double > > TimestampedDoubleArray
Timestamped DoubleArray.
Definition: ntcore_cpp_types.h:831
Timestamped< std::span< double > > TimestampedDoubleArrayView
Timestamped DoubleArray view (for SmallVector-taking functions).
Definition: ntcore_cpp_types.h:837
constexpr PubSubOptions kDefaultPubSubOptions
Default publish/subscribe options.
Definition: ntcore_cpp.h:390
NetworkTables (ntcore) namespace.
Definition: ntcore_cpp.h:36
Definition: ntcore_cpp.h:26
NetworkTables publish/subscribe options.
Definition: ntcore_cpp.h:305
Timestamped value.
Definition: ntcore_cpp_types.h:30