WPILibC++ 2024.3.2
MultiSubscriber.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 <span>
8#include <string_view>
9
11#include "ntcore_cpp.h"
12
13namespace nt {
14
15/**
16 * Subscribe to multiple topics based on one or more topic name prefixes. Can be
17 * used in combination with ValueListenerPoller to listen for value changes
18 * across all matching topics.
19 */
20class MultiSubscriber final {
21 public:
22 MultiSubscriber() = default;
23
24 /**
25 * Create a multiple subscriber.
26 *
27 * @param inst instance
28 * @param prefixes topic name prefixes
29 * @param options subscriber options
30 */
32 std::span<const std::string_view> prefixes,
33 const PubSubOptions& options = kDefaultPubSubOptions);
34
40
41 /**
42 * Determines if the native handle is valid.
43 *
44 * @return True if the native handle is valid, false otherwise.
45 */
46 explicit operator bool() const { return m_handle != 0; }
47
48 /**
49 * Gets the native handle.
50 *
51 * @return Handle
52 */
53 NT_MultiSubscriber GetHandle() const { return m_handle; }
54
55 private:
56 NT_MultiSubscriber m_handle{0};
57};
58
59} // namespace nt
60
61#include "MultiSubscriber.inc"
Subscribe to multiple topics based on one or more topic name prefixes.
Definition: MultiSubscriber.h:20
~MultiSubscriber()
Definition: MultiSubscriber.inc:30
NT_MultiSubscriber GetHandle() const
Gets the native handle.
Definition: MultiSubscriber.h:53
MultiSubscriber(const MultiSubscriber &)=delete
MultiSubscriber()=default
MultiSubscriber & operator=(const MultiSubscriber &)=delete
NetworkTables Instance.
Definition: NetworkTableInstance.h:70
NT_Handle NT_MultiSubscriber
Definition: ntcore_c.h:39
constexpr PubSubOptions kDefaultPubSubOptions
Default publish/subscribe options.
Definition: ntcore_cpp.h:390
NetworkTables (ntcore) namespace.
Definition: ntcore_cpp.h:36
NetworkTables publish/subscribe options.
Definition: ntcore_cpp.h:305