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"
29 #include "../Utils/senfassert.hh"
31 #include "../Utils/TypeInfo.hh"
34 ///////////////////////////////ct.p////////////////////////////////////////
36 template <class PacketType>
37 prefix_ senf::PacketInterpreterBase::factory_t senf::detail::PkReg_EntryImpl<PacketType>::factory()
40 return PacketType::factory();
43 template <class PacketType>
44 prefix_ std::string senf::detail::PkReg_EntryImpl<PacketType>::name()
47 return prettyName(typeid(PacketType));
50 template <class KeyType>
51 template <class PacketType>
52 prefix_ void senf::detail::PacketRegistryImpl<KeyType>::registerPacket(key_t key)
55 registry_.insert(std::make_pair(key, Entry_ptr(new detail::PkReg_EntryImpl<PacketType>())));
56 reverseRegistry_.insert(std::make_pair(senf::typeIdValue<PacketType>(), key));
60 std::make_pair(key, Entry_ptr(new detail::PkReg_EntryImpl<PacketType>()))).second);
61 // If this assertion fails, a Packet was registered with an already known key
62 SENF_ASSERT( isUnique );
64 reverseRegistry_.insert(
65 std::make_pair(senf::typeIdValue<PacketType>(), key)).second);
66 // If this assertion fails, the same Packet was registered with two different keys
71 template <class KeyType>
72 prefix_ typename senf::detail::PacketRegistryImpl<KeyType>::key_t
73 senf::detail::PacketRegistryImpl<KeyType>::key(senf::TypeIdValue const & type)
75 typename ReversePacketMap::iterator i (reverseRegistry_.find(type));
76 if (i==reverseRegistry_.end())
77 throw PacketTypeNotRegisteredException();
81 template <class KeyType>
82 prefix_ boost::optional<typename senf::detail::PacketRegistryImpl<KeyType>::key_t>
83 senf::detail::PacketRegistryImpl<KeyType>::key(senf::TypeIdValue const & type, bool)
85 typename ReversePacketMap::iterator i (reverseRegistry_.find(type));
86 if (i==reverseRegistry_.end())
87 return boost::optional<key_t>();
91 template <class KeyType>
92 prefix_ typename senf::detail::PacketRegistryImpl<KeyType>::Entry const &
93 senf::detail::PacketRegistryImpl<KeyType>::lookup(key_t key)
95 typename PacketMap::iterator i (registry_.find(key));
96 if (i==registry_.end())
97 throw PacketTypeNotRegisteredException();
101 template <class KeyType>
102 prefix_ typename senf::detail::PacketRegistryImpl<KeyType>::Entry const *
103 senf::detail::PacketRegistryImpl<KeyType>::lookup(key_t key, bool)
105 typename PacketMap::iterator i (registry_.find(key));
106 if (i==registry_.end())
108 return i->second.get();
112 prefix_ typename senf::PacketRegistry<Tag>::Registry &
113 senf::PacketRegistry<Tag>::registry()
115 static Registry registry;
119 ///////////////////////////////ct.e////////////////////////////////////////
126 // c-file-style: "senf"
127 // indent-tabs-mode: nil
128 // ispell-local-dictionary: "american"
129 // compile-command: "scons -u test"
130 // comment-column: 40