User Manual, Developers Guide and API Documentation

SwitchLink.hpp

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. 5, 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 #ifndef LTE_HELPER_SWITCHLINK_HPP
00029 #define LTE_HELPER_SWITCHLINK_HPP
00030 
00031 #include <WNS/ldk/Link.hpp>
00032 
00033 #include <WNS/Assure.hpp>
00034 
00035 #include <list>
00036 
00037 namespace lte { namespace helper {
00038 
00039         namespace tests {
00040             class SwitchLinkTest;
00041         }
00042 
00043         template <typename RECEPTACLETYPE>
00044         class SwitchLink :
00045         virtual public wns::ldk::Link<RECEPTACLETYPE>
00046         {
00047             friend class tests::SwitchLinkTest;
00048         public:
00049             SwitchLink()
00050                 : recs(),
00051                   active(NULL)
00052             {}
00053 
00054             virtual
00055             ~SwitchLink()
00056             {
00057                 recs.clear();
00058                 active = NULL;
00059             }
00060 
00064             //{@
00065             virtual void
00066             add(RECEPTACLETYPE* it)
00067             {
00068                 assureNotNull(it);
00069                 recs.push_back(it);
00070             }
00071 
00072             virtual long unsigned int
00073             size() const
00074             {
00075                 return recs.size();
00076             }
00077 
00078             virtual void
00079             clear()
00080             {
00081                 recs.clear();
00082             }
00083 
00084             virtual const typename wns::ldk::Link<RECEPTACLETYPE>::ExchangeContainer
00085             get() const
00086             {
00087                 typename wns::ldk::Link<RECEPTACLETYPE>::ExchangeContainer container;
00088 
00089                 for (typename std::list<RECEPTACLETYPE*>::const_iterator iter = recs.begin();
00090                      iter != recs.end();
00091                      ++iter)
00092                     container.push_back(*iter);
00093 
00094                 return container;
00095             }
00096 
00097             virtual void
00098             set(const typename wns::ldk::Link<RECEPTACLETYPE>::ExchangeContainer& src)
00099             {
00100                 // setting a new set of links deletes the activation. It needs to be re-set
00101                 active = NULL;
00102 
00103                 if (!src.empty())
00104                 {
00105                     recs.clear();
00106                     for (typename wns::ldk::Link<RECEPTACLETYPE>::ExchangeContainer::const_iterator iter = src.begin();
00107                          iter != src.end();
00108                          ++iter)
00109                     {
00110                         assureNotNull(*iter);
00111                         recs.push_back(*iter);
00112                     }
00113                 }
00114             }
00116 
00117             void
00118             activate(const typename wns::ldk::Link<RECEPTACLETYPE>::ExchangeContainer& src)
00119             {
00120                 assure(src.size()<2, "SwitchLink can not activate more than one link at a time.");
00121 
00122                 if (src.size()>0){
00123                     assure(find(recs.begin(), recs.end(), src[0]) != recs.end(),
00124                            "Trying to activate unknown link.");
00125 
00126                     activate(src[0]);
00127                 }
00128             }
00129 
00130             void
00131             activate(const RECEPTACLETYPE* src)
00132             {
00133                 assureNotNull(src);
00134 
00135                 assure(find(recs.begin(), recs.end(), src) != recs.end(),
00136                        "Trying to activate unknown link.");
00137 
00138                 active = *(find(recs.begin(), recs.end(), src));
00139             }
00140 
00141             typename std::list<RECEPTACLETYPE*>
00142             getFUs() const
00143             {
00144                 return recs;
00145             }
00146 
00147         protected:
00148             std::list<RECEPTACLETYPE*> recs;
00149 
00150             RECEPTACLETYPE* active;
00151         };
00152     } // helper
00153 } // lte
00154 
00155 #endif // LTE_HELPER_SWITCHLINK_HPP
00156 
00157 

Generated on Sat May 26 03:32:02 2012 for openWNS by  doxygen 1.5.5