C:/cmcintos/defOrgs/source/cognitive/abc/ControlCenter.h

00001 #if defined (_MSC_VER) && (_MSC_VER >= 1000)
00002 #pragma once
00003 #endif
00004 #ifndef _INC_CONTROLCENTER
00005 #define _INC_CONTROLCENTER
00006 
00007 #include "Behavior.h"
00008 #include "Physics.h"
00009 #include "Sensor.h"
00010 #include "itkSmartPointer.h"
00011 #include <itkLightObject.h> 
00012 #include <vector>//Not to be confused with VNL vectors
00013 
00014 namespace mial{
00015 
00017 
00035         template<class Type,int nDims>
00036         class ControlCenter:public itk::LightObject
00037         {
00038         public:
00039                 //Smartpointers
00040                 typedef ControlCenter Self;
00041                 typedef itk::SmartPointer<Self>  Pointer;
00042                 typedef itk::SmartPointer<const Self>  ConstPointer;
00043                 typedef itk::WeakPointer<const Self>  ConstWeakPointer;
00044                 //itkNewMacro(Self);
00045                 
00047                 ~ControlCenter();
00048 
00050 
00052                 virtual bool update(){
00053                         if(behaviorToRun.IsNull())
00054                                 {decideNextBehavior();runNextBehavior();}
00055                         else if(behaviorToRun->isFinished())
00056                                 {behaviorToRun->cleanUp();decideNextBehavior();runNextBehavior();}
00057                         else
00058                                 {updateCurrentBehavior();}
00059                         return false;};
00060 
00062                 virtual bool setAllPhysics(Physics<Type,nDims> *p){for(int i=0;i<numBehaviors;i++){behaviorList[i]->setPhysLayer(p);} return false;};
00063 
00065 
00068                 virtual Behavior<Type,nDims>* findBehavior(const std::string name);
00069 
00071                 virtual int getNumBehaviors(){return numBehaviors;}; // inline
00072 
00074 
00077                 virtual bool addBehavior(Behavior<Type,nDims> * b);
00078         protected:
00079 
00081                 ControlCenter();
00082 
00084 
00087                 std::vector<typename Behavior<Type,nDims>::Pointer> behaviorList;
00088 
00090                 std::vector<Sensor::Pointer> sensorList;
00091 
00093                 typename Behavior<Type,nDims>::Pointer behaviorToRun;
00094 
00096                 //std::stringstream behaviorToRunArgs;
00097                 typename Behavior<Type,nDims>::behaviorIn* behaviorToRunStruct;
00098                 
00100                 std::stringstream * behaviorToRunStream;
00101                 
00103                 //bool runBehaviorByStream;
00104 
00106                 int state;
00107 
00109                 int numBehaviors;
00110 
00112                 void setBehaviorToRunStream(std::stringstream *a){behaviorToRunStream = a;};
00113 
00115                 virtual bool decideNextBehavior()=0;
00116 
00118                 virtual bool runNextBehavior(){if(behaviorToRun.IsNotNull()){behaviorToRun->run(behaviorToRunStruct,behaviorToRunStream);}return false;};
00119 
00121                 virtual bool updateCurrentBehavior(){behaviorToRun->update();return false;};
00122 
00123         };
00124 }//end mial
00125 #include "ControlCenter.cxx"
00126 #endif /* _INC_CONTROLCENTER*/

Generated on Wed Jul 19 13:05:17 2006 for IDO by  doxygen 1.4.7