16 #include <unordered_map> 19 #include <libcamera/base/class.h> 20 #include <libcamera/base/span.h> 26 class ControlValidator;
45 template<
typename T,
typename = std::
void_t<>>
50 struct control_type<void> {
52 static constexpr std::size_t size = 0;
56 struct control_type<bool> {
58 static constexpr std::size_t size = 0;
62 struct control_type<uint8_t> {
64 static constexpr std::size_t size = 0;
68 struct control_type<uint16_t> {
70 static constexpr std::size_t size = 0;
74 struct control_type<uint32_t> {
76 static constexpr std::size_t size = 0;
80 struct control_type<int32_t> {
82 static constexpr std::size_t size = 0;
86 struct control_type<int64_t> {
88 static constexpr std::size_t size = 0;
92 struct control_type<float> {
94 static constexpr std::size_t size = 0;
98 struct control_type<std::string> {
100 static constexpr std::size_t size = 0;
104 struct control_type<Rectangle> {
105 static constexpr
ControlType value = ControlTypeRectangle;
106 static constexpr std::size_t size = 0;
110 struct control_type<Size> {
111 static constexpr
ControlType value = ControlTypeSize;
112 static constexpr std::size_t size = 0;
116 struct control_type<Point> {
117 static constexpr
ControlType value = ControlTypePoint;
118 static constexpr std::size_t size = 0;
121 template<
typename T, std::
size_t N>
122 struct control_type<Span<T, N>> :
public control_type<std::remove_cv_t<T>> {
123 static constexpr std::size_t size = N;
127 struct control_type<T, std::enable_if_t<std::is_enum_v<T>>> :
public control_type<int32_t> {
138 template<typename T, std::enable_if_t<!details::is_span<T>::value &&
139 details::control_type<T>::value &&
140 !std::is_same<std::string, std::remove_cv_t<T>>::value,
141 std::nullptr_t> =
nullptr>
145 set(details::control_type<std::remove_cv_t<T>>::value,
false,
146 &value, 1,
sizeof(T));
149 template<typename T, std::enable_if_t<details::is_span<T>::value ||
150 std::is_same<std::string, std::remove_cv_t<T>>::value,
151 std::nullptr_t> =
nullptr>
158 set(details::control_type<std::remove_cv_t<T>>::value,
true,
159 value.data(), value.size(),
sizeof(
typename T::value_type));
171 Span<const uint8_t> data()
const;
172 Span<uint8_t> data();
174 std::string toString()
const;
179 return !(*
this == other);
183 template<typename T, std::enable_if_t<!details::is_span<T>::value &&
184 !std::is_same<std::string, std::remove_cv_t<T>>::value,
185 std::nullptr_t> =
nullptr>
188 assert(type_ == details::control_type<std::remove_cv_t<T>>::value);
191 return *
reinterpret_cast<const T *
>(data().data());
194 template<typename T, std::enable_if_t<details::is_span<T>::value ||
195 std::is_same<std::string, std::remove_cv_t<T>>::value,
196 std::nullptr_t> =
nullptr>
202 assert(type_ == details::control_type<std::remove_cv_t<T>>::value);
205 using V =
typename T::value_type;
206 const V *value =
reinterpret_cast<const V *
>(data().data());
207 return T{ value, numElements_ };
211 template<typename T, std::enable_if_t<!details::is_span<T>::value &&
212 !std::is_same<std::string, std::remove_cv_t<T>>::value,
213 std::nullptr_t> =
nullptr>
214 void set(
const T &value)
216 set(details::control_type<std::remove_cv_t<T>>::value,
false,
217 reinterpret_cast<const void *
>(&value), 1,
sizeof(T));
220 template<typename T, std::enable_if_t<details::is_span<T>::value ||
221 std::is_same<std::string, std::remove_cv_t<T>>::value,
222 std::nullptr_t> =
nullptr>
226 void set(
const T &value)
228 set(details::control_type<std::remove_cv_t<T>>::value,
true,
229 value.data(), value.size(),
sizeof(
typename T::value_type));
232 void reserve(
ControlType type,
bool isArray =
false,
233 std::size_t numElements = 1);
238 std::size_t numElements_ : 32;
245 void set(
ControlType type,
bool isArray,
const void *data,
246 std::size_t numElements, std::size_t elementSize);
252 ControlId(
unsigned int id,
const std::string &name,
const std::string &vendor,
254 const std::map<std::string, int32_t> &enumStrMap = {});
256 unsigned int id()
const {
return id_; }
257 const std::string &
name()
const {
return name_; }
258 const std::string &
vendor()
const {
return vendor_; }
261 std::size_t
size()
const {
return size_; }
262 const std::map<int32_t, std::string> &
enumerators()
const {
return reverseMap_; }
265 LIBCAMERA_DISABLE_COPY_AND_MOVE(
ControlId)
272 std::map<std::string, int32_t> enumStrMap_;
273 std::map<int32_t, std::string> reverseMap_;
278 return lhs == rhs.
id();
281 static inline bool operator!=(
unsigned int lhs,
const ControlId &rhs)
283 return !(lhs == rhs);
288 return lhs.
id() == rhs;
291 static inline bool operator!=(
const ControlId &lhs,
unsigned int rhs)
293 return !(lhs == rhs);
302 Control(
unsigned int id,
const char *name,
const char *vendor,
303 const std::map<std::string, int32_t> &enumStrMap = {})
304 :
ControlId(
id, name, vendor, details::control_type<std::remove_cv_t<T>>::value,
305 details::control_type<std::remove_cv_t<T>>::size, enumStrMap)
310 LIBCAMERA_DISABLE_COPY_AND_MOVE(
Control)
319 explicit ControlInfo(Span<const ControlValue> values,
321 explicit ControlInfo(std::set<bool> values,
bool def);
322 explicit ControlInfo(
bool value);
327 const std::vector<ControlValue> &
values()
const {
return values_; }
329 std::string toString()
const;
333 return min_ == other.min_ && max_ == other.max_;
338 return !(*
this == other);
345 std::vector<ControlValue> values_;
348 using ControlIdMap = std::unordered_map<unsigned int, const ControlId *>;
350 class ControlInfoMap :
private std::unordered_map<const ControlId *, ControlInfo>
353 using Map = std::unordered_map<const ControlId *, ControlInfo>;
364 using Map::mapped_type;
365 using Map::value_type;
366 using Map::size_type;
368 using Map::const_iterator;
380 mapped_type &at(
unsigned int key);
381 const mapped_type &at(
unsigned int key)
const;
382 size_type count(
unsigned int key)
const;
383 iterator find(
unsigned int key);
384 const_iterator find(
unsigned int key)
const;
397 using ControlListMap = std::unordered_map<unsigned int, ControlValue>;
417 bool empty()
const {
return controls_.empty(); }
418 std::size_t
size()
const {
return controls_.size(); }
423 bool contains(
unsigned int id)
const;
428 const auto entry = controls_.find(ctrl.id());
429 if (entry == controls_.end())
436 template<
typename T,
typename V>
446 template<
typename T,
typename V,
size_t Size>
453 val->
set(Span<
const typename std::remove_cv_t<V>,
Size>{ value.begin(), value.size() });
466 const ControlValidator *validator_;
470 ControlListMap controls_;
bool isArray() const
Determine if the control is an array control.
Definition: controls.h:260
ControlType type() const
Retrieve the data type of the value.
Definition: controls.h:167
ControlValue(const T &value)
Construct a ControlValue of type T.
Definition: controls.h:155
bool operator!=(const ControlValue &other) const
Compare ControlValue instances for non equality.
Definition: controls.h:177
Describe the limits of valid values for a Control.
Definition: controls.h:313
const ControlInfoMap * infoMap() const
Retrieve the ControlInfoMap used to construct the ControlList.
Definition: controls.h:459
const std::string & name() const
Retrieve the control name.
Definition: controls.h:257
T type
The Control template type T.
Definition: controls.h:300
bool operator==(const ColorSpace &lhs, const ColorSpace &rhs)
Compare color spaces for equality.
Definition: color_space.cpp:506
const std::string & vendor() const
Retrieve the vendor name.
Definition: controls.h:258
const ControlValue & def() const
Retrieve the default value of the control.
Definition: controls.h:326
Top-level libcamera namespace.
Definition: bound_method.h:15
const std::map< int32_t, std::string > & enumerators() const
Retrieve the map of enum values to enum names.
Definition: controls.h:262
Abstract type representing the value of a control.
Definition: controls.h:132
void set(const T &value)
Set the control value to value.
Definition: controls.h:226
bool isArray() const
Determine if the value stores an array.
Definition: controls.h:169
Definition: controls.h:34
Control static metadata.
Definition: controls.h:249
void clear()
Removes all controls from the list.
Definition: controls.h:420
Describe a two-dimensional size.
Definition: geometry.h:52
Definition: controls.h:33
Describe a control and its intrinsic properties.
Definition: controls.h:297
bool operator!=(const ControlInfo &other) const
Compare ControlInfo instances for non equality.
Definition: controls.h:336
const std::vector< ControlValue > & values() const
Retrieve the list of valid values.
Definition: controls.h:327
const ControlIdMap * idMap() const
Retrieve the ControlId map used to construct the ControlList.
Definition: controls.h:460
A map of ControlId to ControlInfo.
Definition: controls.h:350
Definition: controls.h:29
bool empty() const
Identify if the list is empty.
Definition: controls.h:417
Definition: controls.h:36
std::unordered_map< const ControlId *, ControlInfo > Map
The base std::unsorted_map<> container.
Definition: controls.h:353
Definition: controls.h:30
ControlType
Define the data type of a Control.
Definition: controls.h:28
ControlListMap::iterator iterator
Iterator for the controls contained within the list.
Definition: controls.h:409
const ControlIdMap & idmap() const
Retrieve the ControlId map.
Definition: controls.h:386
std::size_t size() const
Retrieve the size of the control if it is an array control.
Definition: controls.h:261
ControlListMap::const_iterator const_iterator
Const iterator for the controls contained within the list.
Definition: controls.h:410
const ControlValue & min() const
Retrieve the minimum value of the control.
Definition: controls.h:324
iterator end()
Retrieve an iterator pointing to the past-the-end control in the list.
Definition: controls.h:413
Definition: controls.h:35
iterator begin()
Retrieve an iterator to the first Control in the list.
Definition: controls.h:412
Definition: controls.h:32
unsigned int id() const
Retrieve the control numerical ID.
Definition: controls.h:256
Definition: controls.h:37
const_iterator end() const
Retrieve a const iterator pointing to the past-the-end control in the list.
Definition: controls.h:415
Control(unsigned int id, const char *name, const char *vendor, const std::map< std::string, int32_t > &enumStrMap={})
Construct a Control instance.
Definition: controls.h:302
const ControlValue & max() const
Retrieve the maximum value of the control.
Definition: controls.h:325
std::size_t size() const
Retrieve the number of controls in the list.
Definition: controls.h:418
ControlType type() const
Retrieve the control data type.
Definition: controls.h:259
Associate a list of ControlId with their values for an object.
Definition: controls.h:394
Data structures related to geometric objects.
bool isNone() const
Determine if the value is not initialised.
Definition: controls.h:168
Definition: controls.h:31
bool operator==(const ControlInfo &other) const
Compare ControlInfo instances for equality.
Definition: controls.h:331
std::unordered_map< unsigned int, const ControlId * > ControlIdMap
A map of numerical control ID to ControlId.
Definition: controls.h:348
MergePolicy
The policy used by the merge function.
Definition: controls.h:400
T get() const
Get the control value.
Definition: controls.h:200
std::size_t numElements() const
Retrieve the number of elements stored in the ControlValue.
Definition: controls.h:170
const_iterator begin() const
Retrieve a const_iterator to the first Control in the list.
Definition: controls.h:414