LIBRCSC Docs
Documentation for HELIOS's BASE LIBRCSC library for RoboCup 2D Simulation League.
All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
rcsc::AudioCodec Class Reference

communication message encoder/decorder More...

#include <audio_codec.h>

Public Types

typedef std::unordered_map< char, int > CharToIntCont
 map from char to int
 
typedef std::vector< char > IntToCharCont
 map from int to char
 

Public Member Functions

void createMap (const int shift)
 
const CharToIntContcharToIntMap () const
 get character to interger map object More...
 
const IntToCharContintToCharMap () const
 get integer to character map object More...
 
bool encodeInt64ToStr (const std::int64_t &ival, const int len, std::string &to) const
 encode decimal (64bit) integer to the encoded string. More...
 
bool decodeStrToInt64 (const std::string &from, std::int64_t *to) const
 decode the message string to the decimal (64bit) integer More...
 
char encodePercentageToChar (const double &value) const
 encode % value to 1 character More...
 
double decodeCharToPercentage (const char ch) const
 decode 1 character to the real number [0,1] More...
 
bool encodePosVelToStr5 (const Vector2D &pos, const Vector2D &vel, std::string &to) const
 encode position and velocity to 5 characters. More...
 
bool decodeStr5ToPosVel (const std::string &from, Vector2D *pos, Vector2D *vel) const
 decode 5 characters to position and velocity More...
 
bool encodePosToStr3 (const Vector2D &pos, std::string &to) const
 encode position to 3 characters. More...
 
bool decodeStr3ToPos (const std::string &from, Vector2D *pos) const
 decode 3 characters to and position More...
 
bool encodeUnumPosToStr4 (const int unum, const Vector2D &pos, std::string &to) const
 encode uniform number and position to 4 characters. More...
 
bool decodeStr4ToUnumPos (const std::string &from, int *unum, Vector2D *pos) const
 decode 4 characters to uniform number and position More...
 
std::string encodeCoordToStr2 (const double &xy, const double &norm_factor) const
 encode coordinate value( x or y ) to 2 characters. More...
 
double decodeStr2ToCoord (const char ch1, const char ch2, const double &norm_factor) const
 decode 2 characters to coordinate value( x or y ) More...
 
std::string encodePosToStr4 (const Vector2D &pos) const
 encode position value to 4 characters with 0.1 step More...
 
Vector2D decodeStr4ToPos (const std::string &from) const
 decode 4 characters to position value More...
 
char encodeSpeedToChar (const double &xy) const
 encode speed value to 1 character. More...
 
double decodeCharToSpeed (const char ch) const
 decode 1 character to speed value More...
 

Static Public Member Functions

static AudioCodecinstance ()
 singleton interface More...
 
static const AudioCodeci ()
 singleton interface More...
 
static char unum2hex (const int unum)
 convert decimal uniform number to hex number More...
 
static int hex2unum (const char hex)
 convert hex number character to decimal uniform number. More...
 

Static Public Attributes

static const double ERROR_VALUE
 constant error value (= std::numeric_limits< double >::max())
 

Detailed Description

communication message encoder/decorder

Member Function Documentation

◆ charToIntMap()

const CharToIntCont & rcsc::AudioCodec::charToIntMap ( ) const
inline

get character to interger map object

Returns
const reference to the map object

◆ decodeCharToPercentage()

double rcsc::AudioCodec::decodeCharToPercentage ( const char  ch) const

decode 1 character to the real number [0,1]

Parameters
chcharacter to be decoded
Returns
decoded value [0,1]. if ch is illegal, negative value is returned.

◆ decodeCharToSpeed()

double rcsc::AudioCodec::decodeCharToSpeed ( const char  ch) const

decode 1 character to speed value

Parameters
chcharacter to be decoded
Returns
decoded speed value. if failed to decode, HUGE_VAL is returned

◆ decodeStr2ToCoord()

double rcsc::AudioCodec::decodeStr2ToCoord ( const char  ch1,
const char  ch2,
const double &  norm_factor 
) const

decode 2 characters to coordinate value( x or y )

Parameters
ch1first character to be decoded
ch2second character to be decoded
norm_factornormalize factor for coordinate value

norm_factor must be same as the value used by encodeCoordL2() norm_factor will be changed depending on the type of target coordinate value, i.e. field length or field width.

◆ decodeStr3ToPos()

bool rcsc::AudioCodec::decodeStr3ToPos ( const std::string &  from,
Vector2D pos 
) const

decode 3 characters to and position

Parameters
fromstring to be decoded
pospointer to the result variable
Returns
true if successfully decoded

The length of 'from' must be 3.

◆ decodeStr4ToPos()

Vector2D rcsc::AudioCodec::decodeStr4ToPos ( const std::string &  from) const

decode 4 characters to position value

Parameters
frommessage string to be decoded
Returns
decoded position value

◆ decodeStr4ToUnumPos()

bool rcsc::AudioCodec::decodeStr4ToUnumPos ( const std::string &  from,
int *  unum,
Vector2D pos 
) const

decode 4 characters to uniform number and position

Parameters
fromstring to be decoded
unumpointer to the result variable
pospointer to the result variable
Returns
true if successfully decoded

The length of 'from' must be 4.

◆ decodeStr5ToPosVel()

bool rcsc::AudioCodec::decodeStr5ToPosVel ( const std::string &  from,
Vector2D pos,
Vector2D vel 
) const

decode 5 characters to position and velocity

Parameters
fromstring to be decoded
posvariable pointer to store the decoded position value
velvariable pointer to store the decoded velocity value
Returns
true if successfully decoded

The length of 'from' must be 5.

◆ decodeStrToInt64()

bool rcsc::AudioCodec::decodeStrToInt64 ( const std::string &  from,
std::int64_t *  to 
) const

decode the message string to the decimal (64bit) integer

Parameters
frominput message string
topointer to the result instance
Returns
decode status

◆ encodeCoordToStr2()

std::string rcsc::AudioCodec::encodeCoordToStr2 ( const double &  xy,
const double &  norm_factor 
) const

encode coordinate value( x or y ) to 2 characters.

Parameters
xycoordinate value to be encoded, X or Y. This value should be within [-norm_factor, norm_factor]
norm_factornormalize factor for xy
Returns
result string, or empty string if failed

Following condition must be satisfied:

  • (norm_factor*2)/COORD_STEP_L2 < CHARSIZE^2

norm_factor must be same as the value used by decodeCoordL2() norm_factor will be changed depending on the type of target coordinate value, i.e. field length or field width.

◆ encodeInt64ToStr()

bool rcsc::AudioCodec::encodeInt64ToStr ( const std::int64_t &  ival,
const int  len,
std::string &  to 
) const

encode decimal (64bit) integer to the encoded string.

Parameters
ivalinput value
lendesired string length
toreference to the result instance
Returns
encode status

◆ encodePercentageToChar()

char rcsc::AudioCodec::encodePercentageToChar ( const double &  value) const

encode % value to 1 character

Parameters
valuereal number [0,1]
Returns
encoded character. if value range is illegal, '0' is returned.

◆ encodePosToStr3()

bool rcsc::AudioCodec::encodePosToStr3 ( const Vector2D pos,
std::string &  to 
) const

encode position to 3 characters.

Parameters
posposition value to be encoded
toreference to the result variable
Returns
encode status

The length of result string must be 3.

◆ encodePosToStr4()

std::string rcsc::AudioCodec::encodePosToStr4 ( const Vector2D pos) const

encode position value to 4 characters with 0.1 step

Parameters
posposition value to be encoded
Returns
encoded string instance. if encoding is failed, empty string is returned

◆ encodePosVelToStr5()

bool rcsc::AudioCodec::encodePosVelToStr5 ( const Vector2D pos,
const Vector2D vel,
std::string &  to 
) const

encode position and velocity to 5 characters.

Parameters
posposition value to be encoded
velvelocity value to be encoded
toreference to the result variable
Returns
encode status

The length of result string must be 5.

◆ encodeSpeedToChar()

char rcsc::AudioCodec::encodeSpeedToChar ( const double &  xy) const

encode speed value to 1 character.

Parameters
xyvelocity element to be encoded, X or Y
Returns
result char

speed value is normalized by SPEED_NORM_FACTOR

◆ encodeUnumPosToStr4()

bool rcsc::AudioCodec::encodeUnumPosToStr4 ( const int  unum,
const Vector2D pos,
std::string &  to 
) const

encode uniform number and position to 4 characters.

Parameters
unumuniform number
posposition value to be encoded
toreference to the result variable
Returns
encode status

The length of result string must be 4.

◆ hex2unum()

static int rcsc::AudioCodec::hex2unum ( const char  hex)
static

convert hex number character to decimal uniform number.

Parameters
hexhex number character, that must be within [0, B], case sensitive!
Returns
decimal uniform number, if invalid character is given, 0 is retuned.

◆ i()

static const AudioCodec & rcsc::AudioCodec::i ( )
static

singleton interface

Returns
const reference to the singleton instance

◆ instance()

static AudioCodec & rcsc::AudioCodec::instance ( )
static

singleton interface

Returns
reference to the singleton instance

◆ intToCharMap()

const IntToCharCont & rcsc::AudioCodec::intToCharMap ( ) const
inline

get integer to character map object

Returns
const reference to the map object

◆ unum2hex()

static char rcsc::AudioCodec::unum2hex ( const int  unum)
static

convert decimal uniform number to hex number

Parameters
unumdecimal uniform number, that must be within [1, 11]
Returns
hex number character. if invalid number is given, '0' is returned.

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