Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages | Examples

ArActionGroup.cpp

00001 /*
00002 MobileRobots Advanced Robotics Interface for Applications (ARIA)
00003 Copyright (C) 2004, 2005 ActivMedia Robotics LLC
00004 Copyright (C) 2006, 2007 MobileRobots Inc.
00005 
00006      This program is free software; you can redistribute it and/or modify
00007      it under the terms of the GNU General Public License as published by
00008      the Free Software Foundation; either version 2 of the License, or
00009      (at your option) any later version.
00010 
00011      This program is distributed in the hope that it will be useful,
00012      but WITHOUT ANY WARRANTY; without even the implied warranty of
00013      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014      GNU General Public License for more details.
00015 
00016      You should have received a copy of the GNU General Public License
00017      along with this program; if not, write to the Free Software
00018      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 
00020 If you wish to redistribute ARIA under different terms, contact 
00021 MobileRobots for information about a commercial version of ARIA at 
00022 robots@mobilerobots.com or 
00023 MobileRobots Inc, 19 Columbia Drive, Amherst, NH 03031; 800-639-9481
00024 */
00025 
00026 #include "ArExport.h"
00027 #include "ariaOSDef.h"
00028 #include "ArActionGroup.h"
00029 #include "ArAction.h"
00030 #include "ArRobot.h"
00031 #include "ArLog.h"
00032 
00037 AREXPORT ArActionGroup::ArActionGroup(ArRobot *robot)
00038 {
00039   myRobot = robot;
00040 }
00041 
00042 AREXPORT ArActionGroup::~ArActionGroup()
00043 {
00044   removeActions();
00045 }
00046 
00047 
00056 AREXPORT void ArActionGroup::addAction(ArAction *action, int priority)
00057 {
00058   if (myRobot == NULL)
00059   {
00060     ArLog::log(ArLog::Terse, 
00061             "ArActionGroup::addAction: NULL robot pointer... failed.");
00062     return;
00063   }
00064   myActions.push_front(action);
00065   myRobot->addAction(action, priority);
00066 }
00067 
00072 AREXPORT void ArActionGroup::remAction(ArAction *action)
00073 {
00074   if (myRobot == NULL)
00075   {
00076     ArLog::log(ArLog::Terse, 
00077             "ArActionGroup::remAction: NULL robot pointer... failed.");
00078     return;
00079   }
00080   myActions.remove(action);
00081   myRobot->remAction(action);
00082 }
00083 
00084 AREXPORT void ArActionGroup::activate(void)
00085 {
00086   std::list<ArAction *>::iterator it;
00087   if (myRobot == NULL)
00088   {
00089     ArLog::log(ArLog::Terse, 
00090             "ArActionGroup::activate: NULL robot pointer... failed.");
00091     return;
00092   }
00093   for (it = myActions.begin(); it != myActions.end(); it++)
00094     (*it)->activate();
00095 }
00096 
00097 AREXPORT void ArActionGroup::activateExclusive(void)
00098 {
00099   std::list<ArAction *>::iterator it;
00100   
00101   if (myRobot == NULL)
00102   {
00103     ArLog::log(ArLog::Terse, 
00104             "ArActionGroup::activateExclusive: NULL robot pointer... failed.");
00105     return;
00106   }
00107   myRobot->deactivateActions();
00108   for (it = myActions.begin(); it != myActions.end(); it++)
00109     (*it)->activate();
00110 }
00111 
00112 AREXPORT void ArActionGroup::deactivate(void)
00113 {
00114   std::list<ArAction *>::iterator it;
00115   if (myRobot == NULL)
00116   {
00117     ArLog::log(ArLog::Terse, 
00118             "ArActionGroup::deactivate: NULL robot pointer... failed.");
00119     return;
00120   }
00121   myRobot->deactivateActions();
00122   for (it = myActions.begin(); it != myActions.end(); it++)
00123     (*it)->deactivate();
00124 }
00125 
00126 AREXPORT std::list<ArAction *> *ArActionGroup::getActionList(void)
00127 {
00128   return &myActions;
00129 }
00130 
00131 AREXPORT void ArActionGroup::removeActions(void)
00132 {
00133   std::list<ArAction *>::iterator it;
00134 
00135   if (myRobot == NULL)
00136   {
00137     ArLog::log(ArLog::Terse, 
00138             "ArActionGroup::removeActions: NULL robot pointer... very bad.");
00139     return;
00140   }
00141 
00142   for (it = myActions.begin(); it != myActions.end(); ++it)
00143     myRobot->remAction((*it));
00144 }
00145 
00146 AREXPORT void ArActionGroup::deleteActions(void)
00147 {
00148   /* MPL removed this since it doesn't differentiate between actions it added and actions added to it, double deletes are no fun
00149    */
00150   /*
00151   std::list<ArAction *>::iterator it;
00152   for (it = myActions.begin(); it != myActions.end(); ++it)
00153   {
00154     delete (*it);
00155   }
00156   */
00157 }

Generated on Tue Feb 20 10:51:38 2007 for Aria by  doxygen 1.4.0