Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

BehaviorReportControl.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_BehaviorReportControl_h_
00003 #define INCLUDED_BehaviorReportControl_h_
00004 
00005 #include "ControlBase.h"
00006 #include "Behaviors/BehaviorBase.h"
00007 
00008 //! Reads the set of currently instantiated behaviors and sends a report to ::sout
00009 class BehaviorReportControl : public ControlBase {
00010 public:
00011   //! Constructor
00012   BehaviorReportControl()
00013     : ControlBase("Behavior Report","Generates a summary of currently instantiated behaviors")
00014   {}
00015 
00016   //! Prints a report to sout
00017   virtual ControlBase * activate(MotionManager::MC_ID, Socket *) {
00018     typedef std::set<BehaviorBase*> registry_t;
00019     typedef std::vector<BehaviorBase*> behlist_t;
00020     const registry_t& reg=BehaviorBase::getRegistry();
00021     behlist_t active,inactive;
00022     for(registry_t::const_iterator it=reg.begin(); it!=reg.end(); it++) {
00023       if((*it)->isActive())
00024         active.push_back(*it);
00025       else
00026         inactive.push_back(*it);
00027     }
00028 
00029     char format[100];
00030     unsigned int maxlen=0;
00031     for(behlist_t::const_iterator it=active.begin(); it!=active.end(); it++)
00032       if((*it)->getName().size()>maxlen)
00033         maxlen=(*it)->getClassName().size();
00034     for(behlist_t::const_iterator it=inactive.begin(); it!=inactive.end(); it++)
00035       if((*it)->getName().size()>maxlen)
00036         maxlen=(*it)->getClassName().size();
00037     snprintf(format,100,"  %%-%ds   %%s\n",maxlen);
00038 
00039     sout->printf("** Currently Instantiated Behavior Report **\n");
00040     sout->printf("%lu active, %lu inactive, %lu total\n\n",(unsigned long)active.size(),(unsigned long)inactive.size(),(unsigned long)reg.size());
00041     sout->printf("Active Behaviors:\n");
00042     sout->printf(format,"Class Name","Instance Name");
00043     sout->printf(format,"------------","---------------");
00044     for(behlist_t::const_iterator it=active.begin(); it!=active.end(); it++)
00045       sout->printf(format,(*it)->getClassName().c_str(),(*it)->getName().c_str());
00046     sout->printf("\n");
00047     sout->printf("Inactive Behaviors:\n");
00048     sout->printf(format,"Class Name","Instance Name");
00049     sout->printf(format,"------------","---------------");
00050     for(behlist_t::const_iterator it=inactive.begin(); it!=inactive.end(); it++)
00051       sout->printf(format,(*it)->getClassName().c_str(),(*it)->getName().c_str());
00052     return NULL;
00053   }
00054 };
00055 
00056 /*! @file
00057  * @brief Defines BehaviorReportControl, which reads the set of currently instantiated behaviors and sends a report to ::sout
00058  * @author ejt (Creator)
00059  *
00060  * $Author: ejt $
00061  * $Name: tekkotsu-4_0 $
00062  * $Revision: 1.6 $
00063  * $State: Exp $
00064  * $Date: 2005/02/05 07:27:26 $
00065  */
00066 
00067 #endif

Tekkotsu v4.0
Generated Thu Nov 22 00:54:51 2007 by Doxygen 1.5.4