ActiveObjectManager.cpp

Go to the documentation of this file.
00001 /*
00002 Copyright 2007, 2008, 2009, 2010, 2011 Instituto de Sistemas e Robotica, Instituto Superior Tecnico
00003 
00004 This file is part of MeRMaID.
00005 
00006 MeRMaID is free software: you can redistribute it and/or modify
00007 it under the terms of the GNU Lesser General Public License as published by
00008 the Free Software Foundation, either version 3 of the License, or
00009 (at your option) any later version.
00010 
00011 MeRMaID is distributed in the hope that it will be useful,
00012 but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 GNU Lesser General Public License for more details.
00015 
00016 You should have received a copy of the GNU Lesser General Public License
00017 along with MeRMaID.  If not, see <http://www.gnu.org/licenses/>.
00018 */
00019 
00020 
00021 
00022 /**
00023  * @Filename ActiveObjectManager.cpp
00024  * @Description ActiveObjectManager implementation
00025  * @Status Work in Progress
00026  * @Version $Id: ActiveObjectManager.cpp 1 2011-03-04 18:13:18Z jreis $
00027  * @Maintainer
00028  */
00029 
00030 
00031 #include "config.h"
00032 
00033 #include <ActiveObjectManager.hpp>
00034 
00035 #include <Exception.hpp>
00036 
00037 #include <iostream>
00038 
00039 using namespace mermaid::support::activeobject;
00040 
00041 using mermaid::support::errorhandling::Exception;
00042 
00043 ActiveObjectManager::ActiveObjectManager()
00044 {
00045 
00046 }; // AcActiveObjectManager()
00047 
00048 ActiveObjectManager::~ActiveObjectManager()
00049 {
00050 
00051 }; // ~AcActiveObjectManager()
00052 
00053 
00054 
00055 
00056 void ActiveObjectManager::addActiveObject (shared_ptr<ActiveObject> ao)
00057 {
00058   smartPointerMap[ao.get() ] = ao;
00059   aoVector_.push_back (ao);
00060   set<shared_ptr<ActiveObject> > s = stateMap[ao->getState() ];
00061   s.insert (ao);
00062   stateMap[ao->getState() ] = s;
00063   
00064 }; // addActiveObject()
00065 
00066 
00067 
00068 
00069 int ActiveObjectManager::getNumberOfActiveObjects()
00070 {
00071   return aoVector_.size();
00072 }; // getNumberOfActiveObjects()
00073 
00074 
00075 
00076 void ActiveObjectManager::notifyActiveObjectStateChange (ActiveObject * aoPtr, ActiveObjectState previousState)
00077 {
00078   shared_ptr<ActiveObject> ao = smartPointerMap[aoPtr];
00079   
00080   set<shared_ptr<ActiveObject> > prevStateSet = stateMap[previousState];
00081   set<shared_ptr<ActiveObject> > currStateSet = stateMap[ao->getState() ];
00082   
00083   prevStateSet.erase (ao);
00084   currStateSet.insert (ao);
00085   
00086   stateMap[previousState] = prevStateSet;
00087   stateMap[ao->getState() ] = currStateSet;
00088   
00089 }; // notifyActiveObjectStateChange
00090 
00091 
00092 vector<shared_ptr<ActiveObject> > ActiveObjectManager::getActiveObjectVector()
00093 {
00094   return vector<shared_ptr<ActiveObject> > (aoVector_);
00095 }; // getActiveObjectVector
00096 
00097 
00098 
00099 set<shared_ptr<ActiveObject> > ActiveObjectManager::getActiveObjectStateSet (ActiveObjectState s)
00100 {
00101   set<shared_ptr<ActiveObject> > ret = stateMap[s];
00102   return set< shared_ptr<ActiveObject> > (ret);
00103 }; // getActiveObjectStateSet
Generated on Fri Mar 4 22:14:58 2011 for MeRMaID::support by  doxygen 1.6.3