Packets: Add PacketParserBase::i(size_type) utility
[senf.git] / Packets / PacketType.hh
index 88768f2..e9d0d30 100644 (file)
@@ -1,6 +1,8 @@
+// $Id$
+//
 // Copyright (C) 2007 
-// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
-// Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
+// Fraunhofer Institute for Open Communication Systems (FOKUS) 
+// Competence Center NETwork research (NET), St. Augustin, GERMANY 
 //     Stefan Bund <g0dil@berlios.de>
 //
 // This program is free software; you can redistribute it and/or modify
@@ -222,8 +224,8 @@ namespace senf {
         \code
         // Here 'SomeRegistryTag' is optional
         struct SimplePacketType 
-            : public senf::PacketTypeBase
-              public senf:PacketTypeMixin<SimplePacketType, SomeRegistryTag>
+            : public senf::PacketTypeBase,
+              public senf::PacketTypeMixin<SimplePacketType, SomeRegistryTag>
         {
             typedef senf::PacketTypeMixin<SimplePacketType, SomeRegistryTag> mixin;
             typedef senf::ConcretePacket<SimplePacketType> packet;
@@ -261,7 +263,7 @@ namespace senf {
                 // member.
             }
 
-            static registry_key_t nextPacketKey(packet p)
+            static key_t nextPacketKey(packet p)
             {
                 // Return the key in the registry under which the next packet
                 // header is to be found. This member must be given if a Registry argument is
@@ -274,7 +276,7 @@ namespace senf {
                 // Set the type field by querying the type of the next packet. This is an 
                 // optional assignment: If the key is not found, the value returned by 'key'
                 // is an empty optional and the assignment will be skipped.
-                p->typeField << key(p.next());
+                p->typeField << key(p.next(senf::nothrow));
 
                 // optionally complete the packet by generating auto-generated information
                 // (like checksums)
@@ -292,8 +294,8 @@ namespace senf {
 
         \code
         struct SimplePacketType 
-            : public senf::PacketTypeBase
-              public senf:PacketTypeMixin<SimplePacketType, SomeRegistryTag>
+            : public senf::PacketTypeBase,
+              public senf::PacketTypeMixin<SimplePacketType, SomeRegistryTag>
         {
             typedef senf::PacketTypeMixin<SimplePacketType, SomeRegistryTag> mixin;
             typedef senf::ConcretePacket<SimplePacketType> packet;
@@ -304,7 +306,7 @@ namespace senf {
             using mixin::initSize;
             using mixin::init;         
 
-            static registry_key_t nextPacketKey(packet p)
+            static key_t nextPacketKey(packet p)
             { return p->typeField(); }
         };
         \endcode
@@ -318,10 +320,10 @@ namespace senf {
     class PacketTypeMixin
     {
     public:
-        typedef typename Registry::key_t registry_key_t;
-        typedef boost::optional<registry_key_t> optional_registry_key_t;
+        typedef typename Registry::key_t key_t;
+        typedef boost::optional<key_t> optional_key_t;
 
-        static optional_registry_key_t key (Packet p); ///< Find key of packet from registry
+        static optional_key_t key (Packet p); ///< Find key of packet from registry
                                         /**< key() will query the registry to find the key of the
                                              given packet. Whereas \c nextPacketKey() as implemented
                                              by the mixin user will provide the registry key of the
@@ -334,6 +336,11 @@ namespace senf {
                                              type is not found in the registry, the returned
                                              optional value will be empty. */
 
+        static PacketTypeBase::factory_t lookup (key_t key); ///< Lookup the key in the registry
+                                        /**< lookup() will query the registry and find the factory
+                                             for the given key. If the key cannot be found,
+                                             no_factory() will be returned. */
+
         ///\name PacketType interface implementation
         ///@{
 
@@ -362,10 +369,10 @@ namespace senf {
 
 ///////////////////////////////hh.e////////////////////////////////////////
 #endif
-#if !defined(SENF_PACKETS_DECL_ONLY) && !defined(HH_PacketType_i_)
+#if !defined(HH_Packets__decls_) && !defined(HH_PacketType_i_)
 #define HH_PacketType_i_
 #include "PacketType.cci"
-//#include "PacketType.ct"
+#include "PacketType.ct"
 #include "PacketType.cti"
 #endif