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

# /Users/fpy/titan-1-5-MBARI/Mers/Executives/DeductiveController/TaskFactory.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 "TaskFactory.h"
    00015
    00016 #include <Mers/Models/Base/BaseModel.h>
    00017 #include <Mers/Models/Base/BaseModelVariable.h>
    00018 #include <Mers/Models/Base/BaseModelVariableArray.h>
    00019 #include <Mers/Models/Base/BaseModelValue.h>
    00020 #include <Mers/Models/Base/BaseModelDomain.h>
    00021 #include <Mers/Utils/Lang/CharUtils.h>
    00022
    00024
    00025 using namespace Mers::Executives::DeductiveController;
    00026 using Mers::Models::Base::BaseModel;
    00027 using Mers::Models::Base::BaseModelVariable;
    00028 using Mers::Models::Base::BaseModelVariableArray;
    00029 using Mers::Models::Base::BaseModelValue;
    00030 using Mers::Models::Base::BaseModelDomain;
    00031 using Mers::Utils::Lang::String;
    00032 using std::vector;
    00033
    00035
    00036 TaskFactory::TaskFactory(BaseModel * model)
    00037         : Mers::Interfaces::StaticTaskFactory()
    00038 {
    00039         BaseModelVariableArray &vars = *model->getVariables();
    00040
    00041         // Count the number of assignments.
    00042         for(unsigned int i = 0; i < vars.getLength(); ++i) {
    00043                 BaseModelVariable * var = vars[i];
    00044
    00045                 m_NumTasks += var->getDomain()->getLength();
    00046         }
    00047
    00048         m_Tasks = new t_TaskSharedPointer [m_NumTasks];
    00049
    00050         // Create all of our tasks.
    00051         unsigned int index = 0;
    00052         for(unsigned int i = 0; i < vars.getLength(); ++i) {
    00053                 BaseModelVariable * var = vars[i];
    00054                 BaseModelDomain &dom = *var->getDomain();
    00055
    00056                 for(unsigned int j = 0; j < dom.getLength(); ++j, ++index) {
    00057                         BaseModelValue * val = dom[j];
    00058                         m_Tasks[index] = t_DCTaskSharedPointer(new t_DCTask(var, val));
    00059                 }
    00060         }
    00061 }
    00062
    00064
    00065 TaskFactory::~TaskFactory()
    00066 {
    00067 }
    00068
    00070
    00071 TaskFactory::t_TaskSharedPointer
    00072 TaskFactory::createTask( const TaskFactory::t_TaskName taskName )
    00073 {
    00074         (void) taskName;
    00075         // All of our tasks have exactly one parameter.
    00076         return t_TaskSharedPointer();
    00077 }
    00078
    00080
    00081 TaskFactory::t_TaskSharedPointer
    00082 TaskFactory::createTask( const TaskFactory::t_TaskName taskName,
    00083         vector<const TaskFactory::t_TaskParameter *> const &parameters )
    00084 {
    00085         // All of our tasks have exactly one parameter.
    00086         if(parameters.size() != 1) {
    00087                 return t_TaskSharedPointer();
    00088         }
    00089
    00090         return StaticTaskFactory::createTask( taskName, parameters );
    00091 }
    00092
    00094