Version: SMASH-3.3
smash::ToBinary Class Reference

#include <outputformatter.h>

Structure to convert a given value into binary format, such that all methods return a std::vector<char>.

Definition at line 109 of file outputformatter.h.

Public Types

using type = std::vector< char >
 Return type of this converter. More...
 

Public Member Functions

type as_integer (int32_t value) const
 Converts an integer to binary format. More...
 
type as_double (double value) const
 Converts a double to binary format. More...
 
type as_precise_double (double value) const
 Converts a double to binary format, intended for precise representation. More...
 
type as_string (const std::string &str) const
 Converts a string to binary format. More...
 

Static Public Attributes

static constexpr std::optional< char > separator = std::nullopt
 separator char is not needed for Binary format More...
 
static constexpr std::optional< char > end_of_line = std::nullopt
 Endline char is not needed for Binary format. More...
 

Private Member Functions

template<typename T >
type as_binary_data (T value) const
 Template method to convert numbers into binary format. More...
 

Member Typedef Documentation

◆ type

using smash::ToBinary::type = std::vector<char>

Return type of this converter.

Definition at line 112 of file outputformatter.h.

Member Function Documentation

◆ as_integer()

type smash::ToBinary::as_integer ( int32_t  value) const
inline

Converts an integer to binary format.

Parameters
[in]valuenumber to convert
Returns
a vector of char representing the binary format of the integer

Definition at line 126 of file outputformatter.h.

126 { return as_binary_data(value); }
type as_binary_data(T value) const
Template method to convert numbers into binary format.

◆ as_double()

type smash::ToBinary::as_double ( double  value) const
inline

Converts a double to binary format.

Parameters
[in]valuenumber to convert
Returns
a vector of char representing the binary format of the double

Definition at line 134 of file outputformatter.h.

134 { return as_binary_data(value); }

◆ as_precise_double()

type smash::ToBinary::as_precise_double ( double  value) const
inline

Converts a double to binary format, intended for precise representation.

Note that for binary output there is no difference between this and the ToBinary::as_double method, but this method has still to be introduced to allow other classes to get the converter class as a template parameter.

Parameters
[in]valuenumber to convert
Returns
a vector of char representing the binary format of the double

Definition at line 145 of file outputformatter.h.

145 { return as_double(value); }
type as_double(double value) const
Converts a double to binary format.

◆ as_string()

type smash::ToBinary::as_string ( const std::string &  str) const
inline

Converts a string to binary format.

Parameters
[in]strstring to convert
Returns
a vector of char representing the binary format of the string

Definition at line 153 of file outputformatter.h.

153  {
154  return type(str.begin(), str.end());
155  }
std::vector< char > type
Return type of this converter.

◆ as_binary_data()

template<typename T >
type smash::ToBinary::as_binary_data ( value) const
inlineprivate

Template method to convert numbers into binary format.

Parameters
[in]valuenumber to convert
Returns
a vector of char representing the binary format of the number

Definition at line 165 of file outputformatter.h.

165  {
166  type binary_data(sizeof(T));
167  std::memcpy(binary_data.data(), &value, sizeof(T));
168  return binary_data;
169  }

Member Data Documentation

◆ separator

constexpr std::optional<char> smash::ToBinary::separator = std::nullopt
staticconstexpr

separator char is not needed for Binary format

Definition at line 115 of file outputformatter.h.

◆ end_of_line

constexpr std::optional<char> smash::ToBinary::end_of_line = std::nullopt
staticconstexpr

Endline char is not needed for Binary format.

Definition at line 118 of file outputformatter.h.


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