Packets: Add 'name()' member to packet registry entries
g0dil [Sun, 10 Feb 2008 18:30:58 +0000 (18:30 +0000)]
git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@678 270642c3-0616-0410-b53a-bc976706d245

Packets/PacketRegistry.ct
Packets/PacketRegistry.hh
Packets/PacketRegistry.ih

index 2f598ce..2cd02f8 100644 (file)
@@ -28,6 +28,7 @@
 // Custom includes
 #include "../Utils/senfassert.hh"
 #include <iostream>
+#include "../Utils/TypeInfo.hh"
 
 #define prefix_
 ///////////////////////////////ct.p////////////////////////////////////////
@@ -39,6 +40,13 @@ prefix_ senf::PacketInterpreterBase::factory_t senf::detail::PkReg_EntryImpl<Pac
     return PacketType::factory();
 }
 
+template <class PacketType>
+prefix_ std::string senf::detail::PkReg_EntryImpl<PacketType>::name()
+    const
+{
+    return prettyName(typeid(PacketType));
+}
+
 template <class KeyType>
 template <class PacketType>
 prefix_ void senf::detail::PacketRegistryImpl<KeyType>::registerPacket(key_t key)
index 8233d66..2ae1fa3 100644 (file)
@@ -48,6 +48,7 @@ namespace senf {
         virtual ~PkReg_Entry();
         virtual Packet::factory_t factory() const = 0;
                                         ///< Get factory of the registered packet type
+        virtual std::string name() const = 0;
     };
 
     namespace detail { template <class Key> class PacketRegistryImpl; }
index 0055983..7d23bfd 100644 (file)
@@ -44,6 +44,7 @@ namespace detail {
         : public PkReg_Entry
     {
         virtual Packet::factory_t factory() const;
+        virtual std::string name() const;
     };
 
     /** \brief Internal: Singleton class implementing the packet registry.
@@ -55,13 +56,18 @@ namespace detail {
         : private boost::noncopyable
     {
     public:
-        ///////////////////////////////////////////////////////////////////////////
-        // Types
-
         typedef KeyType key_t;
-
         typedef PkReg_Entry Entry;
 
+    private:
+        typedef boost::intrusive_ptr<Entry> Entry_ptr;
+        typedef std::map<key_t, Entry_ptr> PacketMap;
+        typedef std::map<senf::TypeIdValue, key_t> ReversePacketMap;
+
+    public:
+        ///////////////////////////////////////////////////////////////////////////
+        // Types
+
         ///////////////////////////////////////////////////////////////////////////
         ///\name Structors and default members
         ///@{
@@ -87,10 +93,6 @@ namespace detail {
     protected:
 
     private:
-        typedef boost::intrusive_ptr<Entry> Entry_ptr;
-        typedef std::map<key_t, Entry_ptr> PacketMap;
-        typedef std::map<senf::TypeIdValue, key_t> ReversePacketMap;
-
         PacketMap registry_;
         ReversePacketMap reverseRegistry_;
     };