LIBRCSC Docs
Documentation for HELIOS's BASE LIBRCSC library for RoboCup 2D Simulation League.
All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
audio_codec.h
Go to the documentation of this file.
1// -*-c++-*-
2
8/*
9 *Copyright:
10
11 Copyright (C) Hidehisa AKIYAMA
12
13 This code is free software; you can redistribute it and/or
14 modify it under the terms of the GNU Lesser General Public
15 License as published by the Free Software Foundation; either
16 version 3 of the License, or (at your option) any later version.
17
18 This library is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 Lesser General Public License for more details.
22
23 You should have received a copy of the GNU Lesser General Public
24 License along with this library; if not, write to the Free Software
25 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26
27 *EndCopyright:
28 */
29
31
32#ifndef RCSC_PLAYER_AUDIO_CODEC_H
33#define RCSC_PLAYER_AUDIO_CODEC_H
34
35#include <rcsc/geom/vector_2d.h>
36
37#include <unordered_map>
38#include <vector>
39#include <string>
40#include <cmath>
41#include <cstdint>
42
43namespace rcsc {
44
50public:
51 typedef std::unordered_map< char, int > CharToIntCont;
52 typedef std::vector< char > IntToCharCont;
53
55 static const double ERROR_VALUE;
56
57private:
58
59 std::string M_char_set;
60
62 CharToIntCont M_char_to_int_map;
63
65 IntToCharCont M_int_to_char_map;
66
70 AudioCodec();
71
72public:
73
78 static AudioCodec & instance();
79
84 static const AudioCodec & i();
85
86 void createMap( const int shift );
87
88private:
89
95 std::int32_t posToBit18( const Vector2D & pos ) const;
96
102 void bit18ToPos( const std::int32_t & val,
103 Vector2D * pos ) const;
104
110 std::int32_t posToBit19( const Vector2D & pos ) const;
111
117 void bit19ToPos( const std::int32_t & val,
118 Vector2D * pos ) const;
119
126 std::int32_t posVelToBit31( const Vector2D & pos,
127 const Vector2D & vel ) const;
128
135 void bit31ToPosVel( const std::int32_t & val,
136 Vector2D * pos,
137 Vector2D * vel ) const;
138
139public:
140
146 {
147 return M_char_to_int_map;
148 }
149
155 {
156 return M_int_to_char_map;
157 }
158
166 bool encodeInt64ToStr( const std::int64_t & ival,
167 const int len,
168 std::string & to ) const;
169
176 bool decodeStrToInt64( const std::string & from,
177 std::int64_t * to ) const;
178
179
186 char encodePercentageToChar( const double & value ) const;
187
194 double decodeCharToPercentage( const char ch ) const;
195
205 bool encodePosVelToStr5( const Vector2D & pos,
206 const Vector2D & vel,
207 std::string & to ) const;
208
218 bool decodeStr5ToPosVel( const std::string & from,
219 Vector2D * pos,
220 Vector2D * vel ) const;
221
230 bool encodePosToStr3( const Vector2D & pos,
231 std::string & to ) const;
232
241 bool decodeStr3ToPos( const std::string & from,
242 Vector2D * pos ) const;
243
244
254 bool encodeUnumPosToStr4( const int unum,
255 const Vector2D & pos,
256 std::string & to ) const;
257
267 bool decodeStr4ToUnumPos( const std::string & from,
268 int * unum,
269 Vector2D * pos ) const;
270
285 std::string encodeCoordToStr2( const double & xy,
286 const double & norm_factor ) const;
287
298 double decodeStr2ToCoord( const char ch1,
299 const char ch2,
300 const double & norm_factor ) const;
301
308 std::string encodePosToStr4( const Vector2D & pos ) const;
309
315 Vector2D decodeStr4ToPos( const std::string & from ) const;
316
324 char encodeSpeedToChar( const double & xy ) const;
325
331 double decodeCharToSpeed( const char ch ) const;
332
338 static
339 char unum2hex( const int unum );
340
341
347 static
348 int hex2unum( const char hex );
349};
350
351}
352
353#endif
communication message encoder/decorder
Definition: audio_codec.h:49
static const double ERROR_VALUE
constant error value (= std::numeric_limits< double >::max())
Definition: audio_codec.h:55
std::vector< char > IntToCharCont
map from int to char
Definition: audio_codec.h:52
static char unum2hex(const int unum)
convert decimal uniform number to hex number
bool encodePosToStr3(const Vector2D &pos, std::string &to) const
encode position to 3 characters.
static AudioCodec & instance()
singleton interface
static int hex2unum(const char hex)
convert hex number character to decimal uniform number.
static const AudioCodec & i()
singleton interface
bool encodePosVelToStr5(const Vector2D &pos, const Vector2D &vel, std::string &to) const
encode position and velocity to 5 characters.
bool decodeStrToInt64(const std::string &from, std::int64_t *to) const
decode the message string to the decimal (64bit) integer
bool encodeInt64ToStr(const std::int64_t &ival, const int len, std::string &to) const
encode decimal (64bit) integer to the encoded string.
std::string encodeCoordToStr2(const double &xy, const double &norm_factor) const
encode coordinate value( x or y ) to 2 characters.
const IntToCharCont & intToCharMap() const
get integer to character map object
Definition: audio_codec.h:154
double decodeStr2ToCoord(const char ch1, const char ch2, const double &norm_factor) const
decode 2 characters to coordinate value( x or y )
std::string encodePosToStr4(const Vector2D &pos) const
encode position value to 4 characters with 0.1 step
double decodeCharToPercentage(const char ch) const
decode 1 character to the real number [0,1]
bool encodeUnumPosToStr4(const int unum, const Vector2D &pos, std::string &to) const
encode uniform number and position to 4 characters.
std::unordered_map< char, int > CharToIntCont
map from char to int
Definition: audio_codec.h:51
Vector2D decodeStr4ToPos(const std::string &from) const
decode 4 characters to position value
bool decodeStr4ToUnumPos(const std::string &from, int *unum, Vector2D *pos) const
decode 4 characters to uniform number and position
const CharToIntCont & charToIntMap() const
get character to interger map object
Definition: audio_codec.h:145
double decodeCharToSpeed(const char ch) const
decode 1 character to speed value
char encodeSpeedToChar(const double &xy) const
encode speed value to 1 character.
bool decodeStr5ToPosVel(const std::string &from, Vector2D *pos, Vector2D *vel) const
decode 5 characters to position and velocity
bool decodeStr3ToPos(const std::string &from, Vector2D *pos) const
decode 3 characters to and position
char encodePercentageToChar(const double &value) const
encode % value to 1 character
2D point vector class
Definition: vector_2d.h:46
2d vector class Header File.