00001 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- 00002 00003 this file is part of the trainer for rcssserver3D 00004 Fri May 9 2003 00005 Copyright (C) 2002,2003 Koblenz University 00006 Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group 00007 00008 This program is free software; you can redistribute it and/or modify 00009 it under the terms of the GNU General Public License as published by 00010 the Free Software Foundation; version 2 of the License. 00011 00012 This program is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with this program; if not, write to the Free Software 00019 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00020 00021 Parser that gets a list of predicates and interprets the trainer 00022 commands contained in them 00023 00024 */ 00025 #ifndef TRAINERCOMMANDPARSER_H 00026 #define TRAINERCOMMANDPARSER_H 00027 00028 #include <string> 00029 #include <oxygen/monitorserver/monitorcmdparser.h> 00030 #include <oxygen/gamecontrolserver/predicate.h> 00031 #include <oxygen/gamecontrolserver/baseparser.h> 00032 #include <salt/vector.h> 00033 #include <soccer/soccertypes.h> 00034 #include <soccer/soccerruleaspect/soccerruleaspect.h> 00035 00036 class TrainerCommandParser : public oxygen::MonitorCmdParser 00037 { 00038 public: 00039 00040 enum ECommandType 00041 { 00042 CT_PLAYER, 00043 CT_BALL, 00044 CT_PLAYMODE, 00045 CT_DROP_BALL, 00046 CT_KICK_OFF, 00047 CT_ACK 00048 }; 00049 00050 typedef std::map<std::string, ECommandType> TCommandMap; 00051 typedef std::map<std::string, TTeamIndex> TTeamIndexMap; 00052 00053 // mapping from string to TPlayMode 00054 typedef std::map<std::string, TPlayMode> TPlayModeMap; 00055 00056 public: 00057 TrainerCommandParser(); 00058 00059 virtual ~TrainerCommandParser(); 00060 00061 bool SendAck(std::string &reply); 00062 00067 virtual void ParseMonitorMessage(const std::string& data); 00068 00069 virtual void OnLink(); 00070 00071 virtual void OnUnlink(); 00072 00073 protected: 00076 void ParsePredicates(oxygen::PredicateList& predList); 00077 00082 bool ParsePredicate(const oxygen::Predicate & predicate); 00083 00087 void ParsePlayerCommand(const oxygen::Predicate & predicate); 00088 00092 void ParseBallCommand(const oxygen::Predicate & predicate); 00093 00097 void ParsePlayModeCommand(const oxygen::Predicate & predicate); 00098 00102 void ParseKickOffCommand(const oxygen::Predicate & predicate); 00103 00104 protected: 00105 TCommandMap mCommandMap; 00106 00107 TTeamIndexMap mTeamIndexMap; 00108 00109 TPlayModeMap mPlayModeMap; 00110 00112 boost::shared_ptr<GameStateAspect> mGameState; 00114 boost::shared_ptr<SoccerRuleAspect> mSoccerRule; 00116 boost::shared_ptr<oxygen::BaseParser> mSexpParser; 00117 00118 bool mGetAck; 00119 std::string mAckString; 00120 }; 00121 00122 DECLARE_CLASS(TrainerCommandParser); 00123 00124 #endif // TRAINERCOMMANDPARSER_H