8 #ifndef __LIBCAMERA_CONTROLS_H__ 9 #define __LIBCAMERA_CONTROLS_H__ 14 #include <unordered_map> 19 #include <libcamera/span.h> 23 class ControlValidator;
44 struct control_type<void> {
49 struct control_type<bool> {
54 struct control_type<uint8_t> {
59 struct control_type<int32_t> {
64 struct control_type<int64_t> {
69 struct control_type<float> {
74 struct control_type<std::string> {
79 struct control_type<Rectangle> {
80 static constexpr
ControlType value = ControlTypeRectangle;
84 struct control_type<Size> {
85 static constexpr
ControlType value = ControlTypeSize;
88 template<
typename T, std::
size_t N>
89 struct control_type<Span<T, N>> :
public control_type<std::remove_cv_t<T>> {
100 template<typename T, typename std::enable_if_t<!details::is_span<T>::value &&
101 details::control_type<T>::value &&
102 !std::is_same<std::string, std::remove_cv_t<T>>::value,
103 std::nullptr_t> =
nullptr>
107 set(details::control_type<std::remove_cv_t<T>>::value,
false,
108 &value, 1,
sizeof(T));
111 template<typename T, typename std::enable_if_t<details::is_span<T>::value ||
112 std::is_same<std::string, std::remove_cv_t<T>>::value,
113 std::nullptr_t> =
nullptr>
120 set(details::control_type<std::remove_cv_t<T>>::value,
true,
121 value.data(), value.size(),
sizeof(
typename T::value_type));
133 Span<const uint8_t> data()
const;
134 Span<uint8_t> data();
136 std::string toString()
const;
141 return !(*
this == other);
145 template<typename T, typename std::enable_if_t<!details::is_span<T>::value &&
146 !std::is_same<std::string, std::remove_cv_t<T>>::value,
147 std::nullptr_t> =
nullptr>
150 assert(type_ == details::control_type<std::remove_cv_t<T>>::value);
153 return *
reinterpret_cast<const T *
>(data().data());
156 template<typename T, typename std::enable_if_t<details::is_span<T>::value ||
157 std::is_same<std::string, std::remove_cv_t<T>>::value,
158 std::nullptr_t> =
nullptr>
164 assert(type_ == details::control_type<std::remove_cv_t<T>>::value);
167 using V =
typename T::value_type;
168 const V *value =
reinterpret_cast<const V *
>(data().data());
169 return { value, numElements_ };
173 template<typename T, typename std::enable_if_t<!details::is_span<T>::value &&
174 !std::is_same<std::string, std::remove_cv_t<T>>::value,
175 std::nullptr_t> =
nullptr>
176 void set(
const T &value)
178 set(details::control_type<std::remove_cv_t<T>>::value,
false,
179 reinterpret_cast<const void *
>(&value), 1,
sizeof(T));
182 template<typename T, typename std::enable_if_t<details::is_span<T>::value ||
183 std::is_same<std::string, std::remove_cv_t<T>>::value,
184 std::nullptr_t> =
nullptr>
188 void set(
const T &value)
190 set(details::control_type<std::remove_cv_t<T>>::value,
true,
191 value.data(), value.size(),
sizeof(
typename T::value_type));
194 void reserve(
ControlType type,
bool isArray =
false,
195 std::size_t numElements = 1);
200 std::size_t numElements_ : 32;
207 void set(
ControlType type,
bool isArray,
const void *data,
208 std::size_t numElements, std::size_t elementSize);
215 : id_(id), name_(name), type_(type)
219 unsigned int id()
const {
return id_; }
220 const std::string &
name()
const {
return name_; }
231 static inline bool operator==(
unsigned int lhs,
const ControlId &rhs)
233 return lhs == rhs.
id();
236 static inline bool operator!=(
unsigned int lhs,
const ControlId &rhs)
238 return !(lhs == rhs);
241 static inline bool operator==(
const ControlId &lhs,
unsigned int rhs)
243 return lhs.
id() == rhs;
246 static inline bool operator!=(
const ControlId &lhs,
unsigned int rhs)
248 return !(lhs == rhs);
258 :
ControlId(id, name, details::control_type<std::remove_cv_t<T>>::value)
272 explicit ControlInfo(Span<const ControlValue> values,
278 const std::vector<ControlValue> &
values()
const {
return values_; }
280 std::string toString()
const;
284 return min_ == other.min_ && max_ == other.max_;
289 return !(*
this == other);
296 std::vector<ControlValue> values_;
299 using ControlIdMap = std::unordered_map<unsigned int, const ControlId *>;
301 class ControlInfoMap :
private std::unordered_map<const ControlId *, ControlInfo>
304 using Map = std::unordered_map<const ControlId *, ControlInfo>;
312 ControlInfoMap &operator=(std::initializer_list<Map::value_type> init);
316 using Map::mapped_type;
317 using Map::value_type;
318 using Map::size_type;
320 using Map::const_iterator;
332 mapped_type &at(
unsigned int key);
333 const mapped_type &at(
unsigned int key)
const;
334 size_type count(
unsigned int key)
const;
335 iterator find(
unsigned int key);
336 const_iterator find(
unsigned int key)
const;
341 void generateIdmap();
349 using ControlListMap = std::unordered_map<unsigned int, ControlValue>;
364 bool empty()
const {
return controls_.empty(); }
365 std::size_t
size()
const {
return controls_.size(); }
368 bool contains(
const ControlId &
id)
const;
369 bool contains(
unsigned int id)
const;
378 return val->
get<T>();
381 template<
typename T,
typename V>
391 template<
typename T,
typename V>
392 void set(
const Control<T> &ctrl,
const std::initializer_list<V> &value)
398 val->
set<T>(Span<const typename std::remove_cv_t<V>>{ value.begin(), value.size() });
414 ControlListMap controls_;
ControlType type() const
Retrieve the data type of the value.
Definition: controls.h:129
ControlValue(const T &value)
Construct a ControlValue of type T.
Definition: controls.h:117
bool operator!=(const ControlValue &other) const
Compare ControlValue instances for non equality.
Definition: controls.h:139
Utilities to help constructing class interfaces.
Describe the limits of valid values for a Control.
Definition: controls.h:266
const ControlInfoMap * infoMap() const
Retrieve the ControlInfoMap used to construct the ControlList.
Definition: controls.h:404
const std::string & name() const
Retrieve the control name.
Definition: controls.h:220
T type
The Control template type T.
Definition: controls.h:255
const ControlValue & def() const
Retrieve the default value of the control.
Definition: controls.h:277
ControlId(unsigned int id, const std::string &name, ControlType type)
Construct a ControlId instance.
Definition: controls.h:214
Top-level libcamera namespace.
Definition: bound_method.h:15
Abstract type representing the value of a control.
Definition: controls.h:94
Control(unsigned int id, const char *name)
Construct a Control instance.
Definition: controls.h:257
void set(const T &value)
Set the control value to value.
Definition: controls.h:188
Interface for the control validator.
Definition: control_validator.h:16
bool isArray() const
Determine if the value stores an array.
Definition: controls.h:131
Definition: controls.h:29
Control static metadata.
Definition: controls.h:211
void clear()
Removes all controls from the list.
Definition: controls.h:366
Describe a control and its intrinsic properties.
Definition: controls.h:252
bool operator!=(const ControlInfo &other) const
Compare ControlInfo instances for non equality.
Definition: controls.h:287
const std::vector< ControlValue > & values() const
Retrieve the list of valid values.
Definition: controls.h:278
A map of ControlId to ControlInfo.
Definition: controls.h:301
Definition: controls.h:26
bool empty() const
Identify if the list is empty.
Definition: controls.h:364
Definition: controls.h:31
std::unordered_map< const ControlId *, ControlInfo > Map
The base std::unsorted_map<> container.
Definition: controls.h:304
Definition: controls.h:27
ControlType
Define the data type of a Control.
Definition: controls.h:25
ControlListMap::iterator iterator
Iterator for the controls contained within the list.
Definition: controls.h:356
const ControlIdMap & idmap() const
Retrieve the ControlId map.
Definition: controls.h:338
ControlListMap::const_iterator const_iterator
Const iterator for the controls contained within the list.
Definition: controls.h:357
const ControlValue & min() const
Retrieve the minimum value of the control.
Definition: controls.h:275
#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:360
Definition: controls.h:30
iterator begin()
Retrieve an iterator to the first Control in the list.
Definition: controls.h:359
unsigned int id() const
Retrieve the control numerical ID.
Definition: controls.h:219
Definition: controls.h:32
const_iterator end() const
Retrieve a const iterator pointing to the past-the-end control in the list.
Definition: controls.h:362
const ControlValue & max() const
Retrieve the maximum value of the control.
Definition: controls.h:276
std::size_t size() const
Retrieve the number of controls in the list.
Definition: controls.h:365
ControlType type() const
Retrieve the control data type.
Definition: controls.h:221
Associate a list of ControlId with their values for an object.
Definition: controls.h:346
Data structures related to geometric objects.
bool isNone() const
Determine if the value is not initialised.
Definition: controls.h:130
Definition: controls.h:28
bool operator==(const ControlInfo &other) const
Compare ControlInfo instances for equality.
Definition: controls.h:282
std::unordered_map< unsigned int, const ControlId * > ControlIdMap
A map of numerical control ID to ControlId.
Definition: controls.h:299
T get() const
Get the control value.
Definition: controls.h:162
std::size_t numElements() const
Retrieve the number of elements stored in the ControlValue.
Definition: controls.h:132
const_iterator begin() const
Retrieve a const_iterator to the first Control in the list.
Definition: controls.h:361