libkeepass 0.2.0
KeePass key database importer/exporter library
Loading...
Searching...
No Matches
util.hh File Reference

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.

Functions

template<typename T >
T keepass::clamp (T min, T max, T val)
 
template<typename T >
bool keepass::indirect_equal (const std::vector< T > &v0, const std::vector< T > &v1)
 
template<typename T >
bool keepass::indirect_equal (const std::shared_ptr< T > &p0, const std::shared_ptr< T > &p1)
 
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)
 
LIBKEEPASS_API std::string keepass::time_to_str (const std::time_t &time)
 
LIBKEEPASS_API std::array< uint8_t, 16 > keepass::generate_uuid ()
 Generates a cryptographically random 128-bit UUID.
 

Detailed Description

Utility functions for clamp, comparison, traversal, and time formatting.

Function Documentation

◆ clamp()

template<typename T >
T keepass::clamp ( T  min,
T  max,
T  val 
)
inline

Clamps a value into a specific range.

Parameters
[in]minMinimum value.
[in]maxMaximum value.
[in]valValue 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
TNode type.
FFunction of T that will return a vector with all children.
Parameters
[in]currentStart node.
[in]callbackFunction to be called for each visited node.

◆ generate_uuid()

LIBKEEPASS_API std::array< uint8_t, 16 > keepass::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]p0Pointer to first element.
[in]p1Pointer 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]v0First vector.
[in]v1Second vector.
Returns
true if all (dereferenced) elements of v1 and v2 are equal. If not, the function returns false.

◆ time_to_str()

LIBKEEPASS_API std::string keepass::time_to_str ( const std::time_t &  time)

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]timeDate and time in UTC.
Returns
time as a human readable string in UTC.