8 #ifndef __LIBCAMERA_CONTROLS_H__ 9 #define __LIBCAMERA_CONTROLS_H__ 14 #include <unordered_map> 17 #include <libcamera/span.h> 21 class ControlValidator;
42 struct control_type<void> {
47 struct control_type<bool> {
52 struct control_type<uint8_t> {
57 struct control_type<int32_t> {
62 struct control_type<int64_t> {
67 struct control_type<float> {
72 struct control_type<std::string> {
77 struct control_type<Rectangle> {
78 static constexpr
ControlType value = ControlTypeRectangle;
82 struct control_type<Size> {
83 static constexpr
ControlType value = ControlTypeSize;
86 template<
typename T, std::
size_t N>
87 struct control_type<Span<T, N>> :
public control_type<std::remove_cv_t<T>> {
98 template<typename T, typename std::enable_if_t<!details::is_span<T>::value &&
99 !std::is_same<std::string, std::remove_cv_t<T>>::value,
100 std::nullptr_t> =
nullptr>
104 set(details::control_type<std::remove_cv_t<T>>::value,
false,
105 &value, 1,
sizeof(T));
108 template<typename T, typename std::enable_if_t<details::is_span<T>::value ||
109 std::is_same<std::string, std::remove_cv_t<T>>::value,
110 std::nullptr_t> =
nullptr>
117 set(details::control_type<std::remove_cv_t<T>>::value,
true,
118 value.data(), value.size(),
sizeof(
typename T::value_type));
130 Span<const uint8_t> data()
const;
131 Span<uint8_t> data();
133 std::string toString()
const;
138 return !(*
this == other);
142 template<typename T, typename std::enable_if_t<!details::is_span<T>::value &&
143 !std::is_same<std::string, std::remove_cv_t<T>>::value,
144 std::nullptr_t> =
nullptr>
147 assert(type_ == details::control_type<std::remove_cv_t<T>>::value);
150 return *
reinterpret_cast<const T *
>(data().data());
153 template<typename T, typename std::enable_if_t<details::is_span<T>::value ||
154 std::is_same<std::string, std::remove_cv_t<T>>::value,
155 std::nullptr_t> =
nullptr>
161 assert(type_ == details::control_type<std::remove_cv_t<T>>::value);
164 using V =
typename T::value_type;
165 const V *value =
reinterpret_cast<const V *
>(data().data());
166 return { value, numElements_ };
170 template<typename T, typename std::enable_if_t<!details::is_span<T>::value &&
171 !std::is_same<std::string, std::remove_cv_t<T>>::value,
172 std::nullptr_t> =
nullptr>
173 void set(
const T &value)
175 set(details::control_type<std::remove_cv_t<T>>::value,
false,
176 reinterpret_cast<const void *
>(&value), 1,
sizeof(T));
179 template<typename T, typename std::enable_if_t<details::is_span<T>::value ||
180 std::is_same<std::string, std::remove_cv_t<T>>::value,
181 std::nullptr_t> =
nullptr>
185 void set(
const T &value)
187 set(details::control_type<std::remove_cv_t<T>>::value,
true,
188 value.data(), value.size(),
sizeof(
typename T::value_type));
191 void reserve(
ControlType type,
bool isArray =
false,
192 std::size_t numElements = 1);
197 std::size_t numElements_ : 32;
204 void set(
ControlType type,
bool isArray,
const void *data,
205 std::size_t numElements, std::size_t elementSize);
212 : id_(id), name_(name), type_(type)
216 unsigned int id()
const {
return id_; }
217 const std::string &
name()
const {
return name_; }
229 static inline bool operator==(
unsigned int lhs,
const ControlId &rhs)
231 return lhs == rhs.
id();
234 static inline bool operator!=(
unsigned int lhs,
const ControlId &rhs)
236 return !(lhs == rhs);
239 static inline bool operator==(
const ControlId &lhs,
unsigned int rhs)
241 return lhs.
id() == rhs;
244 static inline bool operator!=(
const ControlId &lhs,
unsigned int rhs)
246 return !(lhs == rhs);
256 :
ControlId(id, name, details::control_type<std::remove_cv_t<T>>::value)
276 std::string toString()
const;
280 return min_ == other.min_ && max_ == other.max_;
285 return !(*
this == other);
294 using ControlIdMap = std::unordered_map<unsigned int, const ControlId *>;
296 class ControlInfoMap :
private std::unordered_map<const ControlId *, ControlInfo>
299 using Map = std::unordered_map<const ControlId *, ControlInfo>;
307 ControlInfoMap &operator=(std::initializer_list<Map::value_type> init);
311 using Map::mapped_type;
312 using Map::value_type;
313 using Map::size_type;
315 using Map::const_iterator;
327 mapped_type &at(
unsigned int key);
328 const mapped_type &at(
unsigned int key)
const;
329 size_type count(
unsigned int key)
const;
330 iterator find(
unsigned int key);
331 const_iterator find(
unsigned int key)
const;
336 void generateIdmap();
344 using ControlListMap = std::unordered_map<unsigned int, ControlValue>;
359 bool empty()
const {
return controls_.empty(); }
360 std::size_t
size()
const {
return controls_.size(); }
363 bool contains(
const ControlId &
id)
const;
364 bool contains(
unsigned int id)
const;
373 return val->
get<T>();
376 template<
typename T,
typename V>
386 template<
typename T,
typename V>
387 void set(
const Control<T> &ctrl,
const std::initializer_list<V> &value)
393 val->
set<T>(Span<const typename std::remove_cv_t<V>>{ value.begin(), value.size() });
409 ControlListMap controls_;
ControlType type() const
Retrieve the data type of the value.
Definition: controls.h:126
ControlValue(const T &value)
Construct a ControlValue of type T.
Definition: controls.h:114
bool operator!=(const ControlValue &other) const
Compare ControlValue instances for non equality.
Definition: controls.h:136
Describe the limits of valid values for a Control.
Definition: controls.h:265
const ControlInfoMap * infoMap() const
Retrieve the ControlInfoMap used to construct the ControlList.
Definition: controls.h:399
const std::string & name() const
Retrieve the control name.
Definition: controls.h:217
T type
The Control template type T.
Definition: controls.h:253
ControlType
Define the data type of a Control.
Definition: controls.h:23
const ControlValue & def() const
Retrieve the default value of the control.
Definition: controls.h:274
ControlId(unsigned int id, const std::string &name, ControlType type)
Construct a ControlId instance.
Definition: controls.h:211
Definition: bound_method.h:15
Definition: controls.h:24
Abstract type representing the value of a control.
Definition: controls.h:92
Control(unsigned int id, const char *name)
Construct a Control instance.
Definition: controls.h:255
Definition: controls.h:27
void set(const T &value)
Set the control value to value.
Definition: controls.h:185
Interface for the control validator.
Definition: control_validator.h:16
bool isArray() const
Determine if the value stores an array.
Definition: controls.h:128
Control static metadata.
Definition: controls.h:208
void clear()
Removes all controls from the list.
Definition: controls.h:361
Definition: controls.h:29
Describe a control and its intrinsic properties.
Definition: controls.h:250
bool operator!=(const ControlInfo &other) const
Compare ControlInfo instances for non equality.
Definition: controls.h:283
A map of ControlId to ControlInfo.
Definition: controls.h:296
bool empty() const
Identify if the list is empty.
Definition: controls.h:359
std::unordered_map< unsigned int, const ControlId * > ControlIdMap
A map of numerical control ID to ControlId.
Definition: controls.h:294
std::unordered_map< const ControlId *, ControlInfo > Map
The base std::unsorted_map<> container.
Definition: controls.h:299
ControlListMap::iterator iterator
Iterator for the controls contained within the list.
Definition: controls.h:351
const ControlIdMap & idmap() const
Retrieve the ControlId map.
Definition: controls.h:333
ControlListMap::const_iterator const_iterator
Const iterator for the controls contained within the list.
Definition: controls.h:352
const ControlValue & min() const
Retrieve the minimum value of the control.
Definition: controls.h:272
iterator end()
Retrieve an iterator pointing to the past-the-end control in the list.
Definition: controls.h:355
Definition: controls.h:25
iterator begin()
Retrieve an iterator to the first Control in the list.
Definition: controls.h:354
unsigned int id() const
Retrieve the control numerical ID.
Definition: controls.h:216
const_iterator end() const
Retrieve a const iterator pointing to the past-the-end control in the list.
Definition: controls.h:357
Definition: controls.h:26
const ControlValue & max() const
Retrieve the maximum value of the control.
Definition: controls.h:273
std::size_t size() const
Retrieve the number of controls in the list.
Definition: controls.h:360
Definition: controls.h:30
ControlType type() const
Retrieve the control data type.
Definition: controls.h:218
Associate a list of ControlId with their values for an object.
Definition: controls.h:341
Data structures related to geometric objects.
bool isNone() const
Determine if the value is not initialised.
Definition: controls.h:127
Definition: controls.h:28
bool operator==(const ControlInfo &other) const
Compare ControlInfo instances for equality.
Definition: controls.h:278
T get() const
Get the control value.
Definition: controls.h:159
std::size_t numElements() const
Retrieve the number of elements stored in the ControlValue.
Definition: controls.h:129
const_iterator begin() const
Retrieve a const_iterator to the first Control in the list.
Definition: controls.h:356