summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/libcamera/internal/utils.h32
1 files changed, 32 insertions, 0 deletions
diff --git a/include/libcamera/internal/utils.h b/include/libcamera/internal/utils.h
index 83dada7c..15beb0f4 100644
--- a/include/libcamera/internal/utils.h
+++ b/include/libcamera/internal/utils.h
@@ -316,8 +316,40 @@ auto enumerate(T (&iterable)[N]) -> details::enumerate_adapter<T *>
}
#endif
+class Duration : public std::chrono::duration<double, std::nano>
+{
+ using BaseDuration = std::chrono::duration<double, std::nano>;
+
+public:
+ Duration() = default;
+
+ template<typename Rep, typename Period>
+ constexpr Duration(const std::chrono::duration<Rep, Period> &d)
+ : BaseDuration(d)
+ {
+ }
+
+ template<typename Period>
+ double get() const
+ {
+ auto const c = std::chrono::duration_cast<std::chrono::duration<double, Period>>(*this);
+ return c.count();
+ }
+
+ explicit constexpr operator bool() const
+ {
+ return *this != BaseDuration::zero();
+ }
+};
+
} /* namespace utils */
+#ifndef __DOXYGEN__
+template<class CharT, class Traits>
+std::basic_ostream<CharT, Traits> &operator<<(std::basic_ostream<CharT, Traits> &os,
+ const utils::Duration &d);
+#endif
+
} /* namespace libcamera */
#endif /* __LIBCAMERA_INTERNAL_UTILS_H__ */