free_message_parser.h

説明を見る。
00001 // -*-c++-*-
00002 
00008 /*
00009  *Copyright:
00010 
00011  Copyright (C) Hidehisa AKIYAMA
00012 
00013  This code is free software; you can redistribute it and/or
00014  modify it under the terms of the GNU Lesser General Public
00015  License as published by the Free Software Foundation; either
00016  version 2.1 of the License, or (at your option) any later version.
00017 
00018  This library is distributed in the hope that it will be useful,
00019  but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00021  Lesser General Public License for more details.
00022 
00023  You should have received a copy of the GNU Lesser General Public
00024  License along with this library; if not, write to the Free Software
00025  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00026 
00027  *EndCopyright:
00028  */
00029 
00031 
00032 #ifndef RCSC_PLAYER_FREE_MESSAGE_H
00033 #define RCSC_PLAYER_FREE_MESSAGE_H
00034 
00035 #include <rcsc/common/say_message_parser.h>
00036 #include <rcsc/common/audio_memory.h>
00037 
00038 #include <string>
00039 #include <iostream>
00040 
00041 namespace rcsc {
00042 
00043 /*-------------------------------------------------------------------*/
00048 template < std::size_t LEN >
00049 class FreeMessageParser
00050     : public SayMessageParser {
00051 private:
00053     boost::shared_ptr< AudioMemory > M_memory;
00054 
00055 public:
00056 
00061     explicit
00062     FreeMessageParser( boost::shared_ptr< AudioMemory > memory )
00063         : M_memory( memory )
00064       { }
00065 
00070     char header() const
00071       {
00072           return static_cast< char >( '0' + LEN );
00073       }
00074 
00085     int parse( const int unum,
00086                const double & dir,
00087                const char * msg,
00088                const GameTime & current )
00089       {
00090           if ( *msg != header() ) return 0;
00091           ++msg;
00092           if ( std::strlen( msg ) < LEN )
00093           {
00094               std::cerr << __FILE__ << ':' << __LINE__
00095                         << " FreeMessageParser: Illegal message length. message="
00096                         << msg << " must be length " << LEN
00097                         << std::endl;
00098               return -1;
00099           }
00100 
00101           M_memory->setFreeMessage( unum,
00102                                     std::string( msg, 0, LEN ),
00103                                     current );
00104           return 1 + LEN;
00105       }
00106 
00107 };
00108 
00109 }
00110 
00111 #endif

librcscに対してThu May 1 15:41:20 2008に生成されました。  doxygen 1.5.0