15#include <unordered_map>
19#include <libcamera/base/span.h>
25class ControlValidator;
46struct control_type<void> {
51struct control_type<bool> {
56struct control_type<uint8_t> {
61struct control_type<int32_t> {
66struct control_type<int64_t> {
71struct control_type<float> {
76struct control_type<std::string> {
81struct control_type<Rectangle> {
82 static constexpr ControlType value = ControlTypeRectangle;
86struct control_type<Size> {
87 static constexpr ControlType value = ControlTypeSize;
90template<
typename T, std::
size_t N>
91struct control_type<Span<T, N>> :
public control_type<std::remove_cv_t<T>> {
102 template<typename T, std::enable_if_t<!details::is_span<T>::value &&
103 details::control_type<T>::value &&
104 !std::is_same<std::string, std::remove_cv_t<T>>::value,
105 std::nullptr_t> =
nullptr>
109 set(details::control_type<std::remove_cv_t<T>>::value,
false,
110 &value, 1,
sizeof(T));
113 template<typename T, std::enable_if_t<details::is_span<T>::value ||
114 std::is_same<std::string, std::remove_cv_t<T>>::value,
115 std::nullptr_t> =
nullptr>
122 set(details::control_type<std::remove_cv_t<T>>::value,
true,
123 value.data(), value.size(),
sizeof(
typename T::value_type));
135 Span<const uint8_t>
data()
const;
136 Span<uint8_t>
data();
143 return !(*
this == other);
147 template<typename T, std::enable_if_t<!details::is_span<T>::value &&
148 !std::is_same<std::string, std::remove_cv_t<T>>::value,
149 std::nullptr_t> =
nullptr>
152 assert(type_ == details::control_type<std::remove_cv_t<T>>::value);
155 return *
reinterpret_cast<const T *
>(
data().data());
158 template<typename T, std::enable_if_t<details::is_span<T>::value ||
159 std::is_same<std::string, std::remove_cv_t<T>>::value,
160 std::nullptr_t> =
nullptr>
166 assert(type_ == details::control_type<std::remove_cv_t<T>>::value);
169 using V =
typename T::value_type;
170 const V *value =
reinterpret_cast<const V *
>(
data().data());
171 return T{ value, numElements_ };
175 template<typename T, std::enable_if_t<!details::is_span<T>::value &&
176 !std::is_same<std::string, std::remove_cv_t<T>>::value,
177 std::nullptr_t> =
nullptr>
178 void set(
const T &value)
180 set(details::control_type<std::remove_cv_t<T>>::value,
false,
181 reinterpret_cast<const void *
>(&value), 1,
sizeof(T));
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>
192 set(details::control_type<std::remove_cv_t<T>>::value,
true,
193 value.data(), value.size(),
sizeof(
typename T::value_type));
202 std::size_t numElements_ : 32;
221 unsigned int id()
const {
return id_; }
222 const std::string &
name()
const {
return name_; }
233static inline bool operator==(
unsigned int lhs,
const ControlId &rhs)
235 return lhs == rhs.id();
238static inline bool operator!=(
unsigned int lhs,
const ControlId &rhs)
240 return !(lhs == rhs);
243static inline bool operator==(
const ControlId &lhs,
unsigned int rhs)
245 return lhs.id() == rhs;
248static inline bool operator!=(
const ControlId &lhs,
unsigned int rhs)
250 return !(lhs == rhs);
260 :
ControlId(
id,
name, details::control_type<std::remove_cv_t<T>>::value)
282 const std::vector<ControlValue> &
values()
const {
return values_; }
288 return min_ == other.min_ && max_ == other.max_;
293 return !(*
this == other);
300 std::vector<ControlValue> values_;
303using ControlIdMap = std::unordered_map<unsigned int, const ControlId *>;
308 using Map = std::unordered_map<const ControlId *, ControlInfo>;
319 using Map::mapped_type;
320 using Map::value_type;
321 using Map::size_type;
323 using Map::const_iterator;
335 mapped_type &
at(
unsigned int key);
336 const mapped_type &
at(
unsigned int key)
const;
337 size_type
count(
unsigned int key)
const;
338 iterator
find(
unsigned int key);
339 const_iterator
find(
unsigned int key)
const;
352 using ControlListMap = std::unordered_map<unsigned int, ControlValue>;
367 bool empty()
const {
return controls_.empty(); }
368 std::size_t
size()
const {
return controls_.size(); }
373 bool contains(
unsigned int id)
const;
378 const auto entry = controls_.find(ctrl.
id());
379 if (entry == controls_.end())
386 template<
typename T,
typename V>
396 template<
typename T,
typename V,
size_t Size>
397 void set(
const Control<Span<T, Size>> &ctrl,
const std::initializer_list<V> &value)
403 val->
set(Span<
const typename std::remove_cv_t<V>,
Size>{ value.begin(), value.size() });
420 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:214
ControlId(unsigned int id, const std::string &name, ControlType type)
Construct a ControlId instance.
Definition: controls.h:216
ControlType type() const
Retrieve the control data type.
Definition: controls.h:223
const std::string & name() const
Retrieve the control name.
Definition: controls.h:222
unsigned int id() const
Retrieve the control numerical ID.
Definition: controls.h:221
A map of ControlId to ControlInfo.
Definition: controls.h:306
mapped_type & at(unsigned int key)
Access specified element by numerical ID.
Definition: controls.cpp:723
const ControlIdMap & idmap() const
Retrieve the ControlId map.
Definition: controls.h:341
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:308
iterator find(unsigned int key)
Find the element matching a numerical ID.
Definition: controls.cpp:766
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:747
Describe the limits of valid values for a Control.
Definition: controls.h:269
const std::vector< ControlValue > & values() const
Retrieve the list of valid values.
Definition: controls.h:282
std::string toString() const
Provide a string representation of the ControlInfo.
Definition: controls.cpp:588
ControlInfo(const ControlValue &min={}, const ControlValue &max={}, const ControlValue &def={})
Construct a ControlInfo with minimum and maximum range parameters.
Definition: controls.cpp:488
bool operator==(const ControlInfo &other) const
Compare ControlInfo instances for equality.
Definition: controls.h:286
bool operator!=(const ControlInfo &other) const
Compare ControlInfo instances for non equality.
Definition: controls.h:291
const ControlValue & max() const
Retrieve the maximum value of the control.
Definition: controls.h:280
const ControlValue & def() const
Retrieve the default value of the control.
Definition: controls.h:281
const ControlValue & min() const
Retrieve the minimum value of the control.
Definition: controls.h:279
Associate a list of ControlId with their values for an object.
Definition: controls.h:350
void clear()
Removes all controls from the list.
Definition: controls.h:370
const ControlInfoMap * infoMap() const
Retrieve the ControlInfoMap used to construct the ControlList.
Definition: controls.h:409
const ControlIdMap * idMap() const
Retrieve the ControlId map used to construct the ControlList.
Definition: controls.h:410
void set(const Control< Span< T, Size > > &ctrl, const std::initializer_list< V > &value)
Set the control ctrl value to value.
Definition: controls.h:397
ControlListMap::const_iterator const_iterator
Const iterator for the controls contained within the list.
Definition: controls.h:360
iterator end()
Retrieve an iterator pointing to the past-the-end control in the list.
Definition: controls.h:363
std::size_t size() const
Retrieve the number of controls in the list.
Definition: controls.h:368
ControlListMap::iterator iterator
Iterator for the controls contained within the list.
Definition: controls.h:359
std::optional< T > get(const Control< T > &ctrl) const
Get the value of control ctrl.
Definition: controls.h:376
bool empty() const
Identify if the list is empty.
Definition: controls.h:367
void set(const Control< T > &ctrl, const V &value)
Set the control ctrl value to value.
Definition: controls.h:387
iterator begin()
Retrieve an iterator to the first Control in the list.
Definition: controls.h:362
bool contains(unsigned int id) const
Check if the list contains a control with the specified id.
Definition: controls.cpp:956
const_iterator begin() const
Retrieve a const_iterator to the first Control in the list.
Definition: controls.h:364
ControlList()
Construct a ControlList not associated with any object.
Definition: controls.cpp:826
const_iterator end() const
Retrieve a const iterator pointing to the past-the-end control in the list.
Definition: controls.h:365
void merge(const ControlList &source)
Merge the source into the ControlList.
Definition: controls.cpp:924
Interface for the control validator.
Definition: control_validator.h:17
Abstract type representing the value of a control.
Definition: controls.h:97
T get() const
Get the control value.
Definition: controls.h:164
bool isArray() const
Determine if the value stores an array.
Definition: controls.h:133
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:355
bool operator==(const ControlValue &other) const
Compare ControlValue instances for equality.
Definition: controls.cpp:279
void set(const T &value)
Set the control value to value.
Definition: controls.h:190
ControlValue()
Construct an empty ControlValue.
Definition: controls.cpp:98
bool operator!=(const ControlValue &other) const
Compare ControlValue instances for non equality.
Definition: controls.h:141
ControlValue(const T &value)
Construct a ControlValue of type T.
Definition: controls.h:119
ControlType type() const
Retrieve the data type of the value.
Definition: controls.h:131
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:132
std::size_t numElements() const
Retrieve the number of elements stored in the ControlValue.
Definition: controls.h:134
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:255
T type
The Control template type T.
Definition: controls.h:257
Control(unsigned int id, const char *name)
Construct a Control instance.
Definition: controls.h:259
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:27
@ ControlTypeNone
Definition: controls.h:28
@ ControlTypeFloat
Definition: controls.h:33
@ ControlTypeBool
Definition: controls.h:29
@ ControlTypeInteger32
Definition: controls.h:31
@ ControlTypeString
Definition: controls.h:34
@ ControlTypeInteger64
Definition: controls.h:32
@ ControlTypeByte
Definition: controls.h:30
std::unordered_map< unsigned int, const ControlId * > ControlIdMap
A map of numerical control ID to ControlId.
Definition: controls.h:303
bool operator==(const ColorSpace &lhs, const ColorSpace &rhs)
Compare color spaces for equality.
Definition: color_space.cpp:506