User Manual, Developers Guide and API Documentation

CompoundSwitchConnector.cpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002  * This file is part of openWNS (open Wireless Network Simulator)
00003  * _____________________________________________________________________________
00004  *
00005  * Copyright (C) 2004-2007
00006  * Chair of Communication Networks (ComNets)
00007  * Kopernikusstr. 16, D-52074 Aachen, Germany
00008  * phone: ++49-241-80-27910,
00009  * fax: ++49-241-80-22242
00010  * email: info@openwns.org
00011  * www: http://www.openwns.org
00012  * _____________________________________________________________________________
00013  *
00014  * openWNS is free software; you can redistribute it and/or modify it under the
00015  * terms of the GNU Lesser General Public License version 2 as published by the
00016  * Free Software Foundation;
00017  *
00018  * openWNS is distributed in the hope that it will be useful, but WITHOUT ANY
00019  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
00020  * A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00021  * details.
00022  *
00023  * You should have received a copy of the GNU Lesser General Public License
00024  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00025  *
00026  ******************************************************************************/
00027 
00028 #include <DLL/compoundSwitch/CompoundSwitchConnector.hpp>
00029 #include <DLL/compoundSwitch/Filter.hpp>
00030 
00031 #include <algorithm>
00032 
00033 using namespace dll::compoundSwitch;
00034 
00035 // CompoundSwitchConnector::~CompoundSwitchConnector()
00036 // {
00037 //  while ( !filters_.empty() )
00038 //  {
00039 //      delete *(filters_.begin());
00040 //      filters_.erase(filters_.begin());
00041 //  }
00042 // }
00043 
00044 void
00045 CompoundSwitchConnector::addFilter(IFilter* filter)
00046 {
00047     // check for double entries
00048     Filters::iterator it = filters_.begin();
00049     for(;it != filters_.end(); ++it)
00050     {
00051         if ((*it)->getName() == filter->getName())
00052         {
00053             std::ostringstream errorLog;
00054             errorLog << "dll::compoundSwitch::CompoundSwitchConnector: Double entry found in UL od Dl Filter list: " 
00055                      << filter->getName();
00056             assure( 0, errorLog.str() );
00057         }
00058     }
00059 
00060     // add Filter
00061     filters_.push_back( filter );
00062 }
00063 
00064 void
00065 CompoundSwitchConnector::onFUNCreated(bool mustAccept)
00066 {
00067     this->mustAccept_ = mustAccept;
00068 
00069     // Call onFUNCreated of every filter
00070     for(Filters::iterator it = filters_.begin();
00071         it != filters_.end(); ++it)
00072     {
00073         (*it)->onFUNCreated();
00074     }
00075 
00076 }
00077 
00078 IFilter*
00079 CompoundSwitchConnector::getFilter(const wns::ldk::CompoundPtr& compound) const
00080 {
00081     for(Filters::const_iterator it = filters_.begin();
00082         it != filters_.end(); ++it)
00083     {
00084         if( dynamic_cast<IFilter*>(*it)->filter(compound) )
00085         {
00086             return (*it);
00087             break;
00088         }
00089     }
00090     assure (0, "CompoundSwitchDeliverer::getFilter: No filter found for this compound. \n");
00091     return filters_.back();
00092 } // getFilter
00093 
00094 CompoundSwitchConnector::Filters
00095 CompoundSwitchConnector::getAllFilter() const
00096 {
00097     Filters result;
00098     for(Filters::const_iterator it = filters_.begin();
00099         it != filters_.end(); ++it)
00100     {
00101         result.push_back(*it);
00102     }
00103     return result;
00104 } //getAllFilter()
00105 
00106 void
00107 CompoundSwitchConnector::add(wns::ldk::IConnectorReceptacle* fu)
00108 {
00109     fus.push_back(fu);
00110 } // add
00111 
00112 void
00113 CompoundSwitchConnector::clear()
00114 {
00115     fus.clear();
00116 } // clear
00117 
00118 unsigned long int
00119 CompoundSwitchConnector::size() const
00120 {
00121     return fus.size();
00122 } // size
00123 
00124 const wns::ldk::Link<wns::ldk::IConnectorReceptacle>::ExchangeContainer
00125 CompoundSwitchConnector::get() const
00126 {
00127     wns::ldk::Link<wns::ldk::IConnectorReceptacle>::ExchangeContainer result;
00128 
00129     for(wns::ldk::Link<wns::ldk::IConnectorReceptacle>::ExchangeContainer::const_iterator it = fus.begin();
00130         it != fus.end();
00131         ++it) {
00132         result.push_back(*it);
00133     }
00134 
00135     return result;
00136 } // get
00137 
00138 void
00139 CompoundSwitchConnector::set(const wns::ldk::Link<wns::ldk::IConnectorReceptacle>::ExchangeContainer& src)
00140 {
00141     fus.clear();
00142 
00143         for(wns::ldk::Link<wns::ldk::IConnectorReceptacle>::ExchangeContainer::const_iterator it = src.begin();
00144         it != src.end();
00145         ++it) {
00146         fus.push_back(*it);
00147     }
00148 } // set
00149 
00150 bool
00151 CompoundSwitchConnector::hasAcceptor(const wns::ldk::CompoundPtr& compound)
00152 {
00153     int i = 0;
00154     for(Filters::const_iterator it = filters_.begin();
00155         it != filters_.end(); ++it)
00156     {
00157         if( (*it)->filter(compound) )
00158         {
00159             if(this->mustAccept_)
00160             {
00161                 if (fus.at(i)->isAccepting(compound))
00162                     return true;
00163             }
00164             else
00165             {
00166                 return(fus.at(i)->isAccepting(compound));
00167             }
00168         }
00169         ++i;
00170     }
00171     return false;
00172 }
00173 
00174 wns::ldk::IConnectorReceptacle*
00175 CompoundSwitchConnector::getAcceptor(const wns::ldk::CompoundPtr& compound)
00176 {
00177     int i = 0;
00178     for(Filters::const_iterator it = filters_.begin();
00179         it != filters_.end(); ++it)
00180     {
00181         if( (*it)->filter(compound) )
00182         {
00183             if(this->mustAccept_)
00184             {
00185                 if ( fus.at(i)->isAccepting(compound) )
00186                     return fus.at(i);
00187             }
00188             else
00189             {
00190                 return fus.at(i);
00191             }
00192         }
00193         ++i;
00194     }
00195     throw wns::Exception("CompoundSwitchConnector::getAcceptor: No filter found for this compound.");
00196     return 0;
00197 }

Generated on Fri Feb 10 03:32:29 2012 for openWNS by  doxygen 1.5.5