Utility functions for clamp, comparison, traversal, and time formatting.
More...
#include <algorithm>
#include <array>
#include <ctime>
#include <functional>
#include <memory>
#include <string>
#include <vector>
#include "libkeepass/export.hh"
Go to the source code of this file.
Utility functions for clamp, comparison, traversal, and time formatting.
◆ clamp()
template<typename T >
| T keepass::clamp |
( |
T |
min, |
|
|
T |
max, |
|
|
T |
val |
|
) |
| |
|
inline |
Clamps a value into a specific range.
- Parameters
-
| [in] | min | Minimum value. |
| [in] | max | Maximum value. |
| [in] | val | Value to clamp. |
- Returns
- Clamped val.
◆ dfs()
template<typename T , const std::vector< std::shared_ptr< T > > &(T::*)() const F>
| void keepass::dfs |
( |
const std::shared_ptr< T > & |
current, |
|
|
std::function< void(const std::shared_ptr< T > &, std::size_t)> |
callback, |
|
|
std::size_t |
level = 0 |
|
) |
| |
|
inline |
Visits graph nodes in depth-first order. The first root node will not be visited.
- Template Parameters
-
| T | Node type. |
| F | Function of T that will return a vector with all children. |
- Parameters
-
| [in] | current | Start node. |
| [in] | callback | Function to be called for each visited node. |
◆ generate_uuid()
Generates a cryptographically random 128-bit UUID.
- Returns
- std::array of 16 bytes containing a UUID v4 value.
◆ indirect_equal() [1/2]
template<typename T >
| bool keepass::indirect_equal |
( |
const std::shared_ptr< T > & |
p0, |
|
|
const std::shared_ptr< T > & |
p1 |
|
) |
| |
|
inline |
Compares the elements of two pointers for equality. This function will dereference each pointer as necessary in order to test equality by value.
- Parameters
-
| [in] | p0 | Pointer to first element. |
| [in] | p1 | Pointer to second element. |
- Returns
- true if the elements of both dereferenced pointers are equal or if both pointers are null. false is returned otherwise.
◆ indirect_equal() [2/2]
template<typename T >
| bool keepass::indirect_equal |
( |
const std::vector< T > & |
v0, |
|
|
const std::vector< T > & |
v1 |
|
) |
| |
|
inline |
Compares the elements in two vectors for equality. This function is designed for vectors containing pointer types and will dereference each element before comparison.
- Parameters
-
| [in] | v0 | First vector. |
| [in] | v1 | Second vector. |
- Returns
- true if all (dereferenced) elements of v1 and v2 are equal. If not, the function returns false.
◆ time_to_str()
Converts an UTC date and time value into an UTC string.
The time is rendered in UTC regardless of the system timezone, so that the output is deterministic across machines.
- Parameters
-
| [in] | time | Date and time in UTC. |
- Returns
- time as a human readable string in UTC.