00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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