4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@berlios.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.
24 \brief PacketRegistry non-inline template implementation */
26 #include "PacketRegistry.ih"
32 ///////////////////////////////ct.p////////////////////////////////////////
34 template <class PacketType>
35 prefix_ senf::PacketInterpreterBase::factory_t senf::detail::PkReg_EntryImpl<PacketType>::factory()
38 return PacketType::factory();
41 template <class KeyType>
42 template <class PacketType>
43 prefix_ void senf::detail::PacketRegistryImpl<KeyType>::registerPacket(key_t key)
46 registry_.insert(std::make_pair(key, Entry_ptr(new detail::PkReg_EntryImpl<PacketType>())));
47 reverseRegistry_.insert(std::make_pair(senf::typeIdValue<PacketType>(), key));
51 std::make_pair(key, Entry_ptr(new detail::PkReg_EntryImpl<PacketType>()))).second);
52 // If this assertion fails, a Packet was registered with an already known key
53 BOOST_ASSERT( isUnique );
55 reverseRegistry_.insert(
56 std::make_pair(senf::typeIdValue<PacketType>(), key)).second);
57 // If this assertion fails, the same Packet was registered with two different keys
58 BOOST_ASSERT( isNew );
62 template <class KeyType>
63 prefix_ typename senf::detail::PacketRegistryImpl<KeyType>::key_t
64 senf::detail::PacketRegistryImpl<KeyType>::key(senf::TypeIdValue const & type)
66 typename ReversePacketMap::iterator i (reverseRegistry_.find(type));
67 if (i==reverseRegistry_.end())
68 throw PacketTypeNotRegisteredException();
72 template <class KeyType>
73 prefix_ boost::optional<typename senf::detail::PacketRegistryImpl<KeyType>::key_t>
74 senf::detail::PacketRegistryImpl<KeyType>::key(senf::TypeIdValue const & type, bool)
76 typename ReversePacketMap::iterator i (reverseRegistry_.find(type));
77 if (i==reverseRegistry_.end())
78 return boost::optional<key_t>();
82 template <class KeyType>
83 prefix_ typename senf::detail::PacketRegistryImpl<KeyType>::Entry const &
84 senf::detail::PacketRegistryImpl<KeyType>::lookup(key_t key)
86 typename PacketMap::iterator i (registry_.find(key));
87 if (i==registry_.end())
88 throw PacketTypeNotRegisteredException();
92 template <class KeyType>
93 prefix_ typename senf::detail::PacketRegistryImpl<KeyType>::Entry const *
94 senf::detail::PacketRegistryImpl<KeyType>::lookup(key_t key, bool)
96 typename PacketMap::iterator i (registry_.find(key));
97 if (i==registry_.end())
99 return i->second.get();
103 prefix_ typename senf::PacketRegistry<Tag>::Registry &
104 senf::PacketRegistry<Tag>::registry()
106 static Registry registry;
110 ///////////////////////////////ct.e////////////////////////////////////////
117 // c-file-style: "senf"
118 // indent-tabs-mode: nil
119 // ispell-local-dictionary: "american"
120 // compile-command: "scons -u test"
121 // comment-column: 40