summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2020-02-14 17:02:18 +0200
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2020-03-06 18:10:22 +0200
commiteaa1297df0bc4c6620ccde171dc9dc088109e35e (patch)
tree37a0d6d8495dd3b44468edc564a0c40a3b92cd86 /include
parent300f6e44345f5cb7bfe9aece6c6c5b5c0894487b (diff)
libcamera: controls: Move ControlValue get() and set() to controls.h
To avoid defining all specializations of ControlValue::get() and ControlValue::set() manually, move the definition of those functions to controls.h and turn them into single template functions. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Diffstat (limited to 'include')
-rw-r--r--include/libcamera/controls.h15
1 files changed, 13 insertions, 2 deletions
diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h
index 429f01b0..39e24043 100644
--- a/include/libcamera/controls.h
+++ b/include/libcamera/controls.h
@@ -8,6 +8,7 @@
#ifndef __LIBCAMERA_CONTROLS_H__
#define __LIBCAMERA_CONTROLS_H__
+#include <assert.h>
#include <string>
#include <unordered_map>
@@ -70,9 +71,19 @@ public:
}
template<typename T>
- T get() const;
+ T get() const
+ {
+ assert(type_ == details::control_type<std::remove_cv_t<T>>::value);
+
+ return *reinterpret_cast<const T *>(&bool_);
+ }
+
template<typename T>
- void set(const T &value);
+ void set(const T &value)
+ {
+ type_ = details::control_type<std::remove_cv_t<T>>::value;
+ *reinterpret_cast<T *>(&bool_) = value;
+ }
private:
ControlType type_;