4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
6 // Stefan Bund <stefan.bund@fokus.fraunhofer.de>
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 // Definition of non-inline template funPacketRegistry.ons
25 #include "PacketRegistry.ih"
29 #include "Utils/TypeInfo.hh"
32 ///////////////////////////////ct.p////////////////////////////////////////
34 template <class KeyType>
35 template <class OtherPacket>
36 prefix_ void senf::impl::PacketRegistryImpl<KeyType>::registerPacket(key_t key)
38 // If this assertion fails, a Packet was registered with an already known key
39 BOOST_ASSERT( registry_.insert(std::make_pair(
40 key, Entry_ptr(new impl::PkReg_EntryImpl<OtherPacket>()))).second );
41 // If this assertion fails, the same Packet was registered with two different keys
42 BOOST_ASSERT( reverseRegistry_.insert(
43 std::make_pair(senf::typeIdValue<OtherPacket>(), key)).second );
46 template <class KeyType>
47 prefix_ typename senf::impl::PacketRegistryImpl<KeyType>::key_t
48 senf::impl::PacketRegistryImpl<KeyType>::key(senf::TypeIdValue const & type)
50 typename ReversePacketMap::iterator i (reverseRegistry_.find(type));
51 if (i==reverseRegistry_.end())
52 throw PacketTypeNotRegistered();
56 template <class OtherPacket>
58 senf::impl::PkReg_EntryImpl<OtherPacket>::registerInterpreter(Packet const * p,
62 p->template registerInterpreter<OtherPacket>(b,e);
65 template <class OtherPacket>
66 prefix_ senf::Packet::ptr
67 senf::impl::PkReg_EntryImpl<OtherPacket>::reinterpret(Packet * p)
69 return p->template reinterpret<OtherPacket>();
72 template <class KeyType>
73 prefix_ typename senf::impl::PacketRegistryImpl<KeyType>::Entry *
74 senf::impl::PacketRegistryImpl<KeyType>::lookup(key_t key)
76 typename PacketMap::iterator i (registry_.find(key));
77 if (i==registry_.end())
78 return &impl::pkreg_dataEntry;
79 return i->second.get();
83 template <class InputIterator>
84 prefix_ senf::Packet::ptr
85 senf::PacketRegistry<Tag>::create(typename Tag::key_t key, InputIterator b,
88 Packet::ptr p (Packet::create<DataPacket>(b,e));
89 return registry().lookup(key)->reinterpret(p.get());
93 prefix_ typename senf::PacketRegistry<Tag>::Registry &
94 senf::PacketRegistry<Tag>::registry()
96 static Registry registry;
100 ///////////////////////////////ct.e////////////////////////////////////////
106 // c-file-style: "senf"