14 #include <unordered_map> 18 #include <libcamera/base/span.h> 24 class ControlValidator;
45 struct control_type<void> {
50 struct control_type<bool> {
55 struct control_type<uint8_t> {
60 struct control_type<int32_t> {
65 struct control_type<int64_t> {
70 struct control_type<float> {
75 struct control_type<std::string> {
80 struct control_type<Rectangle> {
81 static constexpr
ControlType value = ControlTypeRectangle;
85 struct control_type<Size> {
86 static constexpr
ControlType value = ControlTypeSize;
89 template<
typename T, std::
size_t N>
90 struct control_type<Span<T, N>> :
public control_type<std::remove_cv_t<T>> {
101 template<typename T, typename std::enable_if_t<!details::is_span<T>::value &&
102 details::control_type<T>::value &&
103 !std::is_same<std::string, std::remove_cv_t<T>>::value,
104 std::nullptr_t> =
nullptr>
108 set(details::control_type<std::remove_cv_t<T>>::value,
false,
109 &value, 1,
sizeof(T));
112 template<typename T, typename std::enable_if_t<details::is_span<T>::value ||
113 std::is_same<std::string, std::remove_cv_t<T>>::value,
114 std::nullptr_t> =
nullptr>
121 set(details::control_type<std::remove_cv_t<T>>::value,
true,
122 value.data(), value.size(),
sizeof(
typename T::value_type));
134 Span<const uint8_t> data()
const;
135 Span<uint8_t> data();
137 std::string toString()
const;
142 return !(*
this == other);
146 template<typename T, typename std::enable_if_t<!details::is_span<T>::value &&
147 !std::is_same<std::string, std::remove_cv_t<T>>::value,
148 std::nullptr_t> =
nullptr>
151 assert(type_ == details::control_type<std::remove_cv_t<T>>::value);
154 return *
reinterpret_cast<const T *
>(data().data());
157 template<typename T, typename std::enable_if_t<details::is_span<T>::value ||
158 std::is_same<std::string, std::remove_cv_t<T>>::value,
159 std::nullptr_t> =
nullptr>
165 assert(type_ == details::control_type<std::remove_cv_t<T>>::value);
168 using V =
typename T::value_type;
169 const V *value =
reinterpret_cast<const V *
>(data().data());
170 return { value, numElements_ };
174 template<typename T, typename std::enable_if_t<!details::is_span<T>::value &&
175 !std::is_same<std::string, std::remove_cv_t<T>>::value,
176 std::nullptr_t> =
nullptr>
177 void set(
const T &value)
179 set(details::control_type<std::remove_cv_t<T>>::value,
false,
180 reinterpret_cast<const void *
>(&value), 1,
sizeof(T));
183 template<typename T, typename std::enable_if_t<details::is_span<T>::value ||
184 std::is_same<std::string, std::remove_cv_t<T>>::value,
185 std::nullptr_t> =
nullptr>
189 void set(
const T &value)
191 set(details::control_type<std::remove_cv_t<T>>::value,
true,
192 value.data(), value.size(),
sizeof(
typename T::value_type));
195 void reserve(
ControlType type,
bool isArray =
false,
196 std::size_t numElements = 1);
201 std::size_t numElements_ : 32;
208 void set(
ControlType type,
bool isArray,
const void *data,
209 std::size_t numElements, std::size_t elementSize);
216 : id_(id), name_(name), type_(type)
220 unsigned int id()
const {
return id_; }
221 const std::string &
name()
const {
return name_; }
234 return lhs == rhs.
id();
237 static inline bool operator!=(
unsigned int lhs,
const ControlId &rhs)
239 return !(lhs == rhs);
244 return lhs.
id() == rhs;
247 static inline bool operator!=(
const ControlId &lhs,
unsigned int rhs)
249 return !(lhs == rhs);
259 :
ControlId(id, name, details::control_type<std::remove_cv_t<T>>::value)
273 explicit ControlInfo(Span<const ControlValue> values,
275 explicit ControlInfo(std::set<bool> values,
bool def);
276 explicit ControlInfo(
bool value);
281 const std::vector<ControlValue> &
values()
const {
return values_; }
283 std::string toString()
const;
287 return min_ == other.min_ && max_ == other.max_;
292 return !(*
this == other);
299 std::vector<ControlValue> values_;
302 using ControlIdMap = std::unordered_map<unsigned int, const ControlId *>;
304 class ControlInfoMap :
private std::unordered_map<const ControlId *, ControlInfo>
307 using Map = std::unordered_map<const ControlId *, ControlInfo>;
318 using Map::mapped_type;
319 using Map::value_type;
320 using Map::size_type;
322 using Map::const_iterator;
334 mapped_type &at(
unsigned int key);
335 const mapped_type &at(
unsigned int key)
const;
336 size_type count(
unsigned int key)
const;
337 iterator find(
unsigned int key);
338 const_iterator find(
unsigned int key)
const;
351 using ControlListMap = std::unordered_map<unsigned int, ControlValue>;
366 bool empty()
const {
return controls_.empty(); }
367 std::size_t
size()
const {
return controls_.size(); }
372 bool contains(
const ControlId &
id)
const;
373 bool contains(
unsigned int id)
const;
382 return val->
get<T>();
385 template<
typename T,
typename V>
395 template<
typename T,
typename V>
396 void set(
const Control<T> &ctrl,
const std::initializer_list<V> &value)
402 val->
set<T>(Span<const typename std::remove_cv_t<V>>{ value.begin(), value.size() });
419 ControlListMap controls_;
ControlType type() const
Retrieve the data type of the value.
Definition: controls.h:130
ControlValue(const T &value)
Construct a ControlValue of type T.
Definition: controls.h:118
bool operator!=(const ControlValue &other) const
Compare ControlValue instances for non equality.
Definition: controls.h:140
Utilities to help constructing class interfaces.
Describe the limits of valid values for a Control.
Definition: controls.h:267
const ControlInfoMap * infoMap() const
Retrieve the ControlInfoMap used to construct the ControlList.
Definition: controls.h:408
const std::string & name() const
Retrieve the control name.
Definition: controls.h:221
T type
The Control template type T.
Definition: controls.h:256
bool operator==(const ColorSpace &lhs, const ColorSpace &rhs)
Compare color spaces for equality.
Definition: color_space.cpp:303
const ControlValue & def() const
Retrieve the default value of the control.
Definition: controls.h:280
ControlId(unsigned int id, const std::string &name, ControlType type)
Construct a ControlId instance.
Definition: controls.h:215
Top-level libcamera namespace.
Definition: backtrace.h:17
Abstract type representing the value of a control.
Definition: controls.h:95
Control(unsigned int id, const char *name)
Construct a Control instance.
Definition: controls.h:258
void set(const T &value)
Set the control value to value.
Definition: controls.h:189
Interface for the control validator.
Definition: control_validator.h:16
bool isArray() const
Determine if the value stores an array.
Definition: controls.h:132
Definition: controls.h:30
Control static metadata.
Definition: controls.h:212
void clear()
Removes all controls from the list.
Definition: controls.h:369
Describe a control and its intrinsic properties.
Definition: controls.h:253
bool operator!=(const ControlInfo &other) const
Compare ControlInfo instances for non equality.
Definition: controls.h:290
const std::vector< ControlValue > & values() const
Retrieve the list of valid values.
Definition: controls.h:281
const ControlIdMap * idMap() const
Retrieve the ControlId map used to construct the ControlList.
Definition: controls.h:409
A map of ControlId to ControlInfo.
Definition: controls.h:304
Definition: controls.h:27
bool empty() const
Identify if the list is empty.
Definition: controls.h:366
Definition: controls.h:32
std::unordered_map< const ControlId *, ControlInfo > Map
The base std::unsorted_map<> container.
Definition: controls.h:307
Definition: controls.h:28
ControlType
Define the data type of a Control.
Definition: controls.h:26
ControlListMap::iterator iterator
Iterator for the controls contained within the list.
Definition: controls.h:358
const ControlIdMap & idmap() const
Retrieve the ControlId map.
Definition: controls.h:340
ControlListMap::const_iterator const_iterator
Const iterator for the controls contained within the list.
Definition: controls.h:359
const ControlValue & min() const
Retrieve the minimum value of the control.
Definition: controls.h:278
#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:362
Definition: controls.h:31
iterator begin()
Retrieve an iterator to the first Control in the list.
Definition: controls.h:361
unsigned int id() const
Retrieve the control numerical ID.
Definition: controls.h:220
Definition: controls.h:33
const_iterator end() const
Retrieve a const iterator pointing to the past-the-end control in the list.
Definition: controls.h:364
const ControlValue & max() const
Retrieve the maximum value of the control.
Definition: controls.h:279
std::size_t size() const
Retrieve the number of controls in the list.
Definition: controls.h:367
ControlType type() const
Retrieve the control data type.
Definition: controls.h:222
Associate a list of ControlId with their values for an object.
Definition: controls.h:348
Data structures related to geometric objects.
bool isNone() const
Determine if the value is not initialised.
Definition: controls.h:131
Definition: controls.h:29
bool operator==(const ControlInfo &other) const
Compare ControlInfo instances for equality.
Definition: controls.h:285
std::unordered_map< unsigned int, const ControlId * > ControlIdMap
A map of numerical control ID to ControlId.
Definition: controls.h:302
T get() const
Get the control value.
Definition: controls.h:163
std::size_t numElements() const
Retrieve the number of elements stored in the ControlValue.
Definition: controls.h:133
const_iterator begin() const
Retrieve a const_iterator to the first Control in the list.
Definition: controls.h:363