Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

soccermonitor.cpp

Go to the documentation of this file.
00001 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*-
00002 
00003    this file is part of rcssserver3D
00004    Fri May 9 2003
00005    Copyright (C) 2002,2003 Koblenz University
00006    Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group
00007    $Id: soccermonitor.cpp,v 1.2 2004/12/30 15:56:22 rollmark Exp $
00008 
00009    This program is free software; you can redistribute it and/or modify
00010    it under the terms of the GNU General Public License as published by
00011    the Free Software Foundation; version 2 of the License.
00012 
00013    This program is distributed in the hope that it will be useful,
00014    but WITHOUT ANY WARRANTY; without even the implied warranty of
00015    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016    GNU General Public License for more details.
00017 
00018    You should have received a copy of the GNU General Public License
00019    along with this program; if not, write to the Free Software
00020    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00021 */
00022 #include "soccermonitor.h"
00023 
00024 using namespace zeitgeist;
00025 using namespace oxygen;
00026 using namespace std;
00027 
00028 SoccerMonitor::SoccerMonitor() : CustomMonitor()
00029 {
00030     mTime     = 0.0;
00031     mPlayMode = PM_NONE;
00032     mHalf     = 0;
00033 
00034     SetupPredicateMap();
00035 }
00036 
00037 SoccerMonitor::~SoccerMonitor()
00038 {
00039 }
00040 
00041 void SoccerMonitor::ParseCustomPredicates(const PredicateList& pList)
00042 {
00043     ParsePredicates(pList);
00044 }
00045 
00046 void SoccerMonitor::ParsePredicates(const PredicateList& pList)
00047 {
00048     for (
00049          PredicateList::TList::const_iterator iter = pList.begin();
00050          iter != pList.end();
00051          ++iter
00052          )
00053         {
00054             const Predicate& pred = (*iter);
00055             TPredicateMap::const_iterator pIter = mPredMap.find(pred.name);
00056             if (pIter == mPredMap.end())
00057                 {
00058                     continue;
00059                 }
00060 
00061             const EPredicate& type = (*pIter).second;
00062             switch (type)
00063                 {
00064                 case P_PLAYMODES:
00065                     ParsePlayModes(pred);
00066                     break;
00067 
00068                 case P_TIME:
00069                     if (pred.parameter.GetSize() == 1)
00070                         {
00071                             pred.GetValue(pred.begin(),mTime);
00072                         }
00073                     break;
00074 
00075                 case P_PLAYMODE:
00076                     if (pred.parameter.GetSize() == 1)
00077                         {
00078                             pred.GetValue(pred.begin(),mPlayMode);
00079                         }
00080                     break;
00081 
00082                 case P_HALF:
00083                     if (pred.parameter.GetSize() == 1)
00084                         {
00085                             pred.GetValue(pred.begin(),mHalf);
00086                         }
00087                     break;
00088 
00089                 default:
00090                     break;
00091                 }
00092         }
00093 }
00094 
00095 void SoccerMonitor::ParsePlayModes(const Predicate& pred)
00096 {
00097     mPlayModes.clear();
00098 
00099     const ParameterList& paramList = pred.parameter;
00100     ParameterList::TVector::const_iterator pIter = paramList.begin();
00101 
00102     std::string pMode;
00103     while (
00104            (pIter != paramList.end()) &&
00105            (paramList.AdvanceValue(pIter, pMode))
00106            )
00107         {
00108             mPlayModes.push_back(pMode);
00109         }
00110 }
00111 
00112 void SoccerMonitor::SetupPredicateMap()
00113 {
00114     mPredMap.clear();
00115     mPredMap["play_modes"] = P_PLAYMODES;
00116     mPredMap["time"]       = P_TIME;
00117     mPredMap["play_mode"]  = P_PLAYMODE;
00118     mPredMap["half"]       = P_HALF;
00119 }
00120 
00121 TTime SoccerMonitor::GetTime() const
00122 {
00123     return static_cast<TTime>(mTime);
00124 }
00125 
00126 TPlayMode SoccerMonitor::GetPlayMode() const
00127 {
00128     return static_cast<TPlayMode>(mPlayMode);
00129 }
00130 
00131 string SoccerMonitor::GetPlayModeString() const
00132 {
00133     if (
00134         (mPlayMode < 0) ||
00135         (mPlayMode >= mPlayModes.size())
00136         )
00137         {
00138             return "playmode_unknown";
00139         }
00140 
00141     return mPlayModes[mPlayMode];
00142 }
00143 
00144 TGameHalf SoccerMonitor::GetGameHalf() const
00145 {
00146     return static_cast<TGameHalf>(mHalf);
00147 }
00148 
00149 string SoccerMonitor::GetGameHalfString() const
00150 {
00151     switch (mHalf)
00152         {
00153         default:
00154             return "unknown half";
00155 
00156         case 1:
00157             return "first half";
00158 
00159         case 2:
00160             return "second half";
00161         }
00162 }

Generated on Thu Apr 6 15:25:40 2006 for rcssserver3d by  doxygen 1.4.4