ProvSQL C/C++ API
Adding support for provenance and uncertainty management to PostgreSQL databases
Loading...
Searching...
No Matches
provsql_utils_cpp.h File Reference

C++ utility functions for UUID manipulation. More...

#include "postgres.h"
#include "provsql_utils.h"
#include <string>
Include dependency graph for provsql_utils_cpp.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

std::string UUIDDatum2string (Datum token)
 Convert a PostgreSQL Datum holding a UUID to a std::string.
 
std::string uuid2string (pg_uuid_t uuid)
 Format a pg_uuid_t as a std::string.
 
pg_uuid_t string2uuid (const std::string &source)
 Parse a UUID string into a pg_uuid_t.
 
std::size_t hash_value (const pg_uuid_t &u)
 Compute a hash value for a pg_uuid_t.
 
bool operator== (const pg_uuid_t &u, const pg_uuid_t &v)
 Test two pg_uuid_t values for equality.
 

Detailed Description

C++ utility functions for UUID manipulation.

This header declares C++ helper functions that convert between PostgreSQL's pg_uuid_t / Datum representations and std::string, compute hash values for UUIDs (enabling use in std::unordered_map and Boost containers), and define equality comparison for pg_uuid_t values.

These utilities are used throughout the C++ circuit and evaluation code wherever UUID tokens need to be stored in STL containers or compared by value.

Definition in file provsql_utils_cpp.h.

Function Documentation

◆ hash_value()

std::size_t hash_value ( const pg_uuid_t u)

Compute a hash value for a pg_uuid_t.

Reinterprets the 16-byte UUID as two 64-bit integers and XOR-combines their standard hashes. Used by Boost's hash infrastructure so that pg_uuid_t can be used as a key in Boost multi-index containers.

Parameters
uThe UUID to hash.
Returns
A std::size_t hash value.

Definition at line 110 of file provsql_utils_cpp.cpp.

◆ operator==()

bool operator== ( const pg_uuid_t u,
const pg_uuid_t v 
)

Test two pg_uuid_t values for equality.

Compares all 16 bytes of the UUID data.

Parameters
uFirst UUID.
vSecond UUID.
Returns
true if u and v represent the same UUID.

Definition at line 115 of file provsql_utils_cpp.cpp.

◆ string2uuid()

pg_uuid_t string2uuid ( const std::string &  source)

Parse a UUID string into a pg_uuid_t.

Accepts the standard 36-character hyphenated hex representation. Throws std::invalid_argument if the string is malformed.

Parameters
sourceThe UUID string to parse.
Returns
The parsed pg_uuid_t.

◆ uuid2string()

std::string uuid2string ( pg_uuid_t  uuid)

Format a pg_uuid_t as a std::string.

Parameters
uuidThe UUID to format.
Returns
The UUID as a 36-character hyphenated hex std::string.

Definition at line 28 of file provsql_utils_cpp.cpp.

Here is the caller graph for this function:

◆ UUIDDatum2string()

std::string UUIDDatum2string ( Datum  token)

Convert a PostgreSQL Datum holding a UUID to a std::string.

Detoasts and formats the UUID value as the standard 36-character hyphenated hex string (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).

Parameters
tokenA Datum containing a pg_uuid_t value.
Returns
The UUID as a std::string.

Definition at line 104 of file provsql_utils_cpp.cpp.

Here is the call graph for this function:
Here is the caller graph for this function: