Module.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2006-2011, SRI International (R)
00003  *
00004  * This program is free software: you can redistribute it and/or modify
00005  * it under the terms of the GNU Lesser General Public License as published by
00006  * the Free Software Foundation, either version 3 of the License, or
00007  * (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU Lesser General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Lesser General Public License
00015  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016  */
00017 
00018 #include <OpenKarto/Module.h>
00019 #include <OpenKarto/TypeCasts.h>
00020 #include <OpenKarto/Logger.h>
00021 
00022 #include <iostream>
00023 
00024 namespace karto
00025 {
00026 
00027   Module::Module(const Identifier& rName)
00028     : Object(rName)
00029   {
00030   }
00031 
00032   Module::~Module()
00033   {
00034   }
00035 
00036   kt_bool Module::Process(karto::Object* pObject)
00037   {
00038     kt_bool isObjectProcessed = false;
00039     
00040     if (IsSensor(pObject))
00041     {
00042       m_Sensors.Add(dynamic_cast<karto::Sensor*>(pObject));
00043       isObjectProcessed = true;
00044     }
00045     else if (IsModuleParameters(pObject))
00046     {
00047       karto::ModuleParameters* pParameters = dynamic_cast<karto::ModuleParameters*>(pObject);
00048       
00049       if (pParameters != NULL && pParameters->GetIdentifier() == GetIdentifier())
00050       {
00051         // copy parameters
00052         const karto::ParameterList& rParameters = pParameters->GetParameters();
00053         karto_const_forEach(karto::ParameterList, &rParameters)
00054         {
00055           karto::AbstractParameter* pParameterFrom = *iter;
00056           karto::AbstractParameter* pParameterTo = GetParameter(pParameterFrom->GetName());
00057           if (pParameterTo != NULL)
00058           {
00059             pParameterTo->SetValueFromString(pParameterFrom->GetValueAsString());
00060           }
00061           else
00062           {
00063             Log(LOG_WARNING, String("Invalid ") + GetIdentifier().ToString() + " parameter: " + pParameterFrom->GetName() + " parameter is ignored!");
00064           }
00065         }
00066       }
00067       
00068       isObjectProcessed = true;
00069     }
00070 
00071     return isObjectProcessed;
00072   }
00073 
00074   void Module::Reset()
00075   {
00076     m_Sensors.Clear();
00077   }
00078 
00079 }
00080 


nav2d_karto
Author(s): Sebastian Kasperski
autogenerated on Mon Oct 6 2014 02:44:17