16 #include <unordered_map> 21 #include <libcamera/base/span.h> 27 class ControlValidator;
46 template<
typename T,
typename = std::
void_t<>>
51 struct control_type<void> {
53 static constexpr std::size_t size = 0;
57 struct control_type<bool> {
59 static constexpr std::size_t size = 0;
63 struct control_type<uint8_t> {
65 static constexpr std::size_t size = 0;
69 struct control_type<uint16_t> {
71 static constexpr std::size_t size = 0;
75 struct control_type<uint32_t> {
77 static constexpr std::size_t size = 0;
81 struct control_type<int32_t> {
83 static constexpr std::size_t size = 0;
87 struct control_type<int64_t> {
89 static constexpr std::size_t size = 0;
93 struct control_type<float> {
95 static constexpr std::size_t size = 0;
99 struct control_type<std::string> {
101 static constexpr std::size_t size = 0;
105 struct control_type<Rectangle> {
106 static constexpr
ControlType value = ControlTypeRectangle;
107 static constexpr std::size_t size = 0;
111 struct control_type<Size> {
112 static constexpr
ControlType value = ControlTypeSize;
113 static constexpr std::size_t size = 0;
117 struct control_type<Point> {
118 static constexpr
ControlType value = ControlTypePoint;
119 static constexpr std::size_t size = 0;
122 template<
typename T, std::
size_t N>
123 struct control_type<Span<T, N>> :
public control_type<std::remove_cv_t<T>> {
124 static constexpr std::size_t size = N;
128 struct control_type<T, std::enable_if_t<std::is_enum_v<T>>> :
public control_type<int32_t> {
139 template<typename T, std::enable_if_t<!details::is_span<T>::value &&
140 details::control_type<T>::value &&
141 !std::is_same<std::string, std::remove_cv_t<T>>::value,
142 std::nullptr_t> =
nullptr>
146 set(details::control_type<std::remove_cv_t<T>>::value,
false,
147 &value, 1,
sizeof(T));
150 template<typename T, std::enable_if_t<details::is_span<T>::value ||
151 std::is_same<std::string, std::remove_cv_t<T>>::value,
152 std::nullptr_t> =
nullptr>
159 set(details::control_type<std::remove_cv_t<T>>::value,
true,
160 value.data(), value.size(),
sizeof(
typename T::value_type));
172 Span<const uint8_t> data()
const;
173 Span<uint8_t> data();
175 std::string toString()
const;
180 return !(*
this == other);
184 template<typename T, std::enable_if_t<!details::is_span<T>::value &&
185 !std::is_same<std::string, std::remove_cv_t<T>>::value,
186 std::nullptr_t> =
nullptr>
189 assert(type_ == details::control_type<std::remove_cv_t<T>>::value);
192 return *
reinterpret_cast<const T *
>(data().data());
195 template<typename T, std::enable_if_t<details::is_span<T>::value ||
196 std::is_same<std::string, std::remove_cv_t<T>>::value,
197 std::nullptr_t> =
nullptr>
203 assert(type_ == details::control_type<std::remove_cv_t<T>>::value);
206 using V =
typename T::value_type;
207 const V *value =
reinterpret_cast<const V *
>(data().data());
208 return T{ value, numElements_ };
212 template<typename T, std::enable_if_t<!details::is_span<T>::value &&
213 !std::is_same<std::string, std::remove_cv_t<T>>::value,
214 std::nullptr_t> =
nullptr>
215 void set(
const T &value)
217 set(details::control_type<std::remove_cv_t<T>>::value,
false,
218 reinterpret_cast<const void *
>(&value), 1,
sizeof(T));
221 template<typename T, std::enable_if_t<details::is_span<T>::value ||
222 std::is_same<std::string, std::remove_cv_t<T>>::value,
223 std::nullptr_t> =
nullptr>
227 void set(
const T &value)
229 set(details::control_type<std::remove_cv_t<T>>::value,
true,
230 value.data(), value.size(),
sizeof(
typename T::value_type));
233 void reserve(
ControlType type,
bool isArray =
false,
234 std::size_t numElements = 1);
239 std::size_t numElements_ : 32;
246 void set(
ControlType type,
bool isArray,
const void *data,
247 std::size_t numElements, std::size_t elementSize);
260 ControlId(
unsigned int id,
const std::string &name,
const std::string &vendor,
262 std::size_t size = 0,
263 const std::map<std::string, int32_t> &enumStrMap = {});
265 unsigned int id()
const {
return id_; }
266 const std::string &
name()
const {
return name_; }
267 const std::string &
vendor()
const {
return vendor_; }
270 bool isInput()
const {
return !!(direction_ & Direction::In); }
271 bool isOutput()
const {
return !!(direction_ & Direction::Out); }
273 std::size_t
size()
const {
return size_; }
274 const std::map<int32_t, std::string> &
enumerators()
const {
return reverseMap_; }
285 std::map<std::string, int32_t> enumStrMap_;
286 std::map<int32_t, std::string> reverseMap_;
293 return lhs == rhs.
id();
296 static inline bool operator!=(
unsigned int lhs,
const ControlId &rhs)
298 return !(lhs == rhs);
303 return lhs.
id() == rhs;
306 static inline bool operator!=(
const ControlId &lhs,
unsigned int rhs)
308 return !(lhs == rhs);
317 Control(
unsigned int id,
const char *name,
const char *vendor,
319 const std::map<std::string, int32_t> &enumStrMap = {})
320 :
ControlId(
id, name, vendor, details::control_type<std::remove_cv_t<T>>::value,
321 direction, details::control_type<std::remove_cv_t<T>>::size, enumStrMap)
335 explicit ControlInfo(Span<const ControlValue> values,
337 explicit ControlInfo(std::set<bool> values,
bool def);
338 explicit ControlInfo(
bool value);
343 const std::vector<ControlValue> &
values()
const {
return values_; }
345 std::string toString()
const;
349 return min_ == other.min_ && max_ == other.max_;
354 return !(*
this == other);
361 std::vector<ControlValue> values_;
364 using ControlIdMap = std::unordered_map<unsigned int, const ControlId *>;
366 class ControlInfoMap :
private std::unordered_map<const ControlId *, ControlInfo>
369 using Map = std::unordered_map<const ControlId *, ControlInfo>;
380 using Map::mapped_type;
381 using Map::value_type;
382 using Map::size_type;
384 using Map::const_iterator;
396 mapped_type &at(
unsigned int key);
397 const mapped_type &at(
unsigned int key)
const;
398 size_type count(
unsigned int key)
const;
399 iterator find(
unsigned int key);
400 const_iterator find(
unsigned int key)
const;
413 using ControlListMap = std::unordered_map<unsigned int, ControlValue>;
433 bool empty()
const {
return controls_.empty(); }
434 std::size_t
size()
const {
return controls_.size(); }
439 bool contains(
unsigned int id)
const;
444 const auto entry = controls_.find(ctrl.id());
445 if (entry == controls_.end())
452 template<
typename T,
typename V>
462 template<
typename T,
typename V,
size_t Size>
469 val->
set(Span<
const typename std::remove_cv_t<V>,
Size>{ value.begin(), value.size() });
486 ControlListMap controls_;
bool isArray() const
Determine if the control is an array control.
Definition: controls.h:272
ControlType type() const
Retrieve the data type of the value.
Definition: controls.h:168
ControlValue(const T &value)
Construct a ControlValue of type T.
Definition: controls.h:156
bool operator!=(const ControlValue &other) const
Compare ControlValue instances for non equality.
Definition: controls.h:178
Utilities to help constructing class interfaces.
Describe the limits of valid values for a Control.
Definition: controls.h:329
const ControlInfoMap * infoMap() const
Retrieve the ControlInfoMap used to construct the ControlList.
Definition: controls.h:475
const std::string & name() const
Retrieve the control name.
Definition: controls.h:266
T type
The Control template type T.
Definition: controls.h:315
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:267
const ControlValue & def() const
Retrieve the default value of the control.
Definition: controls.h:342
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:274
Abstract type representing the value of a control.
Definition: controls.h:133
void set(const T &value)
Set the control value to value.
Definition: controls.h:227
bool isInput() const
Determine if the control is available to be used as an input control.
Definition: controls.h:270
Interface for the control validator.
Definition: control_validator.h:16
bool isArray() const
Determine if the value stores an array.
Definition: controls.h:170
Definition: controls.h:35
Control static metadata.
Definition: controls.h:250
void clear()
Removes all controls from the list.
Definition: controls.h:436
Describe a two-dimensional size.
Definition: geometry.h:50
Definition: controls.h:34
Describe a control and its intrinsic properties.
Definition: controls.h:312
bool operator!=(const ControlInfo &other) const
Compare ControlInfo instances for non equality.
Definition: controls.h:352
const std::vector< ControlValue > & values() const
Retrieve the list of valid values.
Definition: controls.h:343
const ControlIdMap * idMap() const
Retrieve the ControlId map used to construct the ControlList.
Definition: controls.h:476
A map of ControlId to ControlInfo.
Definition: controls.h:366
Direction
The direction the control is capable of being passed from/to.
Definition: controls.h:253
Definition: controls.h:30
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:317
bool empty() const
Identify if the list is empty.
Definition: controls.h:433
Definition: controls.h:37
std::unordered_map< const ControlId *, ControlInfo > Map
The base std::unsorted_map<> container.
Definition: controls.h:369
Definition: controls.h:31
ControlType
Define the data type of a Control.
Definition: controls.h:29
ControlListMap::iterator iterator
Iterator for the controls contained within the list.
Definition: controls.h:425
const ControlIdMap & idmap() const
Retrieve the ControlId map.
Definition: controls.h:402
std::size_t size() const
Retrieve the size of the control if it is an array control.
Definition: controls.h:273
ControlListMap::const_iterator const_iterator
Const iterator for the controls contained within the list.
Definition: controls.h:426
const ControlValue & min() const
Retrieve the minimum value of the control.
Definition: controls.h:340
#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:429
Definition: controls.h:36
DirectionFlags direction() const
Return the direction that the control can be used in.
Definition: controls.h:269
iterator begin()
Retrieve an iterator to the first Control in the list.
Definition: controls.h:428
Definition: controls.h:33
unsigned int id() const
Retrieve the control numerical ID.
Definition: controls.h:265
#define LIBCAMERA_FLAGS_ENABLE_OPERATORS(_enum)
Enable bitwise operations on the enum enumeration.
bool isOutput() const
Determine if the control is available to be used in output metadata.
Definition: controls.h:271
Definition: controls.h:38
const_iterator end() const
Retrieve a const iterator pointing to the past-the-end control in the list.
Definition: controls.h:431
const ControlValue & max() const
Retrieve the maximum value of the control.
Definition: controls.h:341
std::size_t size() const
Retrieve the number of controls in the list.
Definition: controls.h:434
ControlType type() const
Retrieve the control data type.
Definition: controls.h:268
Associate a list of ControlId with their values for an object.
Definition: controls.h:410
Data structures related to geometric objects.
bool isNone() const
Determine if the value is not initialised.
Definition: controls.h:169
Definition: controls.h:32
bool operator==(const ControlInfo &other) const
Compare ControlInfo instances for equality.
Definition: controls.h:347
std::unordered_map< unsigned int, const ControlId * > ControlIdMap
A map of numerical control ID to ControlId.
Definition: controls.h:364
MergePolicy
The policy used by the merge function.
Definition: controls.h:416
T get() const
Get the control value.
Definition: controls.h:201
std::size_t numElements() const
Retrieve the number of elements stored in the ControlValue.
Definition: controls.h:171
const_iterator begin() const
Retrieve a const_iterator to the first Control in the list.
Definition: controls.h:430