convertINTEGER.h
Go to the documentation of this file.
1 
25 #pragma once
26 
27 #include <limits>
28 #include <stdexcept>
29 
31 
32  template <typename T>
33  void toRos_INTEGER(const T& _INTEGER_in, int64_t& INTEGER_out) {
34  long out;
35  int status = asn_INTEGER2long(&_INTEGER_in, &out);
36  if (status != 0)
37  throw std::range_error("Failed to convert INTEGER_t to int64_t");
38  INTEGER_out = static_cast<int64_t>(out);
39  }
40 
41  template <typename T>
42  void toRos_INTEGER(const T& _INTEGER_in, uint64_t& INTEGER_out) {
43  unsigned long out;
44  int status = asn_INTEGER2ulong(&_INTEGER_in, &out);
45  if (status != 0)
46  throw std::range_error("Failed to convert INTEGER_t to uint64_t");
47  INTEGER_out = static_cast<uint64_t>(out);
48  }
49 
50  template <typename T>
51  void toRos_INTEGER(const long& _INTEGER_in, T& INTEGER_out) {
52  if (std::numeric_limits<T>::max() < _INTEGER_in)
53  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()) + ")");
54  INTEGER_out = static_cast<T>(_INTEGER_in);
55  }
56 
57  void toRos_INTEGER(const long& _INTEGER_in, int64_t& INTEGER_out) {
58  INTEGER_out = _INTEGER_in;
59  }
60 
61  template <typename T>
62  void toStruct_INTEGER(const int64_t& _INTEGER_in, T& INTEGER_out) {
63  const long in = static_cast<long>(_INTEGER_in);
64  int status = asn_long2INTEGER(&INTEGER_out, in);
65  if (status != 0)
66  throw std::range_error("Failed to convert int64_t to INTEGER_t");
67  }
68 
69  void toStruct_INTEGER(const int64_t& _INTEGER_in, long& INTEGER_out) {
70  INTEGER_out = _INTEGER_in;
71  }
72 
73  void toStruct_INTEGER(const int64_t& _INTEGER_in, unsigned long& INTEGER_out) {
74  if (_INTEGER_in < 0)
75  throw std::range_error("Failed to convert int64_t to unsigned long");
76  INTEGER_out = static_cast<unsigned long>(_INTEGER_in);
77  }
78 }
etsi_its_primitives_conversion::toStruct_INTEGER
void toStruct_INTEGER(const int64_t &_INTEGER_in, T &INTEGER_out)
Definition: convertINTEGER.h:62
etsi_its_primitives_conversion::toRos_INTEGER
void toRos_INTEGER(const T &_INTEGER_in, int64_t &INTEGER_out)
Definition: convertINTEGER.h:33
etsi_its_primitives_conversion
Definition: convertBIT_STRING.h:29


etsi_its_primitives_conversion
Author(s): Jean-Pierre Busch , Guido Küppers , Lennart Reiher
autogenerated on Sun May 18 2025 02:28:47