16 #include <unordered_map> 20 #include <libcamera/base/span.h> 26 class ControlValidator;
43 template<
typename T,
typename = std::
void_t<>>
48 struct control_type<void> {
50 static constexpr std::size_t size = 0;
54 struct control_type<bool> {
56 static constexpr std::size_t size = 0;
60 struct control_type<uint8_t> {
62 static constexpr std::size_t size = 0;
66 struct control_type<int32_t> {
68 static constexpr std::size_t size = 0;
72 struct control_type<int64_t> {
74 static constexpr std::size_t size = 0;
78 struct control_type<float> {
80 static constexpr std::size_t size = 0;
84 struct control_type<std::string> {
86 static constexpr std::size_t size = 0;
90 struct control_type<Rectangle> {
91 static constexpr
ControlType value = ControlTypeRectangle;
92 static constexpr std::size_t size = 0;
96 struct control_type<Size> {
97 static constexpr
ControlType value = ControlTypeSize;
98 static constexpr std::size_t size = 0;
102 struct control_type<Point> {
103 static constexpr
ControlType value = ControlTypePoint;
104 static constexpr std::size_t size = 0;
107 template<
typename T, std::
size_t N>
108 struct control_type<Span<T, N>> :
public control_type<std::remove_cv_t<T>> {
109 static constexpr std::size_t size = N;
113 struct control_type<T, std::enable_if_t<std::is_enum_v<T>>> :
public control_type<int32_t> {
124 template<typename T, std::enable_if_t<!details::is_span<T>::value &&
125 details::control_type<T>::value &&
126 !std::is_same<std::string, std::remove_cv_t<T>>::value,
127 std::nullptr_t> =
nullptr>
131 set(details::control_type<std::remove_cv_t<T>>::value,
false,
132 &value, 1,
sizeof(T));
135 template<typename T, std::enable_if_t<details::is_span<T>::value ||
136 std::is_same<std::string, std::remove_cv_t<T>>::value,
137 std::nullptr_t> =
nullptr>
144 set(details::control_type<std::remove_cv_t<T>>::value,
true,
145 value.data(), value.size(),
sizeof(
typename T::value_type));
157 Span<const uint8_t> data()
const;
158 Span<uint8_t> data();
160 std::string toString()
const;
165 return !(*
this == other);
169 template<typename T, std::enable_if_t<!details::is_span<T>::value &&
170 !std::is_same<std::string, std::remove_cv_t<T>>::value,
171 std::nullptr_t> =
nullptr>
174 assert(type_ == details::control_type<std::remove_cv_t<T>>::value);
177 return *
reinterpret_cast<const T *
>(data().data());
180 template<typename T, std::enable_if_t<details::is_span<T>::value ||
181 std::is_same<std::string, std::remove_cv_t<T>>::value,
182 std::nullptr_t> =
nullptr>
188 assert(type_ == details::control_type<std::remove_cv_t<T>>::value);
191 using V =
typename T::value_type;
192 const V *value =
reinterpret_cast<const V *
>(data().data());
193 return T{ value, numElements_ };
197 template<typename T, std::enable_if_t<!details::is_span<T>::value &&
198 !std::is_same<std::string, std::remove_cv_t<T>>::value,
199 std::nullptr_t> =
nullptr>
200 void set(
const T &value)
202 set(details::control_type<std::remove_cv_t<T>>::value,
false,
203 reinterpret_cast<const void *
>(&value), 1,
sizeof(T));
206 template<typename T, std::enable_if_t<details::is_span<T>::value ||
207 std::is_same<std::string, std::remove_cv_t<T>>::value,
208 std::nullptr_t> =
nullptr>
212 void set(
const T &value)
214 set(details::control_type<std::remove_cv_t<T>>::value,
true,
215 value.data(), value.size(),
sizeof(
typename T::value_type));
218 void reserve(
ControlType type,
bool isArray =
false,
219 std::size_t numElements = 1);
224 std::size_t numElements_ : 32;
231 void set(
ControlType type,
bool isArray,
const void *data,
232 std::size_t numElements, std::size_t elementSize);
238 ControlId(
unsigned int id,
const std::string &name,
const std::string &vendor,
240 const std::map<std::string, int32_t> &enumStrMap = {});
242 unsigned int id()
const {
return id_; }
243 const std::string &
name()
const {
return name_; }
244 const std::string &
vendor()
const {
return vendor_; }
247 std::size_t
size()
const {
return size_; }
248 const std::map<int32_t, std::string> &
enumerators()
const {
return reverseMap_; }
258 std::map<std::string, int32_t> enumStrMap_;
259 std::map<int32_t, std::string> reverseMap_;
264 return lhs == rhs.
id();
267 static inline bool operator!=(
unsigned int lhs,
const ControlId &rhs)
269 return !(lhs == rhs);
274 return lhs.
id() == rhs;
277 static inline bool operator!=(
const ControlId &lhs,
unsigned int rhs)
279 return !(lhs == rhs);
288 Control(
unsigned int id,
const char *name,
const char *vendor,
289 const std::map<std::string, int32_t> &enumStrMap = {})
290 :
ControlId(
id, name, vendor, details::control_type<std::remove_cv_t<T>>::value,
291 details::control_type<std::remove_cv_t<T>>::size, enumStrMap)
305 explicit ControlInfo(Span<const ControlValue> values,
307 explicit ControlInfo(std::set<bool> values,
bool def);
308 explicit ControlInfo(
bool value);
313 const std::vector<ControlValue> &
values()
const {
return values_; }
315 std::string toString()
const;
319 return min_ == other.min_ && max_ == other.max_;
324 return !(*
this == other);
331 std::vector<ControlValue> values_;
334 using ControlIdMap = std::unordered_map<unsigned int, const ControlId *>;
336 class ControlInfoMap :
private std::unordered_map<const ControlId *, ControlInfo>
339 using Map = std::unordered_map<const ControlId *, ControlInfo>;
350 using Map::mapped_type;
351 using Map::value_type;
352 using Map::size_type;
354 using Map::const_iterator;
366 mapped_type &at(
unsigned int key);
367 const mapped_type &at(
unsigned int key)
const;
368 size_type count(
unsigned int key)
const;
369 iterator find(
unsigned int key);
370 const_iterator find(
unsigned int key)
const;
383 using ControlListMap = std::unordered_map<unsigned int, ControlValue>;
403 bool empty()
const {
return controls_.empty(); }
404 std::size_t
size()
const {
return controls_.size(); }
409 bool contains(
unsigned int id)
const;
414 const auto entry = controls_.find(ctrl.id());
415 if (entry == controls_.end())
422 template<
typename T,
typename V>
432 template<
typename T,
typename V,
size_t Size>
439 val->
set(Span<
const typename std::remove_cv_t<V>,
Size>{ value.begin(), value.size() });
456 ControlListMap controls_;
bool isArray() const
Determine if the control is an array control.
Definition: controls.h:246
ControlType type() const
Retrieve the data type of the value.
Definition: controls.h:153
ControlValue(const T &value)
Construct a ControlValue of type T.
Definition: controls.h:141
bool operator!=(const ControlValue &other) const
Compare ControlValue instances for non equality.
Definition: controls.h:163
Utilities to help constructing class interfaces.
Describe the limits of valid values for a Control.
Definition: controls.h:299
const ControlInfoMap * infoMap() const
Retrieve the ControlInfoMap used to construct the ControlList.
Definition: controls.h:445
const std::string & name() const
Retrieve the control name.
Definition: controls.h:243
T type
The Control template type T.
Definition: controls.h:286
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:244
const ControlValue & def() const
Retrieve the default value of the control.
Definition: controls.h:312
Top-level libcamera namespace.
Definition: backtrace.h:17
const std::map< int32_t, std::string > & enumerators() const
Retrieve the map of enum values to enum names.
Definition: controls.h:248
Abstract type representing the value of a control.
Definition: controls.h:118
void set(const T &value)
Set the control value to value.
Definition: controls.h:212
Interface for the control validator.
Definition: control_validator.h:16
bool isArray() const
Determine if the value stores an array.
Definition: controls.h:155
Definition: controls.h:32
Control static metadata.
Definition: controls.h:235
void clear()
Removes all controls from the list.
Definition: controls.h:406
Describe a two-dimensional size.
Definition: geometry.h:52
Describe a control and its intrinsic properties.
Definition: controls.h:283
bool operator!=(const ControlInfo &other) const
Compare ControlInfo instances for non equality.
Definition: controls.h:322
const std::vector< ControlValue > & values() const
Retrieve the list of valid values.
Definition: controls.h:313
const ControlIdMap * idMap() const
Retrieve the ControlId map used to construct the ControlList.
Definition: controls.h:446
A map of ControlId to ControlInfo.
Definition: controls.h:336
Definition: controls.h:29
bool empty() const
Identify if the list is empty.
Definition: controls.h:403
Definition: controls.h:34
std::unordered_map< const ControlId *, ControlInfo > Map
The base std::unsorted_map<> container.
Definition: controls.h:339
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:395
const ControlIdMap & idmap() const
Retrieve the ControlId map.
Definition: controls.h:372
std::size_t size() const
Retrieve the size of the control if it is an array control.
Definition: controls.h:247
ControlListMap::const_iterator const_iterator
Const iterator for the controls contained within the list.
Definition: controls.h:396
const ControlValue & min() const
Retrieve the minimum value of the control.
Definition: controls.h:310
#define LIBCAMERA_DISABLE_COPY_AND_MOVE(klass)
Disable copy and move construction and assignment of the klass.
iterator end()
Retrieve an iterator pointing to the past-the-end control in the list.
Definition: controls.h:399
Definition: controls.h:33
iterator begin()
Retrieve an iterator to the first Control in the list.
Definition: controls.h:398
unsigned int id() const
Retrieve the control numerical ID.
Definition: controls.h:242
Definition: controls.h:35
const_iterator end() const
Retrieve a const iterator pointing to the past-the-end control in the list.
Definition: controls.h:401
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:288
const ControlValue & max() const
Retrieve the maximum value of the control.
Definition: controls.h:311
std::size_t size() const
Retrieve the number of controls in the list.
Definition: controls.h:404
ControlType type() const
Retrieve the control data type.
Definition: controls.h:245
Associate a list of ControlId with their values for an object.
Definition: controls.h:380
Data structures related to geometric objects.
bool isNone() const
Determine if the value is not initialised.
Definition: controls.h:154
Definition: controls.h:31
bool operator==(const ControlInfo &other) const
Compare ControlInfo instances for equality.
Definition: controls.h:317
std::unordered_map< unsigned int, const ControlId * > ControlIdMap
A map of numerical control ID to ControlId.
Definition: controls.h:334
MergePolicy
The policy used by the merge function.
Definition: controls.h:386
T get() const
Get the control value.
Definition: controls.h:186
std::size_t numElements() const
Retrieve the number of elements stored in the ControlValue.
Definition: controls.h:156
const_iterator begin() const
Retrieve a const_iterator to the first Control in the list.
Definition: controls.h:400