Packets: Adjust SENF_PARSER_VARIANT implementation for better public/private support
[senf.git] / Packets / MPEGDVBBundle / DTCPPacket.hh
index 4486d4f..5166c63 100644 (file)
@@ -1,8 +1,8 @@
 // $Id$
 //
-// Copyright (C) 2007 
-// Fraunhofer Institute for Open Communication Systems (FOKUS) 
-// Competence Center NETwork research (NET), St. Augustin, GERMANY 
+// Copyright (C) 2007
+// Fraunhofer Institute for Open Communication Systems (FOKUS)
+// Competence Center NETwork research (NET), St. Augustin, GERMANY
 //     David Wagner <dw6@berlios.de>
 //
 // This program is free software; you can redistribute it and/or modify
@@ -39,7 +39,7 @@ namespace senf {
 #       include SENF_PARSER()        
         SENF_PARSER_PRIVATE_FIELD ( num_of_fbips, UInt8Parser );
         SENF_PARSER_PRIVATE_FIELD ( reserved ,    UInt8Parser );   //must be zero 
-        SENF_PARSER_VEC_N         ( fbiplist,     num_of_fbips, INet4AddressParser );
+        SENF_PARSER_VECTOR        ( fbiplist,     num_of_fbips, INet4AddressParser );
 
         SENF_PARSER_FINALIZE(DTCPIPv4AddressListParser);
     };
@@ -48,7 +48,7 @@ namespace senf {
 #       include SENF_PARSER()        
         SENF_PARSER_PRIVATE_FIELD ( num_of_fbips, UInt8Parser );
         SENF_PARSER_PRIVATE_FIELD ( reserved,     UInt8Parser );   //must be zero 
-        SENF_PARSER_VEC_N         ( fbiplist,     num_of_fbips, INet6AddressParser );
+        SENF_PARSER_VECTOR        ( fbiplist,     num_of_fbips, INet6AddressParser );
 
         SENF_PARSER_FINALIZE(DTCPIPv6AddressListParser);
     };
@@ -86,39 +86,17 @@ namespace senf {
          *      -you NEVER can use templated Parsers in these macros since the macro-preprocessor won't recognize the <> brackets and will
          *      interpret the ","
          * 
-         * The first problem is solved by using (actually inventing)  SENF_PARSER_VARIANT_TRANS which has the same limitations 
-         *      concerning the number of types but isn't limited to the values used. This is achieved by a translating function 
-         *      as you can see. 
+         * The first problem is solved by using key()
          * The second problem is solved by introducing Helper-Parser which cover both the list and the number field. By that no 
          *      templates have to be used. 
          */
 
-        struct ip_version_translator {
-            static unsigned fromChooser(ip_version_t::value_type in) {
-                switch (in) { 
-                case 4: return 0;
-                case 6: return 1;
-                }
-                return 1; //default. should rather throw an exception 
-            }
-            static ip_version_t::value_type toChooser(unsigned in) {
-                switch (in) {
-                case 0: return 4;
-                case 1: return 6; 
-                }
-                return 6; //default. should rather throw an exception 
-            }
-        };
-    
-        SENF_PARSER_VARIANT_TRANS    ( fbiplist,             ip_version, ip_version_translator,
-                                                                 (senf::DTCPIPv4AddressListParser)        //IPv4 
-                                                                 (senf::DTCPIPv6AddressListParser) );     //IPv6
+        SENF_PARSER_VARIANT( fbiplist, ip_version,
+                                        ( ids(getIpv4AddressList, na, setIpVersion4, 
+                                      key(4, senf::DTCPIPv4AddressListParser)) )    //IPv4 
+                                ( ids(getIpv6AddressList, na, setIpVersion6,
+                                      key(6, senf::DTCPIPv6AddressListParser)) ) ); //IPv6
                                                                  
-        DTCPIPv4AddressListParser getIpv4AddressList () const { return fbiplist().get<0>(); }  // this is the absolute index 
-        DTCPIPv6AddressListParser getIpv6AddressList () const { return fbiplist().get<1>(); }
-        void setIpVersion4() const { fbiplist().init<0>(); }
-        void setIpVersion6() const { fbiplist().init<1>(); }
-
         SENF_PARSER_FINALIZE(DTCPPacketParser);
     };