LIBRCSC Docs
Documentation for HELIOS's BASE LIBRCSC library for RoboCup 2D Simulation League.
All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
free_message.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_FREE_MESSAGE_H
33#define RCSC_PLAYER_FREE_MESSAGE_H
34
37#include <rcsc/common/logger.h>
39
40#include <string>
41#include <iostream>
42
43namespace rcsc {
44
45/*-------------------------------------------------------------------*/
50template < std::size_t LEN >
52 : public SayMessage {
53private:
54
55 std::string M_message;
56
57public:
58
63 FreeMessage( const std::string & msg )
64 {
65 M_message = msg;
66 }
67
72 char header() const
73 {
74 return static_cast< char >( '0' + LEN );
75 }
76
81 int length() const
82 {
83 return LEN + 1;
84 }
85
91 bool toString( std::string & to ) const
92 {
93 if ( static_cast< int >( to.length() + 1 + LEN )
94 > ServerParam::i().playerSayMsgSize() )
95 {
96 std::cerr << __FILE__ << ':' << __LINE__
97 << " FreeMessage: over the capacity. message="
98 << M_message << ". current size = "
99 << to.length()
100 << std::endl;
101 return false;
102 }
103
104 if ( M_message.length() != LEN )
105 {
106 std::cerr << __FILE__ << ':' << __LINE__
107 << " Illegal message length. message="
108 << M_message << " must be length " << LEN
109 << std::endl;
110 return false;
111 }
112
113 to += header();
114 to += M_message;
115 return true;
116 }
117
123 std::ostream & printDebug( std::ostream & os ) const
124 {
125 os << "[Free:" << M_message << ']';
126 return os;
127 }
128
129};
130
131}
132
133#endif
communication message data holder Header File
player's free formed say message encoder
Definition: free_message.h:52
bool toString(std::string &to) const
append the audio message to be sent
Definition: free_message.h:91
FreeMessage(const std::string &msg)
construct with raw message string
Definition: free_message.h:63
char header() const
pure virtual method. get the header character of this message
Definition: free_message.h:72
int length() const
pure virtual method. get the length of this message
Definition: free_message.h:81
std::ostream & printDebug(std::ostream &os) const
append the debug message
Definition: free_message.h:123
abstract player's say message
Definition: say_message.h:46
static const ServerParam & i()
singleton instance interface
Definition: server_param.h:695
Logger class Header File.
player's say message builder Header File
server parametor Header File