free_message.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/player/say_message_builder.h>
00036 #include <rcsc/common/audio_memory.h>
00037 #include <rcsc/common/logger.h>
00038 #include <rcsc/common/server_param.h>
00039 
00040 #include <string>
00041 #include <iostream>
00042 
00043 namespace rcsc {
00044 
00045 /*-------------------------------------------------------------------*/
00050 template < std::size_t LEN >
00051 class FreeMessage
00052     : public SayMessage {
00053 private:
00054 
00055     std::string M_message; 
00056 
00057 public:
00058 
00059     FreeMessage( const std::string & msg )
00060       {
00061           M_message = msg;
00062       }
00063 
00068     char header() const
00069       {
00070           return static_cast< char >( '0' + LEN );
00071       }
00072 
00077     std::size_t length() const
00078       {
00079           return LEN + 1;
00080       }
00081 
00087     bool toStr( std::string & to ) const
00088       {
00089           if ( static_cast< int >( to.length() + 1 + LEN )
00090                > ServerParam::i().playerSayMsgSize() )
00091           {
00092               std::cerr << __FILE__ << ':' << __LINE__
00093                         << " FreeMessage: over the capacity. message="
00094                         << M_message << ". current size = "
00095                         << to.length()
00096                         << std::endl;
00097               return false;
00098           }
00099 
00100           if ( M_message.length() != LEN )
00101           {
00102               std::cerr << __FILE__ << ':' << __LINE__
00103                         << " Illegal message length. message="
00104                         << M_message << " must be length " << LEN
00105                         << std::endl;
00106               return false;
00107           }
00108 
00109           to += header();
00110           to += M_message;
00111           return true;
00112       }
00113 
00114 };
00115 
00116 }
00117 
00118 #endif

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