Skip to content

Commit

Permalink
convert all primitive integer conversions to use (u)int64_t instead o…
Browse files Browse the repository at this point in the history
…f long
  • Loading branch information
lreiher committed Feb 20, 2024
1 parent a4dc35f commit e45be1d
Showing 1 changed file with 11 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,72 +30,43 @@ SOFTWARE.
namespace etsi_its_primitives_conversion {

template <typename T>
void toRos_INTEGER(const T& _INTEGER_in, long& INTEGER_out) {
int status = asn_INTEGER2long(&_INTEGER_in, &INTEGER_out);
if (status != 0)
throw std::range_error("Failed to convert INTEGER_t to long");
}

template <typename T>
void toRos_INTEGER(const T& _INTEGER_in, long long& INTEGER_out) {
void toRos_INTEGER(const T& _INTEGER_in, int64_t& INTEGER_out) {
long out;
int status = asn_INTEGER2long(&_INTEGER_in, &out);
if (status != 0)
throw std::range_error("Failed to convert INTEGER_t to long");
INTEGER_out = static_cast<long long>(out);
}

template <typename T>
void toRos_INTEGER(const T& _INTEGER_in, unsigned long& INTEGER_out) {
int status = asn_INTEGER2ulong(&_INTEGER_in, &INTEGER_out);
if (status != 0)
throw std::range_error("Failed to convert INTEGER_t to unsigned long");
INTEGER_out = static_cast<int64_t>(out);
}

template <typename T>
void toRos_INTEGER(const T& _INTEGER_in, unsigned long long& INTEGER_out) {
void toRos_INTEGER(const T& _INTEGER_in, uint64_t& INTEGER_out) {
unsigned long out;
int status = asn_INTEGER2ulong(&_INTEGER_in, &out);
if (status != 0)
throw std::range_error("Failed to convert INTEGER_t to unsigned long");
INTEGER_out = static_cast<unsigned long long>(out);
INTEGER_out = static_cast<uint64_t>(out);
}

template <typename T>
void toRos_INTEGER(const long& _INTEGER_in, T& INTEGER_out) {
void toRos_INTEGER(const int64_t& _INTEGER_in, T& INTEGER_out) {
if (std::numeric_limits<T>::max() < _INTEGER_in)
throw std::range_error("Failed to convert long (" + std::to_string(_INTEGER_in) + ") to smaller integer type (max: " + std::to_string(std::numeric_limits<T>::max()) + ")");
INTEGER_out = _INTEGER_in;
}

template <typename T>
void toStruct_INTEGER(const long& _INTEGER_in, T& INTEGER_out) {
int status = asn_long2INTEGER(&INTEGER_out, _INTEGER_in);
if (status != 0)
throw std::range_error("Failed to convert long to INTEGER_t");
throw std::range_error("Failed to convert int64_t (" + std::to_string(_INTEGER_in) + ") to smaller integer type (max: " + std::to_string(std::numeric_limits<T>::max()) + ")");
INTEGER_out = static_cast<T>(_INTEGER_in);
}

template <typename T>
void toStruct_INTEGER(const long long& _INTEGER_in, T& INTEGER_out) {
void toStruct_INTEGER(const int64_t& _INTEGER_in, T& INTEGER_out) {
const long in = static_cast<long>(_INTEGER_in);
int status = asn_long2INTEGER(&INTEGER_out, in);
if (status != 0)
throw std::range_error("Failed to convert long to INTEGER_t");
}

void toStruct_INTEGER(const long& _INTEGER_in, long& INTEGER_out) {
void toStruct_INTEGER(const int64_t& _INTEGER_in, int64_t& INTEGER_out) {
INTEGER_out = _INTEGER_in;
}

void toStruct_INTEGER(const long long& _INTEGER_in, long long& INTEGER_out) {
INTEGER_out = _INTEGER_in;
}

void toStruct_INTEGER(const long& _INTEGER_in, unsigned long& INTEGER_out) {
INTEGER_out = static_cast<unsigned long>(_INTEGER_in);
}

void toStruct_INTEGER(const long long& _INTEGER_in, unsigned long long& INTEGER_out) {
INTEGER_out = static_cast<unsigned long long>(_INTEGER_in);
void toStruct_INTEGER(const int64_t& _INTEGER_in, uint64_t& INTEGER_out) {
INTEGER_out = static_cast<uint64_t>(_INTEGER_in);
}
}

0 comments on commit e45be1d

Please sign in to comment.