etsi_its_messages v3.0.0
 
Loading...
Searching...
No Matches
checks.h File Reference

Sanity-check functions etc. More...

Go to the source code of this file.

Functions

template<typename T1, typename T2>
void throwIfOutOfRange (const T1 &val, const T2 &min, const T2 &max, const std::string val_desc)
 Throws an exception if a given value is out of a defined range.
 
void throwIfNotPresent (const bool is_present, const std::string val_desc)
 Throws an exception if the given value is not present.
 

Detailed Description

Sanity-check functions etc.

Definition in file checks.h.

Function Documentation

◆ throwIfNotPresent()

void throwIfNotPresent ( const bool is_present,
const std::string val_desc )
inline

Throws an exception if the given value is not present.

Parameters
is_presentWhether the value is present.
val_descDescription of the value for the exception message.

Definition at line 57 of file checks.h.

57 {
58 if (!is_present) throw std::invalid_argument(val_desc + " is not present!");
59}

◆ throwIfOutOfRange()

template<typename T1, typename T2>
void throwIfOutOfRange ( const T1 & val,
const T2 & min,
const T2 & max,
const std::string val_desc )

Throws an exception if a given value is out of a defined range.

Template Parameters
T1
T2
Parameters
valThe value to check if it is in the range.
minThe minimum value of the range.
maxThe maximum value of the range.
val_descDescription of the value for the exception message.

Definition at line 46 of file checks.h.

46 {
47 if (val < min || val > max)
48 throw std::invalid_argument(val_desc + " value is out of range (" + std::to_string(min) + "..." +
49 std::to_string(max) + ")!");
50}