template <class Tag>
template <class PacketType>
prefix_ senf::PacketRegistry<Tag>::RegistrationProxy<PacketType>::
-RegistrationProxy(typename Tag::key_t key)
+RegistrationProxy(typename Tag::key_t key, int priority)
{
- PacketRegistry<Tag>::template registerPacket<PacketType>(key);
+ PacketRegistry<Tag>::template registerPacket<PacketType>(key,priority);
}
template <class Tag>
template <class Tag>
template <class PacketType>
-prefix_ void senf::PacketRegistry<Tag>::registerPacket(typename Tag::key_t key)
+prefix_ void senf::PacketRegistry<Tag>::registerPacket(typename Tag::key_t key, int priority)
{
- registry().registerPacket<PacketType>(key);
+ registry().registerPacket<PacketType>(key, priority);
}
template <class Tag>
}
template <class Tag>
-prefix_ void senf::PacketRegistry<Tag>::unregisterPacket(typename Tag::key_t key)
+prefix_ void senf::PacketRegistry<Tag>::unregisterPacket(typename Tag::key_t key, int priority)
{
- registry().unregisterPacket(key);
+ registry().unregisterPacket(key, priority);
}
template <class Tag>
template <class PacketType>
struct RegistrationProxy
{
- RegistrationProxy(typename Tag::key_t key);
+ RegistrationProxy(typename Tag::key_t key, int priority=0);
~RegistrationProxy();
};
\param key The key of the packet
*/
template <class PacketType>
- static void registerPacket(typename Tag::key_t key);
+ static void registerPacket(typename Tag::key_t key, int priority=0);
template <class PacketType>
static void unregisterPacket();
- static void unregisterPacket(typename Tag::key_t key);
+ static void unregisterPacket(typename Tag::key_t key, int priority=0);
/** \brief Find key of a packet type
\ingroup packet_module
\hideinitializer
*/
-# define SENF_PACKET_REGISTRY_REGISTER( registry, value, type ) \
- namespace { \
- senf::PacketRegistry< registry >::RegistrationProxy< type > \
- BOOST_PP_CAT(packetRegistration_, __LINE__) ( value ); \
+# define SENF_PACKET_REGISTRY_REGISTER( registry, value, type ) \
+ namespace { \
+ senf::PacketRegistry< registry >::RegistrationProxy< type > \
+ BOOST_PP_CAT(packetRegistration_, __LINE__) ( value ); \
+ }
+
+ /** \brief Statically add an entry to a packet registry
+
+ This macro will declare an anonymous global variable in such a way, that constructing this
+ variable will add a registration to the given packet registry.
+
+ \ingroup packet_module
+ \hideinitializer
+ */
+# define SENF_PACKET_REGISTRY_REGISTER_PRIORITY( registry, value, priority, type ) \
+ namespace { \
+ senf::PacketRegistry< registry >::RegistrationProxy< type > \
+ BOOST_PP_CAT(packetRegistration_, __LINE__) ( value, priority ); \
}
/** \brief Dump all packet registries
}
-SENF_PACKET_REGISTRY_REGISTER(StringTag, "foo", FooPacket);
+SENF_PACKET_REGISTRY_REGISTER(StringTag, "foo", OtherPacket);
+SENF_PACKET_REGISTRY_REGISTER_PRIORITY(StringTag, "foo", 1, FooPacket);
SENF_AUTO_UNIT_TEST(packetRegistry_test)
{
PacketTypeNotRegisteredException );
BOOST_CHECK_EQUAL( PacketRegistry<StringTag>::key<FooPacket>(), "foo" );
+ BOOST_CHECK( PacketRegistry<StringTag>::lookup("foo").type() == typeid(FooPacket) );
BOOST_CHECK( ! PacketRegistry<StringTag>::lookup("blub", senf::nothrow) );
BOOST_CHECK( PacketRegistry<BaseTag>::lookup(1u, senf::nothrow) );
&senf::PacketRegistry<BaseTag>::Entry::key>()),
elts1+0, elts1+sizeof(elts1)/sizeof(elts1[0]) );
- std::string elts2[] = { "bar", "foo" };
+ std::string elts2[] = { "bar", "foo", "foo" };
BOOST_CHECK_EQUAL_COLLECTIONS(
boost::make_transform_iterator(
PacketRegistry<StringTag>::begin(),
(s.str())
("(anonymous namespace)::StringTag:\n"
" bar 0 (anonymous namespace)::BarPacketType\n"
- " foo 0 (anonymous namespace)::FooPacketType\n"
+ " foo 1 (anonymous namespace)::FooPacketType\n"
+ " foo 0 (anonymous namespace)::OtherPacketType\n"
"\n" ));
}
(s.str())
("(anonymous namespace)::StringTag:\n"
" bar 0 (anonymous namespace)::BarPacketType\n"
- " foo 0 (anonymous namespace)::FooPacketType\n"
+ " foo 1 (anonymous namespace)::FooPacketType\n"
+ " foo 0 (anonymous namespace)::OtherPacketType\n"
"\n" ));
SENF_CHECK_NO_THROW( PacketRegistry<BaseTag>::unregisterPacket(1u) );
contains,
(s.str())
("(anonymous namespace)::StringTag:\n"
- " foo 0 (anonymous namespace)::FooPacketType\n"
+ " foo 1 (anonymous namespace)::FooPacketType\n"
+ " foo 0 (anonymous namespace)::OtherPacketType\n"
"\n" ));
}
}