}
///////////////////////////////////////////////////////////////////////////
-// senf::PacketRegistry<Tag>
-
-template <class Tag>
-prefix_ typename senf::PacketRegistry<Tag>::Registry &
-senf::PacketRegistry<Tag>::registry()
-{
- static Registry registry (prettyName(typeid(Tag)));
- return registry;
-}
-
-///////////////////////////////////////////////////////////////////////////
// senf::detail::PacketRegistryImpl<KeyType>:
template <class KeyType>
template <class PacketType>
prefix_ void senf::PacketRegistry<Tag>::unregisterPacket()
{
- registry().unregisterPacket<PacketType>();
+ if (alive())
+ registry().unregisterPacket<PacketType>();
}
template <class Tag>
prefix_ void senf::PacketRegistry<Tag>::unregisterPacket(typename Tag::key_t key, int priority)
{
- registry().unregisterPacket(key, priority);
+ if (alive())
+ registry().unregisterPacket(key, priority);
}
template <class Tag>
return registry().end();
}
+template <class Tag>
+prefix_ senf::PacketRegistry<Tag>::PacketRegistry()
+ : registry_ (prettyName(typeid(Tag)))
+{}
+
+template <class Tag>
+prefix_ typename senf::PacketRegistry<Tag>::Registry &
+senf::PacketRegistry<Tag>::registry()
+{
+ return instance().registry_;
+}
+
///////////////////////////////////////////////////////////////////////////
// senf::detail::PacketRegistryImpl<KeyType>
#include <boost/optional.hpp>
#include <boost/preprocessor/cat.hpp>
#include <senf/Utils/Exception.hh>
+#include <senf/Utils/singleton.hh>
#include "Packet.hh"
#include "PacketRegistry.ih"
*/
template <class Tag>
class PacketRegistry
+ : private senf::singleton< PacketRegistry<Tag> >
{
public:
typedef typename detail::PacketRegistryImpl<typename Tag::key_t>::iterator iterator;
static iterator end();
private:
+ using singleton<PacketRegistry>::instance;
+ using singleton<PacketRegistry>::alive;
+
+ PacketRegistry();
+
typedef detail::PacketRegistryImpl<typename Tag::key_t> Registry;
static Registry & registry();
+ Registry registry_;
+
+ friend class senf::singleton< PacketRegistry >;
};
/** \brief Statically add an entry to a packet registry