Sen API
Sen Libraries
Loading...
Searching...
No Matches
General utilities

Containers, adapters, and commonly used functions. More...

Collaboration diagram for General utilities:

Classes

class  sen::Duration
 A time duration. More...
struct  sen::ShouldBePassedByValue< Duration >
class  sen::Quantity< T, D >
 CRTP class that wraps T to ensure it's value stays within a certain range. More...
struct  sen::ShouldBePassedByValue< Quantity< T, D > >
class  sen::ScopeGuard< F >
 Runs the function object F on destruction. More...
struct  sen::SourceLocation
 Represents a location in source code. More...
class  sen::Span< T >
 Contiguous view of elements of type T. Inspired by http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0122r7.pdf. More...
class  sen::StaticVectorBase< T >
 Base class for stack-based, exception-safe and resizable vector with fixed-capacity. More...
class  sen::StaticVector< T, s >
 Stack-based, exception-free and resizable vector with fixed-capacity. More...
class  sen::StrongTypeBase< T >
 Wraps T to make it a strong type. More...
struct  sen::ShouldBePassedByValue< StrongTypeBase< T > >
class  sen::StrongType< T, D >
 CRTP class that wraps T to make it a strong type. More...
class  sen::TimeStamp
 A point in time. More...
struct  sen::ShouldBePassedByValue< TimeStamp >
class  sen::Uuid
 Universal Unique Identifier. More...
class  sen::UuidRandomGenerator
struct  std::hash< sen::Uuid >

Macros

#define SEN_RANGED_QUANTITY(class_name, value_type, min_value, max_value)
 Use this macro to define types for values that shall stay within some [min, max] range. NOLINTNEXTLINE(cppcoreguidelines-macro-usage).
#define SEN_NON_RANGED_QUANTITY(class_name, value_type)
 Use this macro to define types for quantities that specify no range NOLINTNEXTLINE(cppcoreguidelines-macro-usage).
#define SEN_SL()
 Convenience macro including the source location info. NOLINTNEXTLINE(cppcoreguidelines-macro-usage).
#define SEN_VERSION_STRING   "82f62a6\0"
#define SEN_VERSION_MAJOR   0
#define SEN_VERSION_MINOR   0
#define SEN_VERSION_PATCH   0

Typedefs

using float32_t = float
using float64_t = double
using uchar_t = unsigned char
using i8 = int8_t
using u8 = uint8_t
using i16 = int16_t
using u16 = uint16_t
using i32 = int32_t
using u32 = uint32_t
using i64 = int64_t
using u64 = uint64_t
using f32 = float32_t
using f64 = float64_t

Enumerations

enum class  sen::StaticVectorError : std::uint8_t { sen::StaticVectorError::full , sen::StaticVectorError::badRange , sen::StaticVectorError::empty }
 Things that can go wrong when using a StaticVector. More...
enum class  sen::UuidVariant { sen::UuidVariant::ncs = 0 , sen::UuidVariant::rfc = 1 , sen::UuidVariant::microsoft = 2 , sen::UuidVariant::reserved = 3 }
 Indicated by a bit pattern in octet 8, marked with N in xxxxxxxx-xxxx-xxxx-Nxxx-xxxxxxxxxxxx. More...
enum class  sen::UuidVersion {
  sen::UuidVersion::none = 0 , sen::UuidVersion::timeBased = 1 , sen::UuidVersion::dceSecurity = 2 , sen::UuidVersion::nameBasedMd5 = 3 ,
  sen::UuidVersion::randomNumberBased = 4 , sen::UuidVersion::nameBasedSha1 = 5
}
 Indicated by a bit pattern in octet 6, marked with M in xxxxxxxx-xxxx-Mxxx-xxxx-xxxxxxxxxxxx. More...

Functions

template<class F>
auto sen::makeScopeGuard (F &&f)
 Makes scope guard from a callable taking no arguments.
template<class F>
 sen::ScopeGuard (F) -> ScopeGuard< F >
template<class F>
auto sen::makeScopeGuard (const F &&f)=delete
template<class F>
auto sen::makeScopeGuard (F &f)=delete
template<class F>
auto sen::makeScopeGuard (const F &f)=delete
template<typename T>
constexpr bool sen::operator== (const Span< T > &lhs, const Span< T > &rhs) noexcept
template<typename T>
constexpr bool sen::operator!= (const Span< T > &lhs, const Span< T > &rhs) noexcept
template<typename T>
constexpr Span< T > sen::makeSpan (T *ptr, std::size_t size) noexcept
 Takes in a type that can be passed to a contiguous range and returns a Span.
template<typename T, std::size_t n>
constexpr Span< T > sen::makeSpan (T(&arr)[n]) noexcept
 Takes in a type that can be passed to a contiguous range and returns a Span.
template<typename T>
constexpr Span< T > sen::makeSpan (T &val) noexcept
 Takes in a type that can be passed to a contiguous range and returns a Span.
template<typename Iterator, typename T = typename std::iterator_traits<Iterator>::value_type>
constexpr Span< T > sen::makeSpan (Iterator first, Iterator last) noexcept
 Takes in a type that can be passed to a contiguous range and returns a Span.
template<typename T>
constexpr Span< T > sen::makeSpan (std::vector< T > &vector) noexcept
 Takes in a type that can be passed to a contiguous range and returns a Span.
template<typename T, std::size_t s>
constexpr Span< T > sen::makeSpan (std::array< T, s > &array) noexcept
 Takes in a type that can be passed to a contiguous range and returns a Span.
template<typename T>
constexpr Span< const T > sen::makeConstSpan (const T *ptr, std::size_t size) noexcept
 Takes in a type that can be passed to a contiguous range and returns a Span. The element types will be const qualified.
template<typename T, std::size_t n>
constexpr Span< const T > sen::makeConstSpan (const T(&arr)[n]) noexcept
 Takes in a type that can be passed to a contiguous range and returns a Span. The element types will be const qualified.
template<typename Iterator, typename T = typename std::iterator_traits<Iterator>::value_type>
constexpr Span< const T > sen::makeConstSpan (Iterator first, Iterator last) noexcept
 Takes in a type that can be passed to a contiguous range and returns a Span. The element types will be const qualified.
template<typename T>
constexpr Span< const T > sen::makeConstSpan (const std::vector< T > &vector) noexcept
 Takes in a type that can be passed to a contiguous range and returns a Span. The element types will be const qualified.
template<typename T, std::size_t s>
constexpr Span< const T > sen::makeConstSpan (const std::array< T, s > &array) noexcept
 Takes in a type that can be passed to a contiguous range and returns a Span. The element types will be const qualified.
template<typename T, std::size_t size>
std::enable_if_t< HasOperator< T >::eq, bool > sen::operator== (StaticVector< T, size > const &lhs, StaticVector< T, size > const &rhs) noexcept
 Checks if the contents of lhs and rhs are equal, that is, they have the same number of elements and each element in lhs compares equal with the element in rhs at the same position.
template<typename T, std::size_t size>
std::enable_if_t< HasOperator< T >::ne, bool > sen::operator!= (StaticVector< T, size > const &lhs, StaticVector< T, size > const &rhs) noexcept
 Equivalent to negating operator ==.
constexpr sen::Uuid::Uuid () noexcept=default
constexpr sen::Uuid::Uuid (uint64_t hi, uint64_t lo) noexcept
 Construct it from two consecutive 64-bit integers. Does not validate the data.
 sen::Uuid::Uuid (Span< const uint8_t > bytes) noexcept
 Construct it from an array of bytes. Does not validate the data.
 sen::Uuid::~Uuid ()=default
constexpr bool sen::Uuid::isNil () const noexcept
 True if all zeroes.
constexpr UuidVariant sen::Uuid::getVariant () const noexcept
 The variant of the UUID according to the spec.
constexpr UuidVersion sen::Uuid::getVersion () const noexcept
 The version of the UUID according to the spec.
constexpr uint64_t sen::Uuid::getHash () const noexcept
 Computes a 64-bit hash of the UUID.
constexpr uint32_t sen::Uuid::getHash32 () const noexcept
 Computes a 32-bit hash of the UUID.
std::array< uint8_t, byteCountsen::Uuid::bytes () const noexcept
std::string sen::Uuid::toString () const
 Builds a string out of this UUID.
bool sen::Uuid::isValid (std::string_view s) noexcept
 True if the UUID is well-formed.
Uuid sen::Uuid::fromString (std::string_view s) noexcept
 Parses a string and generates a UUD. Returns a Nil UUID in case of error.
void sen::Uuid::copy (std::array< uint8_t, byteCount > &arr) const
 Copy this std::array of bytes into the UUID.
void sen::Uuid::copy (StaticVector< uint8_t, byteCount > &vec) const
 Copy this StaticVector of bytes into the UUID.
void sen::Uuid::swap (Uuid &other) noexcept
 Swap the internal data.
constexpr bool sen::operator== (const Uuid &lhs, const Uuid &rhs)
constexpr bool sen::operator!= (const Uuid &lhs, const Uuid &rhs)
constexpr bool sen::operator< (const Uuid &lhs, const Uuid &rhs)
 sen::UuidRandomGenerator::UuidRandomGenerator ()
 sen::UuidRandomGenerator::UuidRandomGenerator (uint64_t seed)
Uuid sen::UuidRandomGenerator::operator() ()
std::ostream & sen::operator<< (std::ostream &s, const Uuid &id)
size_t std::hash< sen::Uuid >::operator() (const sen::Uuid &uuid) const noexcept

Variables

static constexpr std::size_t sen::Uuid::byteCount = 16

Friends

constexpr bool sen::Uuid::operator== (const Uuid &lhs, const Uuid &rhs)
constexpr bool sen::Uuid::operator!= (const Uuid &lhs, const Uuid &rhs)
constexpr bool sen::Uuid::operator< (const Uuid &lhs, const Uuid &rhs)

Detailed Description

Containers, adapters, and commonly used functions.


Class Documentation

◆ sen::SourceLocation

struct sen::SourceLocation

Represents a location in source code.

Class Members
string_view fileName {"file name not set"}
int lineNumber {-1}
string_view functionName {"function name not set"}

Macro Definition Documentation

◆ SEN_RANGED_QUANTITY

#define SEN_RANGED_QUANTITY ( class_name,
value_type,
min_value,
max_value )
Value:
struct class_name: public sen::Quantity<value_type, class_name> \
{ \
static constexpr bool hasRange = true; \
static constexpr value_type min = min_value; \
static constexpr value_type max = max_value; \
static_assert(min <= max); \
\
};
CRTP class that wraps T to ensure it's value stays within a certain range.
Definition quantity.h:28
constexpr Quantity() noexcept
Default-constructs the internal value. Lower bound is used if not within range.
Definition quantity.h:161

Use this macro to define types for values that shall stay within some [min, max] range. NOLINTNEXTLINE(cppcoreguidelines-macro-usage).

◆ SEN_NON_RANGED_QUANTITY

#define SEN_NON_RANGED_QUANTITY ( class_name,
value_type )
Value:
struct class_name: public sen::Quantity<value_type, class_name> \
{ \
static constexpr bool hasRange = false; \
};

Use this macro to define types for quantities that specify no range NOLINTNEXTLINE(cppcoreguidelines-macro-usage).

◆ SEN_SL

#define SEN_SL ( )
Value:
{ \
std::string_view {&__FILE__[SEN_SL_CONSTEXPR_VAL(::sen::impl::getFilenameOffset(__FILE__))]}, __LINE__, \
std::string_view(__FUNCTION__) \
}
Represents a location in source code.
Definition source_location.h:54
#define SEN_SL_CONSTEXPR_VAL(exp)
To force compile-time evaluation of exp. NOLINTNEXTLINE.
Definition source_location.h:42

Convenience macro including the source location info. NOLINTNEXTLINE(cppcoreguidelines-macro-usage).

◆ SEN_VERSION_STRING

#define SEN_VERSION_STRING   "82f62a6\0"

◆ SEN_VERSION_MAJOR

#define SEN_VERSION_MAJOR   0

◆ SEN_VERSION_MINOR

#define SEN_VERSION_MINOR   0

◆ SEN_VERSION_PATCH

#define SEN_VERSION_PATCH   0

Typedef Documentation

◆ float32_t

using float32_t = float

◆ float64_t

using float64_t = double

◆ uchar_t

using uchar_t = unsigned char

◆ i8

using i8 = int8_t

◆ u8

using u8 = uint8_t

◆ i16

using i16 = int16_t

◆ u16

using u16 = uint16_t

◆ i32

using i32 = int32_t

◆ u32

using u32 = uint32_t

◆ i64

using i64 = int64_t

◆ u64

using u64 = uint64_t

◆ f32

using f32 = float32_t

◆ f64

using f64 = float64_t

Enumeration Type Documentation

◆ StaticVectorError

enum class sen::StaticVectorError : std::uint8_t
strong

Things that can go wrong when using a StaticVector.

Enumerator
full 

The vector cannot hold more elements.

badRange 

The range is invalid.

empty 

Invalid operation on an empty vector.

◆ UuidVariant

enum class sen::UuidVariant
strong

Indicated by a bit pattern in octet 8, marked with N in xxxxxxxx-xxxx-xxxx-Nxxx-xxxxxxxxxxxx.

Enumerator
ncs 

NCS backward compatibility.

rfc 

RFC 4122/DCE 1.1.

microsoft 

Microsoft Corporation backward compatibility.

reserved 

reserved for possible future definition

◆ UuidVersion

enum class sen::UuidVersion
strong

Indicated by a bit pattern in octet 6, marked with M in xxxxxxxx-xxxx-Mxxx-xxxx-xxxxxxxxxxxx.

Enumerator
none 

Only possible for nil or invalid uuids.

timeBased 

The time-based version specified in RFC 4122.

dceSecurity 

DCE Security version, with embedded POSIX UIDs.

nameBasedMd5 

The name-based version specified in RFS 4122 with MD5 hashing.

randomNumberBased 

The randomly or pseudo-randomly generated version specified in RFS 4122.

nameBasedSha1 

The name-based version specified in RFS 4122 with SHA1 hashing.

Function Documentation

◆ makeScopeGuard() [1/4]

template<class F>
auto sen::makeScopeGuard ( F && f)
nodiscard

Makes scope guard from a callable taking no arguments.

◆ ScopeGuard()

template<class F>
sen::ScopeGuard ( F ) -> ScopeGuard< F >

◆ makeScopeGuard() [2/4]

template<class F>
auto sen::makeScopeGuard ( const F && f)
delete

◆ makeScopeGuard() [3/4]

template<class F>
auto sen::makeScopeGuard ( F & f)
delete

◆ makeScopeGuard() [4/4]

template<class F>
auto sen::makeScopeGuard ( const F & f)
delete

◆ operator==() [1/3]

template<typename T>
bool sen::operator== ( const Span< T > & lhs,
const Span< T > & rhs )
nodiscardconstexprnoexcept

◆ operator!=() [1/3]

template<typename T>
bool sen::operator!= ( const Span< T > & lhs,
const Span< T > & rhs )
nodiscardconstexprnoexcept

◆ makeSpan() [1/6]

template<typename T>
Span< T > sen::makeSpan ( T * ptr,
std::size_t size )
nodiscardconstexprnoexcept

Takes in a type that can be passed to a contiguous range and returns a Span.

◆ makeSpan() [2/6]

template<typename T, std::size_t n>
Span< T > sen::makeSpan ( T(&) arr[n])
nodiscardconstexprnoexcept

Takes in a type that can be passed to a contiguous range and returns a Span.

◆ makeSpan() [3/6]

template<typename T>
Span< T > sen::makeSpan ( T & val)
nodiscardconstexprnoexcept

Takes in a type that can be passed to a contiguous range and returns a Span.

◆ makeSpan() [4/6]

template<typename Iterator, typename T = typename std::iterator_traits<Iterator>::value_type>
Span< T > sen::makeSpan ( Iterator first,
Iterator last )
nodiscardconstexprnoexcept

Takes in a type that can be passed to a contiguous range and returns a Span.

◆ makeSpan() [5/6]

template<typename T>
Span< T > sen::makeSpan ( std::vector< T > & vector)
nodiscardconstexprnoexcept

Takes in a type that can be passed to a contiguous range and returns a Span.

◆ makeSpan() [6/6]

template<typename T, std::size_t s>
Span< T > sen::makeSpan ( std::array< T, s > & array)
nodiscardconstexprnoexcept

Takes in a type that can be passed to a contiguous range and returns a Span.

◆ makeConstSpan() [1/5]

template<typename T>
Span< const T > sen::makeConstSpan ( const T * ptr,
std::size_t size )
nodiscardconstexprnoexcept

Takes in a type that can be passed to a contiguous range and returns a Span. The element types will be const qualified.

◆ makeConstSpan() [2/5]

template<typename T, std::size_t n>
Span< const T > sen::makeConstSpan ( const T(&) arr[n])
nodiscardconstexprnoexcept

Takes in a type that can be passed to a contiguous range and returns a Span. The element types will be const qualified.

◆ makeConstSpan() [3/5]

template<typename Iterator, typename T = typename std::iterator_traits<Iterator>::value_type>
Span< const T > sen::makeConstSpan ( Iterator first,
Iterator last )
nodiscardconstexprnoexcept

Takes in a type that can be passed to a contiguous range and returns a Span. The element types will be const qualified.

◆ makeConstSpan() [4/5]

template<typename T>
Span< const T > sen::makeConstSpan ( const std::vector< T > & vector)
nodiscardconstexprnoexcept

Takes in a type that can be passed to a contiguous range and returns a Span. The element types will be const qualified.

◆ makeConstSpan() [5/5]

template<typename T, std::size_t s>
Span< const T > sen::makeConstSpan ( const std::array< T, s > & array)
nodiscardconstexprnoexcept

Takes in a type that can be passed to a contiguous range and returns a Span. The element types will be const qualified.

◆ operator==() [2/3]

template<typename T, std::size_t size>
std::enable_if_t< HasOperator< T >::eq, bool > sen::operator== ( StaticVector< T, size > const & lhs,
StaticVector< T, size > const & rhs )
noexcept

Checks if the contents of lhs and rhs are equal, that is, they have the same number of elements and each element in lhs compares equal with the element in rhs at the same position.

◆ operator!=() [2/3]

template<typename T, std::size_t size>
std::enable_if_t< HasOperator< T >::ne, bool > sen::operator!= ( StaticVector< T, size > const & lhs,
StaticVector< T, size > const & rhs )
noexcept

Equivalent to negating operator ==.

◆ Uuid() [1/3]

sen::Uuid::Uuid ( )
constexprdefaultnoexcept

◆ Uuid() [2/3]

sen::Uuid::Uuid ( uint64_t hi,
uint64_t lo )
inlineconstexprnoexcept

Construct it from two consecutive 64-bit integers. Does not validate the data.

◆ Uuid() [3/3]

sen::Uuid::Uuid ( Span< const uint8_t > bytes)
inlineexplicitnoexcept

Construct it from an array of bytes. Does not validate the data.

◆ ~Uuid()

sen::Uuid::~Uuid ( )
default

◆ isNil()

bool sen::Uuid::isNil ( ) const
inlinenodiscardconstexprnoexcept

True if all zeroes.

◆ getVariant()

UuidVariant sen::Uuid::getVariant ( ) const
nodiscardconstexprnoexcept

The variant of the UUID according to the spec.

◆ getVersion()

UuidVersion sen::Uuid::getVersion ( ) const
nodiscardconstexprnoexcept

The version of the UUID according to the spec.

◆ getHash()

uint64_t sen::Uuid::getHash ( ) const
inlinenodiscardconstexprnoexcept

Computes a 64-bit hash of the UUID.

◆ getHash32()

uint32_t sen::Uuid::getHash32 ( ) const
nodiscardconstexprnoexcept

Computes a 32-bit hash of the UUID.

◆ bytes()

std::array< uint8_t, Uuid::byteCount > sen::Uuid::bytes ( ) const
inlinenodiscardnoexcept

◆ toString()

std::string sen::Uuid::toString ( ) const
nodiscard

Builds a string out of this UUID.

◆ isValid()

bool sen::Uuid::isValid ( std::string_view s)
nodiscardnoexcept

True if the UUID is well-formed.

◆ fromString()

Uuid sen::Uuid::fromString ( std::string_view s)
nodiscardnoexcept

Parses a string and generates a UUD. Returns a Nil UUID in case of error.

◆ copy() [1/2]

void sen::Uuid::copy ( std::array< uint8_t, byteCount > & arr) const
inline

Copy this std::array of bytes into the UUID.

◆ copy() [2/2]

void sen::Uuid::copy ( StaticVector< uint8_t, byteCount > & vec) const
inline

Copy this StaticVector of bytes into the UUID.

◆ swap()

void sen::Uuid::swap ( Uuid & other)
inlinenoexcept

Swap the internal data.

◆ operator==() [3/3]

bool sen::operator== ( const Uuid & lhs,
const Uuid & rhs )
nodiscardconstexprnoexcept

◆ operator!=() [3/3]

bool sen::operator!= ( const Uuid & lhs,
const Uuid & rhs )
nodiscardconstexprnoexcept

◆ operator<()

bool sen::operator< ( const Uuid & lhs,
const Uuid & rhs )
nodiscardconstexprnoexcept

◆ UuidRandomGenerator() [1/2]

sen::UuidRandomGenerator::UuidRandomGenerator ( )
inline

◆ UuidRandomGenerator() [2/2]

sen::UuidRandomGenerator::UuidRandomGenerator ( uint64_t seed)
inlineexplicit

◆ operator()() [1/2]

Uuid sen::UuidRandomGenerator::operator() ( )
inline

◆ operator<<()

std::ostream & sen::operator<< ( std::ostream & s,
const Uuid & id )

◆ operator()() [2/2]

size_t std::hash< sen::Uuid >::operator() ( const sen::Uuid & uuid) const
inlinenoexcept

Variable Documentation

◆ byteCount

std::size_t sen::Uuid::byteCount = 16
staticconstexpr

Friends

◆ operator==

bool operator== ( const Uuid & lhs,
const Uuid & rhs )
friend

◆ operator!=

bool operator!= ( const Uuid & lhs,
const Uuid & rhs )
friend

◆ operator<

bool operator< ( const Uuid & lhs,
const Uuid & rhs )
friend