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 #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