Packets/80221Bundle: extended MIHMessageType / MIHMessageRegistry to validate MIH...
[senf.git] / senf / Packets / PacketRegistry.hh
index 497c143..f69d4f9 100644 (file)
 #define HH_SENF_Packets_PacketRegistry_ 1
 
 // Custom includes
-#include <map>
-#include <boost/utility.hpp> // for boost::noncopyable
 #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"
 //#include "PacketRegistry.mpp"
-///////////////////////////////hh.p////////////////////////////////////////
+//-/////////////////////////////////////////////////////////////////////////////////////////////////
 
 namespace senf {
 
@@ -86,6 +85,7 @@ namespace senf {
      */
     template <class Tag>
     class PacketRegistry
+        : private senf::singleton< PacketRegistry<Tag> >
     {
     public:
         typedef typename detail::PacketRegistryImpl<typename Tag::key_t>::iterator iterator;
@@ -97,7 +97,7 @@ namespace senf {
             directly, define a symbol in the following way:
             \code
             namespace {
-                senf::PacketRegistry<Tag>::RegistrationProxy<PacketType>
+                senf::PacketRegistry<Tag>::ScopedRegistrationProxy<PacketType>
                     registerPacketType (key, optional_priority);
             }
             \endcode
@@ -110,10 +110,10 @@ namespace senf {
             of \c registerPacketType ends.
          */
         template <class PacketType>
-        struct RegistrationProxy
+        struct ScopedRegistrationProxy
         {
-            RegistrationProxy(typename Tag::key_t key, int priority=0);
-            ~RegistrationProxy();
+            ScopedRegistrationProxy(typename Tag::key_t key, int priority=0);
+            ~ScopedRegistrationProxy();
         };
 
         /** \brief Register new packet type
@@ -170,7 +170,7 @@ namespace senf {
 
             \tparam PacketType packet of which the key is requested
             \returns key of the packet wrapped in a <a
-                href="http://www.boost.org/libs/optional/doc/optional.html">boost::optional</a> or
+                href="http://www.boost.org/doc/libs/release/libs/optional/index.html">boost::optional</a> or
                 an unbound optional, if the key is not found.
          */
         template <class PacketType>
@@ -192,7 +192,7 @@ namespace senf {
 
             \param packet The packet of which the key is requested
             \returns key of the packet wrapped in a <a
-                href="http://www.boost.org/libs/optional/doc/optional.html">boost::optional</a> or
+                href="http://www.boost.org/doc/libs/release/libs/optional/index.html">boost::optional</a> or
                 an unbound optional, if the key is not found.
          */
         static typename boost::optional<typename Tag::key_t> key(Packet const & packet, NoThrow_t);
@@ -219,8 +219,16 @@ namespace senf {
         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
@@ -233,7 +241,7 @@ namespace senf {
      */
 #   define SENF_PACKET_REGISTRY_REGISTER( registry, value, type )       \
         namespace {                                                     \
-            senf::PacketRegistry< registry >::RegistrationProxy< type > \
+            senf::PacketRegistry< registry >::ScopedRegistrationProxy< type > \
             BOOST_PP_CAT(packetRegistration_, __LINE__) ( value );      \
         }
 
@@ -247,7 +255,7 @@ namespace senf {
      */
 #   define SENF_PACKET_REGISTRY_REGISTER_PRIORITY( registry, value, priority, type ) \
         namespace {                                                     \
-            senf::PacketRegistry< registry >::RegistrationProxy< type > \
+            senf::PacketRegistry< registry >::ScopedRegistrationProxy< type > \
             BOOST_PP_CAT(packetRegistration_, __LINE__) ( value, priority ); \
         }
 
@@ -267,7 +275,7 @@ namespace senf {
 
 }
 
-///////////////////////////////hh.e////////////////////////////////////////
+//-/////////////////////////////////////////////////////////////////////////////////////////////////
 #endif
 #if !defined(HH_SENF_Packets_Packets__decls_) && !defined(HH_SENF_Packets_PacketRegistry_i_)
 #define HH_SENF_Packets_PacketRegistry_i_