16#include <unordered_map>
20#include <libcamera/base/span.h>
26class ControlValidator;
43template<
typename T,
typename = std::
void_t<>>
48struct control_type<void> {
50 static constexpr std::size_t size = 0;
54struct control_type<bool> {
56 static constexpr std::size_t size = 0;
60struct control_type<uint8_t> {
62 static constexpr std::size_t size = 0;
66struct control_type<int32_t> {
68 static constexpr std::size_t size = 0;
72struct control_type<int64_t> {
74 static constexpr std::size_t size = 0;
78struct control_type<float> {
80 static constexpr std::size_t size = 0;
84struct control_type<std::string> {
86 static constexpr std::size_t size = 0;
90struct control_type<Rectangle> {
91 static constexpr ControlType value = ControlTypeRectangle;
92 static constexpr std::size_t size = 0;
96struct control_type<Size> {
97 static constexpr ControlType value = ControlTypeSize;
98 static constexpr std::size_t size = 0;
102struct control_type<Point> {
103 static constexpr ControlType value = ControlTypePoint;
104 static constexpr std::size_t size = 0;
107template<
typename T, std::
size_t N>
108struct control_type<Span<T, N>> :
public control_type<std::remove_cv_t<T>> {
109 static constexpr std::size_t size = N;
113struct 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();
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>
214 set(details::control_type<std::remove_cv_t<T>>::value,
true,
215 value.data(), value.size(),
sizeof(
typename T::value_type));
224 std::size_t numElements_ : 32;
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_;
262static inline bool operator==(
unsigned int lhs,
const ControlId &rhs)
264 return lhs == rhs.id();
267static inline bool operator!=(
unsigned int lhs,
const ControlId &rhs)
269 return !(lhs == rhs);
272static inline bool operator==(
const ControlId &lhs,
unsigned int rhs)
274 return lhs.id() == rhs;
277static inline bool operator!=(
const ControlId &lhs,
unsigned int rhs)
279 return !(lhs == rhs);
289 const std::map<std::string, int32_t> &enumStrMap = {})
291 details::control_type<std::remove_cv_t<T>>
::size, enumStrMap)
313 const std::vector<ControlValue> &
values()
const {
return values_; }
319 return min_ == other.min_ && max_ == other.max_;
324 return !(*
this == other);
331 std::vector<ControlValue> values_;
334using ControlIdMap = std::unordered_map<unsigned int, const ControlId *>;
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>
433 void set(
const Control<Span<T, Size>> &ctrl,
const std::initializer_list<V> &value)
439 val->
set(Span<
const typename std::remove_cv_t<V>,
Size>{ value.begin(), value.size() });
456 ControlListMap controls_;
Utilities to help constructing class interfaces.
#define LIBCAMERA_DISABLE_COPY_AND_MOVE(klass)
Disable copy and move construction and assignment of the klass.
Control static metadata.
Definition: controls.h:236
ControlId(unsigned int id, const std::string &name, const std::string &vendor, ControlType type, std::size_t size=0, const std::map< std::string, int32_t > &enumStrMap={})
Construct a ControlId instance.
Definition: controls.cpp:402
const std::map< int32_t, std::string > & enumerators() const
Retrieve the map of enum values to enum names.
Definition: controls.h:248
ControlType type() const
Retrieve the control data type.
Definition: controls.h:245
const std::string & vendor() const
Retrieve the vendor name.
Definition: controls.h:244
bool isArray() const
Determine if the control is an array control.
Definition: controls.h:246
const std::string & name() const
Retrieve the control name.
Definition: controls.h:243
std::size_t size() const
Retrieve the size of the control if it is an array control.
Definition: controls.h:247
unsigned int id() const
Retrieve the control numerical ID.
Definition: controls.h:242
A map of ControlId to ControlInfo.
Definition: controls.h:337
mapped_type & at(unsigned int key)
Access specified element by numerical ID.
Definition: controls.cpp:768
const ControlIdMap & idmap() const
Retrieve the ControlId map.
Definition: controls.h:372
ControlInfoMap & operator=(const ControlInfoMap &other)=default
Copy assignment operator, replace the contents with a copy of other.
std::unordered_map< const ControlId *, ControlInfo > Map
The base std::unsorted_map<> container.
Definition: controls.h:339
iterator find(unsigned int key)
Find the element matching a numerical ID.
Definition: controls.cpp:811
ControlInfoMap(const ControlInfoMap &other)=default
Copy constructor, construct a ControlInfoMap from a copy of other.
size_type count(unsigned int key) const
Count the number of elements matching a numerical ID.
Definition: controls.cpp:792
Describe the limits of valid values for a Control.
Definition: controls.h:300
const std::vector< ControlValue > & values() const
Retrieve the list of valid values.
Definition: controls.h:313
std::string toString() const
Provide a string representation of the ControlInfo.
Definition: controls.cpp:633
ControlInfo(const ControlValue &min={}, const ControlValue &max={}, const ControlValue &def={})
Construct a ControlInfo with minimum and maximum range parameters.
Definition: controls.cpp:533
bool operator==(const ControlInfo &other) const
Compare ControlInfo instances for equality.
Definition: controls.h:317
bool operator!=(const ControlInfo &other) const
Compare ControlInfo instances for non equality.
Definition: controls.h:322
const ControlValue & max() const
Retrieve the maximum value of the control.
Definition: controls.h:311
const ControlValue & def() const
Retrieve the default value of the control.
Definition: controls.h:312
const ControlValue & min() const
Retrieve the minimum value of the control.
Definition: controls.h:310
Associate a list of ControlId with their values for an object.
Definition: controls.h:381
void merge(const ControlList &source, MergePolicy policy=MergePolicy::KeepExisting)
Merge the source into the ControlList.
Definition: controls.cpp:983
void clear()
Removes all controls from the list.
Definition: controls.h:406
const ControlInfoMap * infoMap() const
Retrieve the ControlInfoMap used to construct the ControlList.
Definition: controls.h:445
const ControlIdMap * idMap() const
Retrieve the ControlId map used to construct the ControlList.
Definition: controls.h:446
void set(const Control< Span< T, Size > > &ctrl, const std::initializer_list< V > &value)
Definition: controls.h:433
ControlListMap::const_iterator const_iterator
Const iterator for the controls contained within the list.
Definition: controls.h:396
iterator end()
Retrieve an iterator pointing to the past-the-end control in the list.
Definition: controls.h:399
MergePolicy
The policy used by the merge function.
Definition: controls.h:386
@ KeepExisting
Existing controls in the target list are kept.
std::size_t size() const
Retrieve the number of controls in the list.
Definition: controls.h:404
ControlListMap::iterator iterator
Iterator for the controls contained within the list.
Definition: controls.h:395
std::optional< T > get(const Control< T > &ctrl) const
Get the value of control ctrl.
Definition: controls.h:412
bool empty() const
Identify if the list is empty.
Definition: controls.h:403
void set(const Control< T > &ctrl, const V &value)
Set the control ctrl value to value.
Definition: controls.h:423
iterator begin()
Retrieve an iterator to the first Control in the list.
Definition: controls.h:398
bool contains(unsigned int id) const
Check if the list contains a control with the specified id.
Definition: controls.cpp:1015
const_iterator begin() const
Retrieve a const_iterator to the first Control in the list.
Definition: controls.h:400
ControlList()
Construct a ControlList not associated with any object.
Definition: controls.cpp:871
const_iterator end() const
Retrieve a const iterator pointing to the past-the-end control in the list.
Definition: controls.h:401
Interface for the control validator.
Definition: control_validator.h:17
Abstract type representing the value of a control.
Definition: controls.h:119
T get() const
Get the control value.
Definition: controls.h:186
bool isArray() const
Determine if the value stores an array.
Definition: controls.h:155
ControlValue & operator=(const ControlValue &other)
Replace the content of the ControlValue with a copy of the content of other.
Definition: controls.cpp:146
void reserve(ControlType type, bool isArray=false, std::size_t numElements=1)
Set the control type and reserve memory.
Definition: controls.cpp:360
bool operator==(const ControlValue &other) const
Compare ControlValue instances for equality.
Definition: controls.cpp:284
void set(const T &value)
Set the control value to value.
Definition: controls.h:212
ControlValue()
Construct an empty ControlValue.
Definition: controls.cpp:98
bool operator!=(const ControlValue &other) const
Compare ControlValue instances for non equality.
Definition: controls.h:163
ControlValue(const T &value)
Construct a ControlValue of type T.
Definition: controls.h:141
ControlType type() const
Retrieve the data type of the value.
Definition: controls.h:153
std::string toString() const
Assemble and return a string describing the value.
Definition: controls.cpp:208
bool isNone() const
Determine if the value is not initialised.
Definition: controls.h:154
std::size_t numElements() const
Retrieve the number of elements stored in the ControlValue.
Definition: controls.h:156
Span< const uint8_t > data() const
Retrieve the raw data of a control value.
Definition: controls.cpp:186
Describe a control and its intrinsic properties.
Definition: controls.h:284
T type
The Control template type T.
Definition: controls.h:286
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
Describe a two-dimensional size.
Definition: geometry.h:53
Data structures related to geometric objects.
Top-level libcamera namespace.
Definition: backtrace.h:17
ControlType
Define the data type of a Control.
Definition: controls.h:28
@ ControlTypeNone
Definition: controls.h:29
@ ControlTypeFloat
Definition: controls.h:34
@ ControlTypeBool
Definition: controls.h:30
@ ControlTypeInteger32
Definition: controls.h:32
@ ControlTypeString
Definition: controls.h:35
@ ControlTypeInteger64
Definition: controls.h:33
@ ControlTypeByte
Definition: controls.h:31
std::unordered_map< unsigned int, const ControlId * > ControlIdMap
A map of numerical control ID to ControlId.
Definition: controls.h:334
bool operator==(const ColorSpace &lhs, const ColorSpace &rhs)
Compare color spaces for equality.
Definition: color_space.cpp:506