summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Elder <paul.elder@ideasonboard.com>2021-11-22 19:09:43 +0900
committerPaul Elder <paul.elder@ideasonboard.com>2021-12-22 16:07:17 -0600
commit86ab84677fff4e4c903453c846adc06524fa79d5 (patch)
treec6ff2e6d3c72d84a90107d8de3b9cc5d8757cf40 /src
parent733d690b93e1c2b526fc16cb504035f92d1a396d (diff)
android: camera_metadata: Add setEntry helper
Add setEntry() helper, that automatically detects if updateEntry() or addEntry() should be used. Note that updateEntry() will fail if the entry was not yet added, and addEntry() will fail is the entry was already added. They are silent failures that cause unexpected values to find their way into the android metadata instance. Previously this helper was not necessary, as (with respect to the current use case) the preview template generator would always add a key so the other template generators that used the preview template as boilerplate could reliably use updateEntry(). The preview template generator will soon decide based on capabilities whether or not to add keys, so the other template generators need a helper to decide whether to use updateEntry() or addEntry(). For now only implement it for enums and arithmetic values, as they will mainly be used in populating templates. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Diffstat (limited to 'src')
-rw-r--r--src/android/camera_metadata.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/android/camera_metadata.h b/src/android/camera_metadata.h
index e70f60af..0c31ec6b 100644
--- a/src/android/camera_metadata.h
+++ b/src/android/camera_metadata.h
@@ -36,6 +36,17 @@ public:
template<typename T,
std::enable_if_t<std::is_arithmetic_v<T> ||
std::is_enum_v<T>> * = nullptr>
+ bool setEntry(uint32_t tag, const T &data)
+ {
+ if (hasEntry(tag))
+ return updateEntry(tag, &data, 1, sizeof(T));
+ else
+ return addEntry(tag, &data, 1, sizeof(T));
+ }
+
+ template<typename T,
+ std::enable_if_t<std::is_arithmetic_v<T> ||
+ std::is_enum_v<T>> * = nullptr>
bool addEntry(uint32_t tag, const T &data)
{
return addEntry(tag, &data, 1, sizeof(T));