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

ArAction.cpp

00001 /*
00002 ActivMedia Robotics Interface for Applications (ARIA)
00003 Copyright (C) 2004,2005 ActivMedia Robotics, LLC
00004 
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 ActivMedia Robotics for information about a commercial version of ARIA at 
00022 robots@activmedia.com or 
00023 ActivMedia Robotics, 19 Columbia Drive, Amherst, NH 03031; 800-639-9481
00024 
00025 */
00026 
00027 #include "ArExport.h"
00028 #include "ariaOSDef.h"
00029 #include "ArResolver.h"
00030 #include "ArAction.h"
00031 #include "ArLog.h"
00032 #include "ArRobot.h"
00033 
00034 ArAction::ArAction(const char *name, const char *description)
00035 {
00036   myRobot = NULL;
00037   myNumArgs = 0;
00038   myName = name;
00039   myDescription = description;
00040   myIsActive = true;
00041 }
00042 
00043 ArAction::~ArAction()
00044 {
00045   if (myRobot != NULL)
00046     myRobot->remAction(this);
00047 }
00048 
00049 const char *ArAction::getName(void) const
00050 {
00051   return myName.c_str();
00052 }
00053 
00054 const char *ArAction::getDescription(void) const
00055 {
00056   return myDescription.c_str();
00057 }
00058 
00059 int ArAction::getNumArgs(void) const
00060 {
00061   return myNumArgs;
00062 }
00063 
00064 void ArAction::setNextArgument(ArArg const &arg)
00065 {
00066   myArgumentMap[myNumArgs] = arg;
00067   myNumArgs++;
00068 }
00069 
00070 ArArg *ArAction::getArg(int number) 
00071 {
00072   std::map<int, ArArg>::iterator it;
00073   
00074   it = myArgumentMap.find(number);
00075   if (it != myArgumentMap.end())
00076     return &(*it).second;
00077   else
00078     return NULL;
00079 }
00080 
00081 const ArArg *ArAction::getArg(int number) const
00082 {
00083   std::map<int, ArArg>::const_iterator it;
00084   
00085   it = myArgumentMap.find(number);
00086   if (it != myArgumentMap.end())
00087     return &(*it).second;
00088   else
00089     return NULL;
00090 }
00091 
00092 void ArAction::setRobot(ArRobot *robot)
00093 {
00094   myRobot = robot;
00095 }
00096 
00097 bool ArAction::isActive(void) const
00098 {
00099   return myIsActive;
00100 }
00101 
00102 void ArAction::activate(void)
00103 {
00104   myIsActive = true;
00105 }
00106 
00107 void ArAction::deactivate(void)
00108 {
00109   myIsActive = false;
00110 }
00111 
00112 void ArAction::log(bool verbose) const
00113 {
00114   int i;
00115   std::string str;
00116   const ArArg *arg;
00117 
00118   ArLog::log(ArLog::Terse, "Action %s isActive %d", getName(), myIsActive);
00119   if (!verbose)
00120     return;
00121   if (strlen(getDescription()) != 0)
00122     ArLog::log(ArLog::Terse, "Action %s is described as: %s", 
00123                getName(), getDescription());
00124   else
00125     ArLog::log(ArLog::Terse, "Action %s has no description.", 
00126                getName());
00127   if (getNumArgs() == 0)
00128     ArLog::log(ArLog::Terse, "Action %s has no arguments.\n", 
00129                getName());
00130   else
00131   {
00132     ArLog::log(ArLog::Terse, "Action %s has %d arguments, of type(s):", 
00133                (getName()), getNumArgs());
00134 
00135     for (i = 0; i < getNumArgs(); i++) 
00136     {
00137       arg = getArg(i);
00138       if (arg == NULL)
00139         continue;
00140       arg->log();
00141     }
00142     ArLog::log(ArLog::Terse, "");
00143   }
00144 }
00145 
00146 
00147 

Generated on Wed Oct 19 12:56:34 2005 for Aria by  doxygen 1.4.0