00001
00002
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
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
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