WPILibC++ 2027.0.0-alpha-4
Loading...
Searching...
No Matches
VideoProperty.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#pragma once
6
7#include <string>
8#include <string_view>
9#include <vector>
10
11#include "wpi/cs/cscore_cpp.hpp"
12
13namespace wpi::cs {
14
15/**
16 * @defgroup cscore_oo cscore C++ object-oriented API
17 *
18 * Recommended interface for C++, identical to Java API.
19 *
20 * <p>The classes are RAII and handle reference counting internally.
21 *
22 * @{
23 */
24
25// Forward declarations so friend declarations work correctly
26class ImageSource;
27class VideoEvent;
28class VideoSink;
29class VideoSource;
30
31/**
32 * A source or sink property.
33 */
35 friend class ImageSource;
36 friend class VideoEvent;
37 friend class VideoSink;
38 friend class VideoSource;
39
40 public:
41 enum Kind {
42 /// No specific property.
44 /// Boolean property.
46 /// Integer property.
48 /// String property.
50 /// Enum property.
52 };
53
54 VideoProperty() = default;
55
56 /**
57 * Returns property name.
58 *
59 * @return Property name.
60 */
61 std::string GetName() const {
62 m_status = 0;
63 return GetPropertyName(m_handle, &m_status);
64 }
65
66 /**
67 * Returns property kind.
68 *
69 * @return Property kind.
70 */
71 Kind GetKind() const { return m_kind; }
72
73 /**
74 * Returns true if property is valid.
75 *
76 * @return True if property is valid.
77 */
78 explicit operator bool() const { return m_kind != kNone; }
79
80 /**
81 * Returns true if property is a boolean.
82 *
83 * @return True if property is a boolean.
84 */
85 bool IsBoolean() const { return m_kind == kBoolean; }
86
87 /**
88 * Returns true if property is an integer.
89 *
90 * @return True if property is an integer.
91 */
92 bool IsInteger() const { return m_kind == kInteger; }
93
94 /**
95 * Returns true if property is a string.
96 *
97 * @return True if property is a string.
98 */
99 bool IsString() const { return m_kind == kString; }
100
101 /**
102 * Returns true if property is an enum.
103 *
104 * @return True if property is an enum.
105 */
106 bool IsEnum() const { return m_kind == kEnum; }
107
108 /**
109 * Returns property value.
110 *
111 * @return Property value.
112 */
113 int Get() const {
114 m_status = 0;
115 return GetProperty(m_handle, &m_status);
116 }
117
118 /**
119 * Sets property value.
120 *
121 * @param value Property value.
122 */
123 void Set(int value) {
124 m_status = 0;
125 SetProperty(m_handle, value, &m_status);
126 }
127
128 /**
129 * Returns property minimum value.
130 *
131 * @return Property minimum value.
132 */
133 int GetMin() const {
134 m_status = 0;
135 return GetPropertyMin(m_handle, &m_status);
136 }
137
138 /**
139 * Returns property maximum value.
140 *
141 * @return Property maximum value.
142 */
143 int GetMax() const {
144 m_status = 0;
145 return GetPropertyMax(m_handle, &m_status);
146 }
147
148 /**
149 * Returns property step size.
150 *
151 * @return Property step size.
152 */
153 int GetStep() const {
154 m_status = 0;
155 return GetPropertyStep(m_handle, &m_status);
156 }
157
158 /**
159 * Returns property default value.
160 *
161 * @return Property default value.
162 */
163 int GetDefault() const {
164 m_status = 0;
165 return GetPropertyDefault(m_handle, &m_status);
166 }
167
168 /**
169 * Returns the string property value.
170 *
171 * <p>This function is string-specific.
172 *
173 * @return The string property value.
174 */
175 std::string GetString() const {
176 m_status = 0;
177 return GetStringProperty(m_handle, &m_status);
178 }
179
180 /**
181 * Returns the string property value as a reference to the given buffer.
182 *
183 * This function is string-specific.
184 *
185 * @param buf The backing storage to which to write the property value.
186 * @return The string property value as a reference to the given buffer.
187 */
188 std::string_view GetString(wpi::util::SmallVectorImpl<char>& buf) const {
189 m_status = 0;
190 return GetStringProperty(m_handle, buf, &m_status);
191 }
192
193 /**
194 * Sets the string property value.
195 *
196 * This function is string-specific.
197 *
198 * @param value String property value.
199 */
200 void SetString(std::string_view value) {
201 m_status = 0;
202 SetStringProperty(m_handle, value, &m_status);
203 }
204
205 /**
206 * Returns the possible values for the enum property value.
207 *
208 * This function is enum-specific.
209 *
210 * @return The possible values for the enum property value.
211 */
212 std::vector<std::string> GetChoices() const {
213 m_status = 0;
214 return GetEnumPropertyChoices(m_handle, &m_status);
215 }
216
217 /**
218 * Returns the last status.
219 *
220 * @return The last status.
221 */
222 CS_Status GetLastStatus() const { return m_status; }
223
224 private:
225 explicit VideoProperty(CS_Property handle) : m_handle(handle) {
226 m_status = 0;
227 if (handle == 0) {
228 m_kind = kNone;
229 } else {
230 m_kind = static_cast<Kind>(
231 static_cast<int>(GetPropertyKind(handle, &m_status)));
232 }
233 }
234
235 VideoProperty(CS_Property handle, Kind kind)
236 : m_handle(handle), m_kind(kind) {}
237
238 mutable CS_Status m_status{0};
239 CS_Property m_handle{0};
240 Kind m_kind{kNone};
241};
242
243} // namespace wpi::cs
A base class for single image providing sources.
Definition ImageSource.hpp:22
An event generated by the library and provided to event listeners.
Definition VideoEvent.hpp:17
A sink for video that accepts a sequence of frames.
Definition VideoSink.hpp:24
A source for video that provides a sequence of frames.
Definition VideoSource.hpp:25
Definition BooleanTopic.hpp:24
@ CS_PROP_ENUM
Definition cscore_c.h:102
@ CS_PROP_NONE
Definition cscore_c.h:98
@ CS_PROP_INTEGER
Definition cscore_c.h:100
@ CS_PROP_BOOLEAN
Definition cscore_c.h:99
@ CS_PROP_STRING
Definition cscore_c.h:101
std::vector< std::string > GetChoices() const
Returns the possible values for the enum property value.
Definition VideoProperty.hpp:212
void Set(int value)
Sets property value.
Definition VideoProperty.hpp:123
Kind
Definition VideoProperty.hpp:41
std::string GetString() const
Returns the string property value.
Definition VideoProperty.hpp:175
int GetDefault() const
Returns property default value.
Definition VideoProperty.hpp:163
int GetStep() const
Returns property step size.
Definition VideoProperty.hpp:153
int GetMax() const
Returns property maximum value.
Definition VideoProperty.hpp:143
bool IsString() const
Returns true if property is a string.
Definition VideoProperty.hpp:99
bool IsBoolean() const
Returns true if property is a boolean.
Definition VideoProperty.hpp:85
std::string GetName() const
Returns property name.
Definition VideoProperty.hpp:61
int GetMin() const
Returns property minimum value.
Definition VideoProperty.hpp:133
friend class VideoSink
Definition VideoProperty.hpp:37
bool IsInteger() const
Returns true if property is an integer.
Definition VideoProperty.hpp:92
std::string_view GetString(wpi::util::SmallVectorImpl< char > &buf) const
Returns the string property value as a reference to the given buffer.
Definition VideoProperty.hpp:188
CS_Status GetLastStatus() const
Returns the last status.
Definition VideoProperty.hpp:222
void SetString(std::string_view value)
Sets the string property value.
Definition VideoProperty.hpp:200
friend class VideoEvent
Definition VideoProperty.hpp:36
friend class VideoSource
Definition VideoProperty.hpp:38
int Get() const
Returns property value.
Definition VideoProperty.hpp:113
Kind GetKind() const
Returns property kind.
Definition VideoProperty.hpp:71
friend class ImageSource
Definition VideoProperty.hpp:35
bool IsEnum() const
Returns true if property is an enum.
Definition VideoProperty.hpp:106
@ kBoolean
Boolean property.
Definition VideoProperty.hpp:45
@ kString
String property.
Definition VideoProperty.hpp:49
@ kInteger
Integer property.
Definition VideoProperty.hpp:47
@ kNone
No specific property.
Definition VideoProperty.hpp:43
@ kEnum
Enum property.
Definition VideoProperty.hpp:51
int GetPropertyMin(CS_Property property, CS_Status *status)
std::string GetPropertyName(CS_Property property, CS_Status *status)
int GetPropertyDefault(CS_Property property, CS_Status *status)
int GetPropertyMax(CS_Property property, CS_Status *status)
void SetStringProperty(CS_Property property, std::string_view value, CS_Status *status)
CS_PropertyKind GetPropertyKind(CS_Property property, CS_Status *status)
std::string GetStringProperty(CS_Property property, CS_Status *status)
void SetProperty(CS_Property property, int value, CS_Status *status)
int GetPropertyStep(CS_Property property, CS_Status *status)
std::vector< std::string > GetEnumPropertyChoices(CS_Property property, CS_Status *status)
int GetProperty(CS_Property property, CS_Status *status)
int CS_Status
Definition cscore_c.h:41
CS_Handle CS_Property
Definition cscore_c.h:44
CameraServer (cscore) namespace.
Definition CvSource.hpp:15