- Main Page
- Namespaces
- Classes
- Files
- Related Pages

# /Users/fpy/titan-1-5-MBARI/Mers/Interfaces/Task.cpp

    00001
    00002 //
    00003 // Copyright (c) 2004           Model-based Embedded and Robotic Systems Group
    00004 // All Rights Reserved          Massachusetts Institute of Technology
    00005 //
    00006 // This software is provided as is. Model-based Embedded and Robotic Systems
    00007 // (MERS) group does not assume any responsibility.
    00008 //
    00009 // Organization:        Model-based Embedded and Robotic Systems Group
    00010 //                                      Massachusetts Institute of Technology
    00011 //
    00013
    00014 #include "Task.h"
    00015
    00016 // contains CharUtils::strdupnew()
    00017 //#include <Mers/Utils/Lang/CharUtils.h>
    00018
    00019 using namespace Mers::Interfaces;
    00020 using Mers::Utils::Lang::String;
    00021 //using Mers::Utils::Lang::CharUtils;
    00022 using std::vector;
    00023 using std::cerr;
    00024 using std::endl;
    00025
    00027
    00028 Task::Task( const String &taskName )
    00029   : mName(), mParameters(), mControllable(true)
    00030 {
    00031   // copy task name ( no parameters )
    00032   mName = taskName;
    00033 }
    00034
    00035
    00037
    00038 Task::Task( const String &taskName,
    00039             vector< const String * > const &parameters )
    00040   : mName(), mParameters(), mControllable(true)
    00041 {
    00042   // copy task name
    00043   mName = taskName;
    00044
    00045   // copy parameters
    00046   for( unsigned int i = 0; i < parameters.size(); i++ )
    00047     mParameters.push_back( new String(*(parameters[i])) );
    00048 }
    00049
    00051
    00052 Task::Task( Task const &other )
    00053   : mName(), mParameters()
    00054 {
    00055   *this  = other;
    00056 }
    00057
    00059
    00060 Task& Task::operator=( Task const &other )
    00061 {
    00062   // copy name
    00063   mName = other.mName;
    00064
    00065   mControllable = other.mControllable;
    00066
    00067   // copy parameters
    00068   mParameters.clear();
    00069   for( unsigned int i = 0; i < other.mParameters.size(); i++ )
    00070     mParameters.push_back( new String(*(other.mParameters[i])) );
    00071
    00072
    00073   return *this;
    00074 }
    00075
    00077
    00078 Task::~Task()
    00079 {
    00080         // Delete the parameters
    00081         for( unsigned int i = 0; i < mParameters.size(); ++i )
    00082                 delete mParameters[i];
    00083   mParameters.clear();
    00084 }
    00085
    00087
    00088 const String &Task::getName() const
    00089 {
    00090   return mName;
    00091 }
    00092
    00094
    00095 vector< const String * > const & Task::getParameters() const
    00096 {
    00097   return mParameters;
    00098 }
    00099
    00101
    00102 String Task::toString() const
    00103 {
    00104   // Note that we could create this once and store it since our values
    00105   // don't change.
    00106   String result;
    00107
    00108   result = mName + "(";
    00109   for( unsigned int i = 0; i < mParameters.size(); i++ )
    00110   {
    00111     if( i != 0 )
    00112     {
    00113       result += ", ";
    00114     }
    00115     result += *(mParameters[i]);
    00116   }
    00117   result += ")";
    00118   return result;
    00119 }
    00120
    00122
    00123 bool Task::operator==( Task const & task )
    00124 {
    00125         if (mName == task.mName)
    00126         {
    00127                 int parameterLength1 = mParameters.size();
    00128                 int parameterLength2 = task.mParameters.size();
    00129
    00130                 if (parameterLength1 == parameterLength2)
    00131                 {
    00132                         if (parameterLength1 == 0 && parameterLength2 == 0)
    00133                         {
    00134                                 return true;
    00135                         }
    00136                         else
    00137                         {
    00138                                 vector< const Mers::Utils::Lang::String * >::const_iterator it1 =
    00139                                         mParameters.begin();
    00140                                 vector< const Mers::Utils::Lang::String * >::const_iterator it2 =
    00141                                         task.mParameters.begin();
    00142                                 while (it1 != mParameters.end())
    00143                                 {
    00144                                         if (**it1 != **it2)
    00145                                         {
    00146                                                 return false;
    00147                                         }
    00148                                         it1++;
    00149                                         it2++;
    00150                                 }
    00151                                 return true;
    00152                         }
    00153                 }
    00154                 else
    00155                 {
    00156                         return false;
    00157                 }
    00158         }
    00159         else
    00160         {
    00161                 return false;
    00162         }
    00163
    00164 }
    00165
    00166
    00168
    00169 Task::Task()
    00170   : mName("?"), mParameters()
    00171 {
    00172 }
    00173
    00175
    00176 bool
    00177 Task::isControllable()
    00178 {
    00179   return mControllable;
    00180 }
    00181
    00182
    00183 void
    00184 Task::setControllable( bool value )
    00185 {
    00186   mControllable = value;
    00187 }