ETSI STF525 / Internal Testing test suite This project provides an internal testing test suite and its associated Test Adapter/Codec

Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Attributes | List of all members
converter Class Reference

This class provide a set of methods for types conversions. More...

`#include <converter.hh>`

## Public Types
enum | endian_t { big_endian, little_endian }
| Endianess style. More...

## Public Member Functions
uint8_t | bcd_to_bin (const uint8_t p_value)
| Convert a Binary Coded Decimal value into a binary value. More...
uint8_t | bin_to_bcd (const uint8_t p_value)
| Convert a binary value into a Binary Coded Decimal value. More...
uint16_t | swap (const uint16_t p_value)
| Swap two bytes length value (e.g. 0xCAFE becomes 0xFECA) More...
int16_t | swap (const int16_t p_value)
uint32_t | swap (const uint32_t p_value)
| Swap four bytes length value (used for littel endian / big endian) More...
int32_t | swap (const int32_t p_value)
std::string | string_to_hexa (const std::string &p_value)
| Convert a string into an hexadecimal string. More...
std::string | bytes_to_hexa (const std::vector< uint8_t > &p_value)
| Convert a bytes array int32_t an hexadecimal string. More...
std::vector< uint8_t > | hexa_to_bytes (const std::string &p_value)
| Convert an hexadecimal string into a bytes array. More...
std::string | time_to_string (const time_t p_time)
| Convert a time in time_t format into a string formated according to RFC 822, 1036, 1123, 2822. More...
std::string | time_to_string (const struct tm &p_time)
| Convert a time in struct tm format into a string formated according to RFC 822, 1036, 1123, 2822. More...
std::vector< uint8_t > | short_to_bytes (const int16_t p_value, const endian_t p_endianess=big_endian) const
| Convert a 16-bits integer (int16_t) into a bytes array. More...
int16_t | bytes_to_short (const std::vector< uint8_t > &p_value, const endian_t p_endianess=big_endian) const
| Convert a bytes array into a 16-bits integer (int16_t) More...
std::vector< uint8_t > | int_to_bytes (const int32_t p_value, const endian_t p_endianess=big_endian) const
| Convert a 32-bits integer (int32_t) into a bytes array. More...
int32_t | bytes_to_int (const std::vector< uint8_t > &p_value, const endian_t p_endianess=big_endian) const
| Convert a bytes array into a 32-bits integer (int32_t) More...
std::vector< uint8_t > | long_to_bytes (const int64_t p_value, const endian_t p_endianess=big_endian) const
| Convert a 64-bits integer (int64_t) into a bytes array. More...
int64_t | bytes_to_long (const std::vector< uint8_t > &p_value, const endian_t p_endianess=big_endian) const
| Convert a bytes array into a 64-bits integer (int64_t) More...
std::vector< uint8_t > | float_to_bytes (const float p_value) const
| Convert a float value into a bytes array. More...
float | bytes_to_float (const std::vector< uint8_t > &p_value) const
| Convert a bytes array into a float. More...
std::vector< uint8_t > | string_to_bytes (const std::string &p_value) const
| Convert a string into a bytes array. More...
std::string | bytes_to_string (const std::vector< uint8_t > &p_value) const
| Convert a bytes array into a string. More...
int32_t | string_to_int (const std::string &p_value) const
| Convert a string into an integer. More...
std::string | int_to_string (const int32_t &p_value) const
| Convert an integer into a string. More...
std::string | trim (const std::string &p_value, const std::string &p_trim_chars=" \)
| Returns a copy of the string, with leading and trailing special characters omitted. More...
std::vector< std::string > | split_arguments_line (const std::string &p_value)
| Convert the provided string into a list of arguments. More...

## Static Public Member Functions
static converter & | get_instance ()
| Public accessor to the single object reference. More...

## Private Member Functions
| converter ()
| Default private ctor. More...
| ~converter ()
| Default private dtor. More...

## Static Private Attributes
static converter * | instance = NULL
| Unique static object reference of this class. More...

## Detailed Description

This class provide a set of methods for types conversions.

Remarks
  Singleton pattern

## Member Enumeration Documentation

## ◆ endian_t

enum converter::endian_t

Endianess style.

Enumerator
big_endian |
little_endian |

## Constructor & Destructor Documentation

## ◆ converter()

converter::converter | ( |  | ) |
| inline private

Default private ctor.

## ◆ ~converter()

converter::~converter | ( |  | ) |
| inline private

Default private dtor.

## Member Function Documentation

## ◆ bcd_to_bin()

uint8_t converter::bcd_to_bin | ( | const uint8_t | p_value | ) |
| inline

Convert a Binary Coded Decimal value into a binary value.

Parameters

  [in] | p_value | The BDC value

Returns
  The binary value

## ◆ bin_to_bcd()

uint8_t converter::bin_to_bcd | ( | const uint8_t | p_value | ) |
| inline

Convert a binary value into a Binary Coded Decimal value.

Parameters

  [in] | p_value | The binary value

Returns
  The BCD value

## ◆ bytes_to_float()

float converter::bytes_to_float | ( | const std::vector< uint8_t > & | p_value | ) | const
| inline

Convert a bytes array into a float.

Parameters

  [in] | p_value | The bytes array

Returns
  The float value

## ◆ bytes_to_hexa()

std::string converter::bytes_to_hexa | ( | const std::vector< uint8_t > & | p_value | ) |

Convert a bytes array int32_t an hexadecimal string.

Parameters

  [in] | p_value | The bytes array value

Returns
  The hexadecimal value

## ◆ bytes_to_int()

int32_t converter::bytes_to_int | ( | const std::vector< uint8_t > & | p_value,
|  | const endian_t | p_endianess = `big_endian`
| ) |  | const
| inline

Convert a bytes array into a 32-bits integer (int32_t)

Parameters

  [in] | p_value | The bytes array
  [in] | p_endianess | Endianess style. Default: big_endian

Returns
  The 32-bits integer on success, LONG_MAX on error (wrong bytes array size)

## ◆ bytes_to_long()

int64_t converter::bytes_to_long | ( | const std::vector< uint8_t > & | p_value,
|  | const endian_t | p_endianess = `big_endian`
| ) |  | const
| inline

Convert a bytes array into a 64-bits integer (int64_t)

Parameters

  [in] | p_value | The bytes array
  [in] | p_endianess | Endianess style. Default: big_endian

Returns
  The 64-bits integer on success, LLONG_MAX on error (wrong bytes array size)

## ◆ bytes_to_short()

int16_t converter::bytes_to_short | ( | const std::vector< uint8_t > & | p_value,
|  | const endian_t | p_endianess = `big_endian`
| ) |  | const
| inline

Convert a bytes array into a 16-bits integer (int16_t)

Parameters

  [in] | p_value | The bytes array
  [in] | p_endianess | Endianess style. Default: big_endian

Returns
  The 16-bits integer on success, SHRT_MAX on error (wrong bytes array size)

## ◆ bytes_to_string()

std::string converter::bytes_to_string | ( | const std::vector< uint8_t > & | p_value | ) | const
| inline

Convert a bytes array into a string.

Parameters

  [in] | p_value | The bytes array value

Returns
  The string value

## ◆ float_to_bytes()

std::vector<uint8_t> converter::float_to_bytes | ( | const float | p_value | ) | const
| inline

Convert a float value into a bytes array.

Parameters

  [in] | p_value | The float value

Returns
  The bytes array value

## ◆ get_instance()

static converter& converter::get_instance | ( |  | ) |
| inline static

Public accessor to the single object reference.

## ◆ hexa_to_bytes()

std::vector< uint8_t > converter::hexa_to_bytes | ( | const std::string & | p_value | ) |

Convert an hexadecimal string into a bytes array.

Parameters

  [in] | p_value | The hexadecimal value

Returns
  The bytes array value

## ◆ int_to_bytes()

std::vector<uint8_t> converter::int_to_bytes | ( | const int32_t | p_value,
|  | const endian_t | p_endianess = `big_endian`
| ) |  | const
| inline

Convert a 32-bits integer (int32_t) into a bytes array.

Parameters

  [in] | p_value | The 32-bits integer value
  [in] | p_endianess | Endianess style. Default: big_endian

Returns
  The bytes array value

## ◆ int_to_string()

std::string converter::int_to_string | ( | const int32_t & | p_value | ) | const
| inline

Convert an integer into a string.

Parameters

  [in] | p_value | The integer value

Returns
  The string value

## ◆ long_to_bytes()

std::vector<uint8_t> converter::long_to_bytes | ( | const int64_t | p_value,
|  | const endian_t | p_endianess = `big_endian`
| ) |  | const
| inline

Convert a 64-bits integer (int64_t) into a bytes array.

Parameters

  [in] | p_value | The 64-bits integer value
  [in] | p_endianess | Endianess style. Default: big_endian

Returns
  The bytes array value

## ◆ short_to_bytes()

std::vector<uint8_t> converter::short_to_bytes | ( | const int16_t | p_value,
|  | const endian_t | p_endianess = `big_endian`
| ) |  | const
| inline

Convert a 16-bits integer (int16_t) into a bytes array.

Parameters

  [in] | p_value | The 16-bits integer value
  [in] | p_endianess | Endianess style. Default: big_endian

Returns
  The bytes array value

## ◆ split_arguments_line()

std::vector< std::string > converter::split_arguments_line | ( | const std::string & | p_value | ) |

Convert the provided string into a list of arguments.

Parameters

  [in] | p_value | The string value

Returns
  The arguments list
  std::string str = "--host localhost --port 12345 --duration -1";
  std::vector<std::string> tokens = converter::get_instance().split_arguments_line(str);
  std::clog << "Tokens: " << std::endl;
  for (auto it = tokens.begin(); it != tokens.end(); ++it) {
  std::clog << " " << *it << std::endl;
  }

## ◆ string_to_bytes()

std::vector<uint8_t> converter::string_to_bytes | ( | const std::string & | p_value | ) | const
| inline

Convert a string into a bytes array.

Parameters

  [in] | p_value | The string value

Returns
  The bytes array value

## ◆ string_to_hexa()

std::string converter::string_to_hexa | ( | const std::string & | p_value | ) |

Convert a string into an hexadecimal string.

Parameters

  [in] | p_value | The string value

Returns
  The hexadecimal value

## ◆ string_to_int()

int32_t converter::string_to_int | ( | const std::string & | p_value | ) | const
| inline

Convert a string into an integer.

Parameters

  [in] | p_value | The string value

Returns
  The integer value

## ◆ swap() [1/4]

uint16_t converter::swap | ( | const uint16_t | p_value | ) |

Swap two bytes length value (e.g. 0xCAFE becomes 0xFECA)

Parameters

  [in] | p_value | The value to swap

Returns
  The swapped value

## ◆ swap() [2/4]

int16_t converter::swap | ( | const int16_t | p_value | ) |
| inline

## ◆ swap() [3/4]

uint32_t converter::swap | ( | const uint32_t | p_value | ) |

Swap four bytes length value (used for littel endian / big endian)

Parameters

  [in] | p_value | The value to swap

Returns
  The swapped value

## ◆ swap() [4/4]

int32_t converter::swap | ( | const int32_t | p_value | ) |
| inline

## ◆ time_to_string() [1/2]

std::string converter::time_to_string | ( | const time_t | p_time | ) |

Convert a time in time_t format into a string formated according to RFC 822, 1036, 1123, 2822.

Parameters

  [in] | p_time | The time to convert in time_t format

Returns
  The time string formated

See also
  http://www.unixtimestamp.com/
  std::string result = time_to_string(1489755780);
  result.compare("Fri, 17 Mar 2017 13:03:00 +0000") == 0 // When time zone is set to UTC

Remarks
  Use commands 1) timedatectl to change your machine timezone (e.g. sudo timedatectl set-timezone UTC to change machine timezone to UTC, 2) timedatectl list-timezones to get the list of the timezones)

## ◆ time_to_string() [2/2]

std::string converter::time_to_string | ( | const struct tm & | p_time | ) |

Convert a time in struct tm format into a string formated according to RFC 822, 1036, 1123, 2822.

Parameters

  [in] | p_time | The time to convert in struct tm format

Returns
  The time string formated

See also
  http://www.unixtimestamp.com/

## ◆ trim()

std::string converter::trim | ( | const std::string & | p_value,
|  | const std::string & | p_trim_chars = `" \t"`
| ) |  |

Returns a copy of the string, with leading and trailing special characters omitted.

Parameters

  [in] | p_value | The string value
  [in] | p_trim_chars | The special characters to be omitted. Default: ' ' and TAB

Returns
  The new string value

## Member Data Documentation

## ◆ instance

converter * converter::instance = NULL
| static private

Unique static object reference of this class.

The documentation for this class was generated from the following files:

- /home/vagrant/TriesAndDelete/etsi_its/framework/include/converter.hh
- /home/vagrant/TriesAndDelete/etsi_its/framework/src/converter.cc