Packets: Packet Registry unregister() support
[senf.git] / senf / Packets / PacketRegistry.ih
index 24c9851..a1d66ba 100644 (file)
@@ -28,6 +28,7 @@
 
 // Custom includes
 #include <ext/functional>
+#include <limits>
 #include <boost/intrusive_ptr.hpp>
 #include <boost/iterator/transform_iterator.hpp>
 #include <senf/Utils/TypeIdValue.hh>
@@ -47,6 +48,7 @@ namespace senf {
         virtual Packet::factory_t factory() const = 0;
                                         ///< Get factory of the registered packet type
         virtual std::string name() const = 0;
+        virtual TypeIdValue typeIdValue() const = 0;
     };
 
 namespace detail {
@@ -61,6 +63,7 @@ namespace detail {
     {
         virtual Packet::factory_t factory() const;
         virtual std::string name() const;
+        virtual TypeIdValue typeIdValue() const ;
     };
 
     /** \brief Internal: Registry implementation base-class and registry of registries
@@ -74,13 +77,16 @@ namespace detail {
         virtual ~PacketRegistryImplBase();
 
         static void dump(std::ostream & os);
+        static void clear();
 
     protected:
         typedef std::map<std::string, PacketRegistryImplBase*>  RegistryMap;
         static RegistryMap & registries();
 
     private:
-        virtual void v_dump(std::ostream & os) = 0;
+        virtual bool v_empty() const = 0;
+        virtual void v_dump(std::ostream & os) const = 0;
+        virtual void v_clear() = 0;
     };
 
     /** \brief Internal: Singleton class implementing the packet registry.
@@ -119,6 +125,10 @@ namespace detail {
         template <class PacketType>
         void registerPacket(key_t key);
 
+        template <class PacketType>
+        void unregisterPacket();
+        void unregisterPacket(key_t key);
+
         key_t key(senf::TypeIdValue const & type);
         boost::optional<key_t> key(senf::TypeIdValue const & type, bool);
 
@@ -131,12 +141,26 @@ namespace detail {
     protected:
 
     private:
-        virtual void v_dump(std::ostream & os);
+        virtual bool v_empty() const;
+        virtual void v_dump(std::ostream & os) const;
+        virtual void v_clear();
 
         PacketMap registry_;
         ReversePacketMap reverseRegistry_;
     };
 
+    template <class KeyType, bool is_integral=std::numeric_limits<KeyType>::is_integer>
+    struct DumpKey
+    {
+        static void dump(KeyType const & v, std::ostream & os);
+    };
+
+    template <class KeyType>
+    struct DumpKey<KeyType, true>
+    {
+        static void dump(KeyType const & v, std::ostream & os);
+    };
+
 }}
 
 ///////////////////////////////ih.e////////////////////////////////////////