User Manual, Developers Guide and API Documentation

ContextProviderCollection.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. 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 #ifndef WNS_PROBE_BUS_CONTEXTPROVIDERREGISTRY_HPP
00029 #define WNS_PROBE_BUS_CONTEXTPROVIDERREGISTRY_HPP
00030 
00031 #include <WNS/probe/bus/ContextProvider.hpp>
00032 
00033 #include <WNS/osi/PDU.hpp>
00034 
00035 #include <string>
00036 #include <list>
00037 
00038 namespace wns { namespace probe { namespace bus {
00039 
00047     class ContextProviderCollection
00048     {
00052         class IProviderWrapper :
00053             public wns::probe::bus::IContextProvider
00054         {
00055         public:
00056             virtual IProviderWrapper*
00057             clone() const = 0;
00058         };
00059 
00063         template <typename T>
00064         class ProviderWrapper :
00065             public IProviderWrapper
00066         {
00067             T wrapee_;
00068 
00069             virtual IProviderWrapper*
00070             clone() const
00071                 {
00072                     return new ProviderWrapper<T>(*this);
00073                 }
00074         public:
00075             explicit
00076             ProviderWrapper(T t) : wrapee_(t) {}
00077 
00078             virtual void
00079             visit(IContext& context, const wns::osi::PDUPtr& pdu) const
00080                 {
00081                     wrapee_.visit(context,  pdu);
00082                 }
00083 
00084             virtual void
00085             visit(IContext& context) const
00086                 {
00087                     wrapee_.visit(context);
00088                 }
00089 
00090         };
00091 
00092 
00093     public:
00094         typedef std::list<IProviderWrapper*> ProviderContainer;
00095         typedef ProviderContainer::const_iterator ProviderIterator;
00096 
00097         ContextProviderCollection() :
00098             parent_(NULL),
00099             providers_()
00100         {}
00101 
00102         ContextProviderCollection(ContextProviderCollection* parent) :
00103             parent_(parent),
00104             providers_()
00105         {
00106         }
00107 
00108         ContextProviderCollection(const ContextProviderCollection& other) :
00109             parent_(other.parent_),
00110             providers_()
00111         {
00112             for (ProviderContainer::const_iterator iter = other.providers_.begin();
00113                  iter != other.providers_.end();
00114                  ++iter)
00115             {
00116                 this->providers_.push_back( (*iter)->clone() );
00117             }
00118         }
00119 
00120         ~ContextProviderCollection(){
00121             parent_ = NULL;
00122 
00123             while (!providers_.empty())
00124             {
00125                 delete providers_.front();
00126                 providers_.pop_front();
00127             }
00128         }
00129 
00133         template <typename T>
00134         void
00135         addProvider(T provider)
00136         {
00137             providers_.push_back(new ProviderWrapper<T>(provider));
00138         } // addProvider
00139 
00143         void
00144         fillContext(IContext& context) const
00145         {
00146             if (parent_ != NULL)
00147             {
00148                 parent_->fillContext(context);
00149             }
00150             for (ProviderContainer::const_iterator iter = providers_.begin();
00151                  iter != providers_.end();
00152                  ++iter)
00153             {
00154                 (*iter)->visit(context);
00155             }
00156         }
00157 
00161         void
00162         fillContext(IContext& context, const wns::osi::PDUPtr& compound) const
00163         {
00164             if (parent_ != NULL)
00165             {
00166                 parent_->fillContext(context, compound);
00167             }
00168             for (ProviderContainer::const_iterator iter = providers_.begin();
00169                  iter != providers_.end();
00170                  ++iter)
00171             {
00172                 (*iter)->visit(context, compound);
00173             }
00174         }
00175 
00176     private:
00177         ContextProviderCollection* parent_;
00178         ProviderContainer providers_;
00179     };
00180 }}}
00181 
00182 #endif // NOT defined WNS_PROBE_BUS_CONTEXTPROVIDERREGISTRY_HPP
00183 
00184 /*
00185   Local Variables:
00186   mode: c++
00187   fill-column: 80
00188   c-basic-offset: 8
00189   c-tab-always-indent: t
00190   indent-tabs-mode: t
00191   tab-width: 8
00192   End:
00193 */

Generated on Tue May 22 03:31:46 2012 for openWNS by  doxygen 1.5.5