17#include <unordered_map>
21#include <libcamera/base/class.h>
28class ControlValidator;
48struct is_span :
public std::false_type {
51template<
typename T, std::
size_t Extent>
52struct is_span<std::span<T, Extent>> :
public std::true_type {
55template<
typename T,
typename =
void>
60struct control_type<void> {
62 static constexpr std::size_t size = 0;
66struct control_type<bool> {
68 static constexpr std::size_t size = 0;
72struct control_type<uint8_t> {
74 static constexpr std::size_t size = 0;
78struct control_type<uint16_t> {
80 static constexpr std::size_t size = 0;
84struct control_type<uint32_t> {
86 static constexpr std::size_t size = 0;
90struct control_type<int32_t> {
92 static constexpr std::size_t size = 0;
96struct control_type<int64_t> {
98 static constexpr std::size_t size = 0;
102struct control_type<float> {
104 static constexpr std::size_t size = 0;
108struct control_type<std::string_view> {
110 static constexpr std::size_t size = 0;
114struct control_type<Rectangle> {
115 static constexpr ControlType value = ControlTypeRectangle;
116 static constexpr std::size_t size = 0;
120struct control_type<Size> {
121 static constexpr ControlType value = ControlTypeSize;
122 static constexpr std::size_t size = 0;
126struct control_type<Point> {
127 static constexpr ControlType value = ControlTypePoint;
128 static constexpr std::size_t size = 0;
131template<
typename T, std::
size_t N>
132struct control_type<std::span<T, N>, std::enable_if_t<control_type<std::remove_cv_t<T>>::size == 0>> :
public control_type<std::remove_cv_t<T>> {
133 static constexpr std::size_t size = N;
137struct control_type<T, std::enable_if_t<std::is_enum_v<T> && sizeof(T) == sizeof(int32_t)>> :
public control_type<int32_t> {
149 details::control_type<T>::value &&
150 !std::is_same<std::string_view, std::remove_cv_t<T>>::value,
151 std::nullptr_t> =
nullptr>
155 set(details::control_type<std::remove_cv_t<T>>::value,
false,
156 &value, 1,
sizeof(
T));
160 std::is_same<std::string_view, std::remove_cv_t<T>>::value,
161 std::nullptr_t> =
nullptr>
168 set(details::control_type<std::remove_cv_t<T>>::value,
true,
169 value.data(), value.size(),
sizeof(
typename T::value_type));
179 isArray_(std::exchange(
other.isArray_,
false)),
180 numElements_(std::exchange(
other.numElements_, 0)),
181 storage_(std::exchange(
other.storage_, {}))
187 if (
this != &
other) {
191 isArray_ = std::exchange(
other.isArray_,
false);
192 numElements_ = std::exchange(
other.numElements_, 0);
193 storage_ = std::exchange(
other.storage_, {});
203 std::span<const uint8_t>
data()
const;
204 std::span<uint8_t>
data();
211 return !(*
this ==
other);
216 !std::is_same<std::string_view, std::remove_cv_t<T>>::value,
217 std::nullptr_t> =
nullptr>
220 assert(type_ == details::control_type<std::remove_cv_t<T>>::value);
223 return *
reinterpret_cast<const T *
>(
data().data());
226 template<typename T, std::enable_if_t<details::is_span<T>::value ||
227 std::is_same<std::string_view, std::remove_cv_t<T>>::value,
228 std::nullptr_t> =
nullptr>
234 assert(type_ == details::control_type<std::remove_cv_t<T>>::value);
237 using V =
typename T::value_type;
238 const V *value =
reinterpret_cast<const V *
>(
data().data());
239 return T{ value, numElements_ };
244 !std::is_same<std::string_view, std::remove_cv_t<T>>::value,
245 std::nullptr_t> =
nullptr>
246 void set(
const T &value)
248 set(details::control_type<std::remove_cv_t<T>>::value,
false,
249 reinterpret_cast<const void *
>(&value), 1,
sizeof(
T));
252 template<typename T, std::enable_if_t<details::is_span<T>::value ||
253 std::is_same<std::string_view, std::remove_cv_t<T>>::value,
254 std::nullptr_t> =
nullptr>
260 set(details::control_type<std::remove_cv_t<T>>::value,
true,
261 value.data(), value.size(),
sizeof(
typename T::value_type));
269 std::swap(type_,
other.type_);
270 std::swap(isArray_,
other.isArray_);
271 std::swap(numElements_,
other.numElements_);
272 std::swap(storage_,
other.storage_);
306 std::size_t
size = 0,
307 const std::map<std::string, int32_t> &
enumStrMap = {});
309 unsigned int id()
const {
return id_; }
310 const std::string &
name()
const {
return name_; }
311 const std::string &
vendor()
const {
return vendor_; }
317 std::size_t
size()
const {
return size_; }
318 const std::map<int32_t, std::string> &
enumerators()
const {
return reverseMap_; }
329 std::map<std::string, int32_t> enumStrMap_;
330 std::map<int32_t, std::string> reverseMap_;
335static inline bool operator==(
unsigned int lhs,
const ControlId &rhs)
337 return lhs == rhs.id();
340static inline bool operator!=(
unsigned int lhs,
const ControlId &rhs)
342 return !(lhs == rhs);
345static inline bool operator==(
const ControlId &lhs,
unsigned int rhs)
347 return lhs.id() == rhs;
350static inline bool operator!=(
const ControlId &lhs,
unsigned int rhs)
352 return !(lhs == rhs);
363 const std::map<std::string, int32_t> &
enumStrMap = {})
370 LIBCAMERA_DISABLE_COPY_AND_MOVE(Control)
385 const std::vector<ControlValue> &
values()
const {
return values_; }
391 return min_ ==
other.min_ && max_ ==
other.max_;
396 return !(*
this ==
other);
403 std::vector<ControlValue> values_;
406using ControlIdMap = std::unordered_map<unsigned int, const ControlId *>;
411 using Map = std::unordered_map<const ControlId *, ControlInfo>;
422 using Map::mapped_type;
423 using Map::value_type;
424 using Map::size_type;
426 using Map::const_iterator;
441 iterator
find(
unsigned int key);
442 const_iterator
find(
unsigned int key)
const;
455 using ControlListMap = std::unordered_map<unsigned int, ControlValue>;
475 bool empty()
const {
return controls_.empty(); }
476 std::size_t
size()
const {
return controls_.size(); }
481 bool contains(
unsigned int id)
const;
486 const auto entry = controls_.find(
ctrl.id());
487 if (
entry == controls_.end())
494 template<
typename T,
typename V>
504 template<
typename T,
typename V,
size_t Size>
505 void set(
const Control<std::span<T, Size>> &
ctrl,
const std::initializer_list<V> &value)
511 val->set(std::span<
const typename std::remove_cv_t<V>,
Size>{ value.begin(), value.size() });
529 ControlListMap controls_;
Control static metadata.
Definition controls.h:295
const std::map< int32_t, std::string > & enumerators() const
Retrieve the map of enum values to enum names.
Definition controls.h:318
ControlType type() const
Retrieve the control data type.
Definition controls.h:312
bool isOutput() const
Determine if the control is available to be used in output metadata.
Definition controls.h:315
bool isInput() const
Determine if the control is available to be used as an input control.
Definition controls.h:314
Flags< Direction > DirectionFlags
A wrapper for ControlId::Direction so that it can be used as flags.
Definition controls.h:302
Direction
The direction the control is capable of being passed from/to.
Definition controls.h:297
@ Out
The control can be returned as output in metadata.
@ In
The control can be passed as input in controls.
const std::string & vendor() const
Retrieve the vendor name.
Definition controls.h:311
bool isArray() const
Determine if the control is an array control.
Definition controls.h:316
DirectionFlags direction() const
Return the direction that the control can be used in.
Definition controls.h:313
const std::string & name() const
Retrieve the control name.
Definition controls.h:310
std::size_t size() const
Retrieve the size of the control if it is an array control.
Definition controls.h:317
unsigned int id() const
Retrieve the control numerical ID.
Definition controls.h:309
A map of ControlId to ControlInfo.
Definition controls.h:409
mapped_type & at(unsigned int key)
Access specified element by numerical ID.
Definition controls.cpp:838
const ControlIdMap & idmap() const
Retrieve the ControlId map.
Definition controls.h:444
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:411
iterator find(unsigned int key)
Find the element matching a numerical ID.
Definition controls.cpp:873
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:862
Describe the limits of valid values for a Control.
Definition controls.h:374
const std::vector< ControlValue > & values() const
Retrieve the list of valid values.
Definition controls.h:385
std::string toString() const
Provide a string representation of the ControlInfo.
Definition controls.cpp:703
bool operator==(const ControlInfo &other) const
Compare ControlInfo instances for equality.
Definition controls.h:389
bool operator!=(const ControlInfo &other) const
Compare ControlInfo instances for non equality.
Definition controls.h:394
const ControlValue & max() const
Retrieve the maximum value of the control.
Definition controls.h:383
const ControlValue & def() const
Retrieve the default value of the control.
Definition controls.h:384
const ControlValue & min() const
Retrieve the minimum value of the control.
Definition controls.h:382
Associate a list of ControlId with their values for an object.
Definition controls.h:453
void set(const Control< std::span< T, Size > > &ctrl, const std::initializer_list< V > &value)
Set the control ctrl value to value.
Definition controls.h:505
void merge(const ControlList &source, MergePolicy policy=MergePolicy::KeepExisting)
Merge the source into the ControlList.
Definition controls.cpp:1045
void clear()
Removes all controls from the list.
Definition controls.h:478
const ControlInfoMap * infoMap() const
Retrieve the ControlInfoMap used to construct the ControlList.
Definition controls.h:518
const ControlIdMap * idMap() const
Retrieve the ControlId map used to construct the ControlList.
Definition controls.h:519
ControlListMap::const_iterator const_iterator
Const iterator for the controls contained within the list.
Definition controls.h:468
iterator end()
Retrieve an iterator pointing to the past-the-end control in the list.
Definition controls.h:471
MergePolicy
The policy used by the merge function.
Definition controls.h:458
@ OverwriteExisting
Existing controls in the target list are updated.
@ 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:476
ControlListMap::iterator iterator
Iterator for the controls contained within the list.
Definition controls.h:467
std::optional< T > get(const Control< T > &ctrl) const
Get the value of control ctrl.
Definition controls.h:484
bool empty() const
Identify if the list is empty.
Definition controls.h:475
void set(const Control< T > &ctrl, const V &value)
Set the control ctrl value to value.
Definition controls.h:495
iterator begin()
Retrieve an iterator to the first Control in the list.
Definition controls.h:470
bool contains(unsigned int id) const
Check if the list contains a control with the specified id.
Definition controls.cpp:1077
const_iterator begin() const
Retrieve a const_iterator to the first Control in the list.
Definition controls.h:472
ControlList()
Construct a ControlList not associated with any object.
Definition controls.cpp:933
const_iterator end() const
Retrieve a const iterator pointing to the past-the-end control in the list.
Definition controls.h:473
Abstract type representing the value of a control.
Definition controls.h:143
void swap(ControlValue &other) noexcept
Swap two control values.
Definition controls.h:267
ControlValue & operator=(ControlValue &&other) noexcept
Move assignment operator for ControlValue.
Definition controls.h:185
T get() const
Get the control value.
Definition controls.h:232
bool isArray() const
Determine if the value stores an array.
Definition controls.h:201
ControlValue & operator=(const ControlValue &other)
Replace the content of the ControlValue with a copy of the content of other.
Definition controls.cpp:152
void reserve(ControlType type, bool isArray=false, std::size_t numElements=1)
Set the control type and reserve memory.
Definition controls.cpp:394
bool operator==(const ControlValue &other) const
Compare ControlValue instances for equality.
Definition controls.cpp:318
void set(const T &value)
Set the control value to value.
Definition controls.h:258
ControlValue()
Construct an empty ControlValue.
Definition controls.cpp:104
bool operator!=(const ControlValue &other) const
Compare ControlValue instances for non equality.
Definition controls.h:209
std::span< const uint8_t > data() const
Retrieve the raw data of a control value.
Definition controls.cpp:210
ControlValue(const T &value)
Construct a ControlValue of type T.
Definition controls.h:165
ControlType type() const
Retrieve the data type of the value.
Definition controls.h:199
std::string toString() const
Assemble and return a string describing the value.
Definition controls.cpp:232
ControlValue(ControlValue &&other) noexcept
Move constructor for ControlValue.
Definition controls.h:177
friend void swap(ControlValue &a, ControlValue &b) noexcept
Swap two control values.
Definition controls.h:275
bool isNone() const
Determine if the value is not initialised.
Definition controls.h:200
std::size_t numElements() const
Retrieve the number of elements stored in the ControlValue.
Definition controls.h:202
Describe a control and its intrinsic properties.
Definition controls.h:357
Control(unsigned int id, const char *name, const char *vendor, ControlId::DirectionFlags direction, const std::map< std::string, int32_t > &enumStrMap={})
Construct a Control instance.
Definition controls.h:361
Type-safe container for enum-based bitfields.
Definition flags.h:16
Describe a two-dimensional size.
Definition geometry.h:51
#define LIBCAMERA_FLAGS_ENABLE_OPERATORS(_enum)
Enable bitwise operations on the enum enumeration.
Definition flags.h:189
Data structures related to geometric objects.
Top-level libcamera namespace.
Definition bound_method.h:15
ControlType
Define the data type of a Control.
Definition controls.h:30
@ ControlTypeNone
Definition controls.h:31
@ ControlTypeFloat
Definition controls.h:38
@ ControlTypeUnsigned16
Definition controls.h:34
@ ControlTypeBool
Definition controls.h:32
@ ControlTypeUnsigned32
Definition controls.h:35
@ ControlTypeInteger32
Definition controls.h:36
@ ControlTypeString
Definition controls.h:39
@ ControlTypeInteger64
Definition controls.h:37
@ ControlTypeByte
Definition controls.h:33
std::unordered_map< unsigned int, const ControlId * > ControlIdMap
A map of numerical control ID to ControlId.
Definition controls.h:406
bool operator==(const ColorSpace &lhs, const ColorSpace &rhs)
Compare color spaces for equality.
Definition color_space.cpp:506