summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorPaul Elder <paul.elder@ideasonboard.com>2024-09-16 01:24:18 +0200
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2024-09-25 23:53:44 +0300
commit9bbccb97fa0debc86d906fdfc1fbedbd50de5d06 (patch)
tree5794a9de150d8800bcfc4de2631fe6b06588ac1c /include
parent44b49af7a0a870d5fce5c162e3998ef3696912d5 (diff)
libcamera: controls: Add enum names and values map to ControlId
Add to ControlId information about the names and values of enum, in the event that the ControlId is an enum type. This allows applications to query the ControlId for the names of the enum values, so that they can be displayed on a UI, for example. Without this, it was necessary to use macros of NameOfControlNameValueMap, which is difficult to use and is very inflexible. There already exists a map from name -> value in generated code. Reuse this and pass it to the ControlId constructor, which in turn generates the reverse map. The reverse map is then exposed to applications. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Umang Jain <umang.jain@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'include')
-rw-r--r--include/libcamera/controls.h14
1 files changed, 8 insertions, 6 deletions
diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h
index 7c2bb287..96a774cc 100644
--- a/include/libcamera/controls.h
+++ b/include/libcamera/controls.h
@@ -8,6 +8,7 @@
#pragma once
#include <assert.h>
+#include <map>
#include <optional>
#include <set>
#include <stdint.h>
@@ -213,14 +214,13 @@ private:
class ControlId
{
public:
- ControlId(unsigned int id, const std::string &name, ControlType type)
- : id_(id), name_(name), type_(type)
- {
- }
+ ControlId(unsigned int id, const std::string &name, ControlType type,
+ const std::map<std::string, int32_t> &enumStrMap = {});
unsigned int id() const { return id_; }
const std::string &name() const { return name_; }
ControlType type() const { return type_; }
+ const std::map<int32_t, std::string> &enumerators() const { return reverseMap_; }
private:
LIBCAMERA_DISABLE_COPY_AND_MOVE(ControlId)
@@ -228,6 +228,8 @@ private:
unsigned int id_;
std::string name_;
ControlType type_;
+ std::map<std::string, int32_t> enumStrMap_;
+ std::map<int32_t, std::string> reverseMap_;
};
static inline bool operator==(unsigned int lhs, const ControlId &rhs)
@@ -256,8 +258,8 @@ class Control : public ControlId
public:
using type = T;
- Control(unsigned int id, const char *name)
- : ControlId(id, name, details::control_type<std::remove_cv_t<T>>::value)
+ Control(unsigned int id, const char *name, const std::map<std::string, int32_t> &enumStrMap = {})
+ : ControlId(id, name, details::control_type<std::remove_cv_t<T>>::value, enumStrMap)
{
}