PoiManager.cpp
Go to the documentation of this file.
00001 /*******************************************************************************
00002  *  NavigationMap.cpp
00003  *
00004  *  (C) 2007 AG Aktives Sehen <agas@uni-koblenz.de>
00005  *           Universitaet Koblenz-Landau
00006  *
00007  *  Information on Code Review state:
00008  *  Author: CB; DevelTest: 05.03.2007; Reviewer: initials; Review: date; State: NOK
00009  *
00010  *  Additional information:
00011  *  $Id: PoiManager.cpp 44313 2011-04-06 22:46:28Z agas $
00012  *******************************************************************************/
00013 
00014 #include "PoiManager.h"
00015 
00016 #include <sstream>
00017 
00018 #define THIS PoiManager
00019 
00020 //#include <iostream>
00021 
00022 using namespace std;
00023 
00024 
00025 THIS::THIS()
00026 {
00027   m_CurrentId=0;
00028 }
00029 
00030 THIS::THIS ( list<PointOfInterest> pois )
00031 {
00032   //copy POIs
00033   m_Pois = pois;
00034 
00035   //search maximum occupied ID
00036   list<PointOfInterest>::iterator it;
00037   m_CurrentId=0;
00038 
00039   for ( it=m_Pois.begin() ; it != m_Pois.end(); it++ )
00040   {
00041     if ( it->getId() >m_CurrentId )
00042     {
00043       m_CurrentId=it->getId();
00044     }
00045   }
00046 
00047   //set next ID to be used
00048   m_CurrentId++;
00049 
00050   ostringstream stream;
00051 
00052   stream << "Copied POI list. Next ID to be used: " << m_CurrentId;
00053 
00054   // TRACE_INFO ( stream.str() ); // TODO use ROS
00055 }
00056 
00057 list<PointOfInterest> THIS:: getList()
00058 {
00059   return m_Pois;
00060 }
00061 
00062 bool THIS::addPointOfInterest ( int id, const PointOfInterest* poi )
00063 {
00064   ostringstream stream;
00065 
00066   //make sure there's no POI with the same ID
00067 
00068   if ( poiExists ( id ) )
00069   {
00070     ostringstream stream;
00071     stream << "Poi with id " << id << " already exists! Doing nothing.";
00072     // TRACE_ERROR ( stream.str() ); // TODO use ROS
00073     return false;
00074   }
00075 
00076   //copy poi & assigning new id
00077   PointOfInterest new_poi=PointOfInterest ( id,poi );
00078 
00079   stream << "Adding POI '" << new_poi.getName() << "'. New ID: " << id << ".";
00080 
00081   // TRACE_INFO ( stream.str() ); // TODO use ROS
00082 
00083   //insert into list
00084   m_Pois.push_back ( new_poi );
00085 
00086   return true;
00087 }
00088 
00089 int THIS::addPointOfInterest ( const PointOfInterest* poi )
00090 {
00091   addPointOfInterest ( m_CurrentId,poi );
00092   m_CurrentId++;
00093 
00094   return m_CurrentId-1;
00095 }
00096 
00097 bool THIS::modifyPointOfInterest ( const PointOfInterest* poi )
00098 {
00099   int id=const_cast < PointOfInterest* > ( poi )->getId();
00100 
00101   list<PointOfInterest>::iterator it;
00102 
00103   for ( it=m_Pois.begin() ; it != m_Pois.end(); it++ )
00104   {
00105     if ( it->getId() ==id )
00106     {
00107       *it=*poi;
00108       return true;
00109     }
00110   }
00111 
00112   // TRACE_ERROR ( "Cannot modify: POI does not exist!" ); // TODO use ROS
00113 
00114   return false;
00115 }
00116 
00117 bool THIS::poiExists ( int id )
00118 {
00119   list<PointOfInterest>::iterator it;
00120 
00121   for ( it=m_Pois.begin() ; it != m_Pois.end(); it++ )
00122   {
00123     if ( it->getId() ==id )
00124     {
00125       return true;
00126     }
00127   }
00128 
00129   return false;
00130 }
00131 
00132 bool THIS::deletePointOfInterest ( int id )
00133 {
00134   ostringstream s;
00135 
00136   list< PointOfInterest >::iterator it;
00137 
00138   for ( it=m_Pois.begin() ; it != m_Pois.end(); it++ )
00139   {
00140     if ( it->getId() == id )
00141     {
00142       s << "Erasing POI " << id << ".";
00143       // TRACE_INFO ( s.str() ); // TODO use ROS
00144 
00145       it = m_Pois.erase ( it );
00146 
00147       return true;
00148     }
00149   }
00150 
00151   s << "POI " << id << " does not exist.";
00152 
00153   // TRACE_ERROR ( s.str() ); // TODO use ROS
00154 
00155   return false;
00156 }
00157 
00158 int THIS::deletePointOfInterest ( string namePart )
00159 {
00160   int deleteCount = 0;
00161 
00162   list< PointOfInterest >::iterator it = m_Pois.begin();
00163 
00164   while ( it != m_Pois.end() )
00165   {
00166     if ( it->hasInName ( namePart ) )
00167     {
00168       ostringstream s;
00169       s << "Erasing POI " << it->getId() << " named '" << it->getName() << "'.";
00170       // TRACE_INFO ( s.str() ); // TODO use ROS
00171 
00172       it = m_Pois.erase ( it );
00173       deleteCount++;
00174     }
00175     else
00176     {
00177       it++;
00178     }
00179   }
00180 
00181   return deleteCount;
00182 }
00183 
00184 
00185 #undef THIS


obj_rec_gui
Author(s): AGAS/agas@uni-koblenz.de
autogenerated on Mon Oct 6 2014 02:53:43