15 #include <unordered_map> 19 #include <libcamera/base/span.h> 25 class ControlValidator;
46 struct control_type<void> {
51 struct control_type<bool> {
56 struct control_type<uint8_t> {
61 struct control_type<int32_t> {
66 struct control_type<int64_t> {
71 struct control_type<float> {
76 struct control_type<std::string> {
81 struct control_type<Rectangle> {
82 static constexpr
ControlType value = ControlTypeRectangle;
86 struct control_type<Size> {
87 static constexpr
ControlType value = ControlTypeSize;
90 template<
typename T, std::
size_t N>
91 struct 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();
138 std::string toString()
const;
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>
190 void set(
const T &value)
192 set(details::control_type<std::remove_cv_t<T>>::value,
true,
193 value.data(), value.size(),
sizeof(
typename T::value_type));
196 void reserve(
ControlType type,
bool isArray =
false,
197 std::size_t numElements = 1);
202 std::size_t numElements_ : 32;
209 void set(
ControlType type,
bool isArray,
const void *data,
210 std::size_t numElements, std::size_t elementSize);
217 : id_(id), name_(name), type_(type)
221 unsigned int id()
const {
return id_; }
222 const std::string &
name()
const {
return name_; }
235 return lhs == rhs.
id();
238 static inline bool operator!=(
unsigned int lhs,
const ControlId &rhs)
240 return !(lhs == rhs);
245 return lhs.
id() == rhs;
248 static 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)
274 explicit ControlInfo(Span<const ControlValue> values,
276 explicit ControlInfo(std::set<bool> values,
bool def);
277 explicit ControlInfo(
bool value);
282 const std::vector<ControlValue> &
values()
const {
return values_; }
284 std::string toString()
const;
288 return min_ == other.min_ && max_ == other.max_;
293 return !(*
this == other);
300 std::vector<ControlValue> values_;
303 using ControlIdMap = std::unordered_map<unsigned int, const ControlId *>;
305 class ControlInfoMap :
private std::unordered_map<const ControlId *, ControlInfo>
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>;
372 bool empty()
const {
return controls_.empty(); }
373 std::size_t
size()
const {
return controls_.size(); }
378 bool contains(
unsigned int id)
const;
383 const auto entry = controls_.find(ctrl.id());
384 if (entry == controls_.end())
391 template<
typename T,
typename V>
401 template<
typename T,
typename V,
size_t Size>
408 val->
set(Span<
const typename std::remove_cv_t<V>,
Size>{ value.begin(), value.size() });
425 ControlListMap controls_;
ControlType type() const
Retrieve the data type of the value.
Definition: controls.h:131
ControlValue(const T &value)
Construct a ControlValue of type T.
Definition: controls.h:119
bool operator!=(const ControlValue &other) const
Compare ControlValue instances for non equality.
Definition: controls.h:141
Utilities to help constructing class interfaces.
Describe the limits of valid values for a Control.
Definition: controls.h:268
const ControlInfoMap * infoMap() const
Retrieve the ControlInfoMap used to construct the ControlList.
Definition: controls.h:414
const std::string & name() const
Retrieve the control name.
Definition: controls.h:222
T type
The Control template type T.
Definition: controls.h:257
bool operator==(const ColorSpace &lhs, const ColorSpace &rhs)
Compare color spaces for equality.
Definition: color_space.cpp:506
const ControlValue & def() const
Retrieve the default value of the control.
Definition: controls.h:281
ControlId(unsigned int id, const std::string &name, ControlType type)
Construct a ControlId instance.
Definition: controls.h:216
Top-level libcamera namespace.
Definition: backtrace.h:17
Abstract type representing the value of a control.
Definition: controls.h:96
Control(unsigned int id, const char *name)
Construct a Control instance.
Definition: controls.h:259
Definition: v4l2_pixelformat.h:60
void set(const T &value)
Set the control value to value.
Definition: controls.h:190
Interface for the control validator.
Definition: control_validator.h:16
bool isArray() const
Determine if the value stores an array.
Definition: controls.h:133
Definition: controls.h:31
Control static metadata.
Definition: controls.h:213
void clear()
Removes all controls from the list.
Definition: controls.h:375
Describe a two-dimensional size.
Definition: geometry.h:52
Describe a control and its intrinsic properties.
Definition: controls.h:254
bool operator!=(const ControlInfo &other) const
Compare ControlInfo instances for non equality.
Definition: controls.h:291
const std::vector< ControlValue > & values() const
Retrieve the list of valid values.
Definition: controls.h:282
const ControlIdMap * idMap() const
Retrieve the ControlId map used to construct the ControlList.
Definition: controls.h:415
A map of ControlId to ControlInfo.
Definition: controls.h:305
Definition: controls.h:28
bool empty() const
Identify if the list is empty.
Definition: controls.h:372
Definition: controls.h:33
std::unordered_map< const ControlId *, ControlInfo > Map
The base std::unsorted_map<> container.
Definition: controls.h:308
Definition: controls.h:29
ControlType
Define the data type of a Control.
Definition: controls.h:27
ControlListMap::iterator iterator
Iterator for the controls contained within the list.
Definition: controls.h:364
const ControlIdMap & idmap() const
Retrieve the ControlId map.
Definition: controls.h:341
ControlListMap::const_iterator const_iterator
Const iterator for the controls contained within the list.
Definition: controls.h:365
const ControlValue & min() const
Retrieve the minimum value of the control.
Definition: controls.h:279
#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:368
Definition: controls.h:32
iterator begin()
Retrieve an iterator to the first Control in the list.
Definition: controls.h:367
unsigned int id() const
Retrieve the control numerical ID.
Definition: controls.h:221
Definition: controls.h:34
const_iterator end() const
Retrieve a const iterator pointing to the past-the-end control in the list.
Definition: controls.h:370
const ControlValue & max() const
Retrieve the maximum value of the control.
Definition: controls.h:280
std::size_t size() const
Retrieve the number of controls in the list.
Definition: controls.h:373
ControlType type() const
Retrieve the control data type.
Definition: controls.h:223
Associate a list of ControlId with their values for an object.
Definition: controls.h:349
Data structures related to geometric objects.
bool isNone() const
Determine if the value is not initialised.
Definition: controls.h:132
Definition: controls.h:30
bool operator==(const ControlInfo &other) const
Compare ControlInfo instances for equality.
Definition: controls.h:286
std::unordered_map< unsigned int, const ControlId * > ControlIdMap
A map of numerical control ID to ControlId.
Definition: controls.h:303
MergePolicy
The policy used by the merge function.
Definition: controls.h:355
T get() const
Get the control value.
Definition: controls.h:164
std::size_t numElements() const
Retrieve the number of elements stored in the ControlValue.
Definition: controls.h:134
const_iterator begin() const
Retrieve a const_iterator to the first Control in the list.
Definition: controls.h:369