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

ArAction.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 "ArResolver.h"
00029 #include "ArAction.h"
00030 #include "ArLog.h"
00031 #include "ArRobot.h"
00032 
00033 AREXPORT ArAction::ArAction(const char *name, const char *description)
00034 {
00035   myRobot = NULL;
00036   myNumArgs = 0;
00037   myName = name;
00038   myDescription = description;
00039   myIsActive = true;
00040 }
00041 
00042 AREXPORT ArAction::~ArAction()
00043 {
00044   if (myRobot != NULL)
00045     myRobot->remAction(this);
00046 }
00047 
00048 AREXPORT const char *ArAction::getName(void) const
00049 {
00050   return myName.c_str();
00051 }
00052 
00053 AREXPORT const char *ArAction::getDescription(void) const
00054 {
00055   return myDescription.c_str();
00056 }
00057 
00058 AREXPORT int ArAction::getNumArgs(void) const
00059 {
00060   return myNumArgs;
00061 }
00062 
00063 AREXPORT void ArAction::setNextArgument(ArArg const &arg)
00064 {
00065   myArgumentMap[myNumArgs] = arg;
00066   myNumArgs++;
00067 }
00068 
00069 AREXPORT ArArg *ArAction::getArg(int number) 
00070 {
00071   std::map<int, ArArg>::iterator it;
00072   
00073   it = myArgumentMap.find(number);
00074   if (it != myArgumentMap.end())
00075     return &(*it).second;
00076   else
00077     return NULL;
00078 }
00079 
00080 AREXPORT const ArArg *ArAction::getArg(int number) const
00081 {
00082   std::map<int, ArArg>::const_iterator it;
00083   
00084   it = myArgumentMap.find(number);
00085   if (it != myArgumentMap.end())
00086     return &(*it).second;
00087   else
00088     return NULL;
00089 }
00090 
00097 AREXPORT void ArAction::setRobot(ArRobot *robot)
00098 {
00099   myRobot = robot;
00100 }
00101 
00102 AREXPORT bool ArAction::isActive(void) const
00103 {
00104   return myIsActive;
00105 }
00106 
00107 AREXPORT void ArAction::activate(void)
00108 {
00109   myIsActive = true;
00110 }
00111 
00112 AREXPORT void ArAction::deactivate(void)
00113 {
00114   myIsActive = false;
00115 }
00116 
00117 AREXPORT void ArAction::log(bool verbose) const
00118 {
00119   int i;
00120   std::string str;
00121   const ArArg *arg;
00122   const ArActionDesired *desired;
00123 
00124   ArLog::log(ArLog::Terse, "Action %s isActive %d", getName(), myIsActive);
00125   if (myIsActive && (desired = getDesired()) != NULL)
00126     desired->log();
00127   if (!verbose)
00128     return;
00129   if (strlen(getDescription()) != 0)
00130     ArLog::log(ArLog::Terse, "Action %s is described as: %s", 
00131            getName(), getDescription());
00132   else
00133     ArLog::log(ArLog::Terse, "Action %s has no description.", 
00134            getName());
00135   if (getNumArgs() == 0)
00136     ArLog::log(ArLog::Terse, "Action %s has no arguments.\n", 
00137            getName());
00138   else
00139   {
00140     ArLog::log(ArLog::Terse, "Action %s has %d arguments, of type(s):", 
00141            (getName()), getNumArgs());
00142 
00143     for (i = 0; i < getNumArgs(); i++) 
00144     {
00145       arg = getArg(i);
00146       if (arg == NULL)
00147     continue;
00148       arg->log();
00149     }
00150     ArLog::log(ArLog::Terse, "");
00151   }
00152 }
00153 
00154 
00155 

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