soccer_intention.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_SOCCER_INTENTION_H
00033 #define RCSC_PLAYER_SOCCER_INTENTION_H
00034 
00035 #include <boost/shared_ptr.hpp>
00036 
00037 #include <string>
00038 #include <queue>
00039 
00040 namespace rcsc {
00041 
00042 class PlayerAgent;
00043 
00048 class SoccerIntention {
00049 private:
00051     SoccerIntention( const SoccerIntention & );
00053     SoccerIntention & operator=( const SoccerIntention & );
00054 
00055 protected:
00059     SoccerIntention()
00060       { }
00061 
00062 public:
00066     virtual
00067     ~SoccerIntention()
00068       { }
00069 
00071 
00072     // virtual functions
00073 
00078     virtual
00079     bool finished( const PlayerAgent * agent ) = 0;
00080 
00085     virtual
00086     bool execute( PlayerAgent * agent ) = 0;
00087 };
00088 
00090 
00095 class SoccerIntentionQueue
00096     : public SoccerIntention {
00097 private:
00098 
00099     typedef boost::shared_ptr< SoccerIntention > IntentionPtr;
00100 
00101 
00103     std::queue< IntentionPtr >  M_internal_q;
00104 
00105 public:
00106 
00111     bool finished( const PlayerAgent * agent )
00112       {
00113           while ( ! M_internal_q.empty()
00114                   && M_internal_q.front()->finished( agent ) )
00115           {
00116               M_internal_q.pop();
00117           }
00118 
00119           if ( M_internal_q.empty() )
00120           {
00121               return true;
00122           }
00123           return false;
00124       }
00125 
00130     bool execute( PlayerAgent * agent )
00131       {
00132           return pop( agent );
00133       }
00134 
00139     void push( IntentionPtr intention )
00140       {
00141           M_internal_q.push( intention );
00142       }
00143 
00150     bool pop( PlayerAgent * agent )
00151       {
00152           while ( ! M_internal_q.empty()
00153                   && M_internal_q.front()->finished( agent ) )
00154           {
00155               M_internal_q.pop();
00156           }
00157 
00158           if ( M_internal_q.empty() )
00159           {
00160               return false;
00161           }
00162 
00163           return M_internal_q.front()->execute( agent );
00164       }
00165 
00169     void clear()
00170       {
00171           while ( ! M_internal_q.empty() )
00172           {
00173               M_internal_q.pop();
00174           }
00175       }
00176 };
00177 
00178 }
00179 
00180 #endif

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