7 #ifndef __LIBCAMERA_INTERNAL_UTILS_H__ 8 #define __LIBCAMERA_INTERNAL_UTILS_H__ 24 #define O_TMPFILE (020000000 | O_DIRECTORY) 33 const char *
basename(
const char *path);
36 std::string
dirname(
const std::string &path);
39 std::vector<typename T::key_type>
map_keys(
const T &map)
41 std::vector<typename T::key_type> keys;
42 std::transform(map.begin(), map.end(), std::back_inserter(keys),
43 [](
const auto &value) {
return value.first; });
47 template<
class InputIt1,
class InputIt2>
49 InputIt2 first2, InputIt2 last2)
51 unsigned int count = 0;
53 while (first1 != last1 && first2 != last2) {
54 if (*first1 < *first2) {
57 if (!(*first2 < *first1))
66 using clock = std::chrono::steady_clock;
67 using duration = std::chrono::steady_clock::duration;
68 using time_point = std::chrono::steady_clock::time_point;
79 std::basic_ostream<char, std::char_traits<char>> &
80 operator<<(std::basic_ostream<char, std::char_traits<char>> &stream,
const _hex &h);
84 _hex
hex(T value,
unsigned int width = 0);
88 inline _hex hex<int32_t>(int32_t value,
unsigned int width)
90 return {
static_cast<uint64_t
>(value), width ? width : 8 };
94 inline _hex hex<uint32_t>(uint32_t value,
unsigned int width)
96 return {
static_cast<uint64_t
>(value), width ? width : 8 };
100 inline _hex hex<int64_t>(int64_t value,
unsigned int width)
102 return {
static_cast<uint64_t
>(value), width ? width : 16 };
106 inline _hex hex<uint64_t>(uint64_t value,
unsigned int width)
108 return {
static_cast<uint64_t
>(value), width ? width : 16 };
112 size_t strlcpy(
char *dst,
const char *src,
size_t size);
115 template<
typename Container,
typename UnaryOp>
116 std::string
join(
const Container &items,
const std::string &sep, UnaryOp op)
118 std::ostringstream ss;
121 for (
typename Container::const_iterator it = std::begin(items);
122 it != std::end(items); ++it) {
134 template<
typename Container>
135 std::string
join(
const Container &items,
const std::string &sep)
137 std::ostringstream ss;
140 for (
typename Container::const_iterator it = std::begin(items);
141 it != std::end(items); ++it) {
153 template<
typename Container,
typename UnaryOp>
154 std::string
join(
const Container &items,
const std::string &sep, UnaryOp op =
nullptr);
162 StringSplitter(
const std::string &str,
const std::string &delim);
167 iterator(
const StringSplitter *ss, std::string::size_type pos);
169 iterator &operator++();
171 bool operator!=(
const iterator &other)
const;
174 const StringSplitter *ss_;
175 std::string::size_type pos_;
176 std::string::size_type next_;
179 iterator begin()
const;
180 iterator end()
const;
189 details::StringSplitter
split(
const std::string &str,
const std::string &delim);
191 std::string
toAscii(
const std::string &str);
196 constexpr
unsigned int alignDown(
unsigned int value,
unsigned int alignment)
198 return value / alignment * alignment;
201 constexpr
unsigned int alignUp(
unsigned int value,
unsigned int alignment)
203 return (value + alignment - 1) / alignment * alignment;
209 struct reverse_adapter {
214 auto begin(reverse_adapter<T> r)
216 return std::rbegin(r.iterable);
220 auto end(reverse_adapter<T> r)
222 return std::rend(r.iterable);
228 details::reverse_adapter<T>
reverse(T &&iterable)
std::string libcameraSourcePath()
Retrieve the path to the source directory.
Definition: utils.cpp:428
const char * basename(const char *path)
Strip the directory prefix from the path.
Definition: utils.cpp:45
struct timespec duration_to_timespec(const duration &value)
Convert a duration to a timespec.
Definition: utils.cpp:164
Transform operator*(Transform t0, Transform t1)
Compose two transforms together.
Definition: transform.cpp:207
Top-level libcamera namespace.
Definition: bound_method.h:15
std::chrono::steady_clock clock
The libcamera clock (monotonic)
Definition: utils.h:66
std::vector< typename T::key_type > map_keys(const T &map)
Retrieve the keys of a std::map<>
Definition: utils.h:39
std::string dirname(const std::string &path)
Identify the dirname portion of a path.
Definition: utils.cpp:86
_hex hex(T value, unsigned int width=0)
Write an hexadecimal value to an output string.
unsigned int set_overlap(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2)
Count the number of elements in the intersection of two ranges.
Definition: utils.h:48
std::chrono::steady_clock::time_point time_point
The libcamera time point related to libcamera::utils::clock.
Definition: utils.h:68
std::string time_point_to_string(const time_point &time)
Convert a time point to a string representation.
Definition: utils.cpp:178
char * secure_getenv(const char *name)
Get an environment variable.
Definition: utils.cpp:65
std::string libcameraBuildPath()
Retrieve the path to the build directory.
Definition: utils.cpp:388
constexpr unsigned int alignDown(unsigned int value, unsigned int alignment)
Align value down to alignment.
Definition: utils.h:196
std::chrono::steady_clock::duration duration
The libcamera duration related to libcamera::utils::clock.
Definition: utils.h:67
details::StringSplitter split(const std::string &str, const std::string &delim)
Split a string based on a delimiter.
Definition: utils.cpp:326
size_t strlcpy(char *dst, const char *src, size_t size)
Copy a string with a size limit.
Definition: utils.cpp:243
std::string join(const Container &items, const std::string &sep, UnaryOp op=nullptr)
Join elements of a container in a string with a separator.
constexpr unsigned int alignUp(unsigned int value, unsigned int alignment)
Align value up to alignment.
Definition: utils.h:201
std::string toAscii(const std::string &str)
Remove any non-ASCII characters from a string.
Definition: utils.cpp:340
details::reverse_adapter< T > reverse(T &&iterable)
Wrap an iterable to reverse iteration in a range-based loop.
Definition: utils.h:228