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_parser.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_COMMON_FREE_MESSAGE_PARSER_H
33#define RCSC_COMMON_FREE_MESSAGE_PARSER_H
34
37
38#include <string>
39#include <iostream>
40#include <cstring>
41
42namespace rcsc {
43
44/*-------------------------------------------------------------------*/
49template < std::size_t LEN >
51 : public SayMessageParser {
52private:
54 std::shared_ptr< AudioMemory > M_memory;
55
56 // not used
57 FreeMessageParser() = delete;
58
59public:
60
65 explicit
66 FreeMessageParser( std::shared_ptr< AudioMemory > memory )
67 : M_memory( memory )
68 { }
69
74 char header() const
75 {
76 return static_cast< char >( '0' + LEN );
77 }
78
88 int parse( const int unum,
89 const double & /* dir */,
90 const char * msg,
91 const GameTime & current )
92 {
93 if ( *msg != header() ) return 0;
94 ++msg;
95 if ( std::strlen( msg ) < LEN )
96 {
97 std::cerr << __FILE__ << ':' << __LINE__
98 << " FreeMessageParser: Illegal message length. message="
99 << msg << " must be length " << LEN
100 << std::endl;
101 return -1;
102 }
103
104 M_memory->setFreeMessage( unum,
105 std::string( msg, 0, LEN ),
106 current );
107 return 1 + LEN;
108 }
109
110};
111
112}
113
114#endif
communication message data holder Header File
player's freeform say message parser
Definition: free_message_parser.h:51
int parse(const int unum, const double &, const char *msg, const GameTime &current)
virtual method which analyzes audio messages.
Definition: free_message_parser.h:88
char header() const
get the header character.
Definition: free_message_parser.h:74
FreeMessageParser(std::shared_ptr< AudioMemory > memory)
construct with audio memory
Definition: free_message_parser.h:66
game time object
Definition: game_time.h:43
abstract player's say message parser
Definition: say_message_parser.h:50
player's say message parser Header File