From: tho Date: Wed, 9 Jun 2010 14:59:38 +0000 (+0000) Subject: Packets: added ValueParserBase; documentation missing X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=fe035ea968fc80d7822631f0da38378dfc929ec2;p=senf.git Packets: added ValueParserBase; documentation missing git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1636 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/senf/Packets/DefaultBundle/EthernetPacket.hh b/senf/Packets/DefaultBundle/EthernetPacket.hh index b38edfc..5a38c98 100644 --- a/senf/Packets/DefaultBundle/EthernetPacket.hh +++ b/senf/Packets/DefaultBundle/EthernetPacket.hh @@ -43,21 +43,15 @@ namespace senf { \see MACAddress \n EthernetPacket */ - struct MACAddressParser : public PacketParserBase + struct MACAddressParser + : public ValueParserBase { - MACAddressParser(data_iterator i, state_type s) : PacketParserBase(i,s,fixed_bytes) {} - - /////////////////////////////////////////////////////////////////////////// - - typedef MACAddress value_type; - static const size_type fixed_bytes = 6u; + MACAddressParser(data_iterator i, state_type s) : Base(i,s) {} value_type value() const { return MACAddress::from_data(i()); } void value(value_type const & v) { std::copy(v.begin(), v.end(), i()); } - operator value_type () { return value(); } - byte & operator[](size_type index) { return *boost::next(i(),index); } - MACAddressParser const & operator= (value_type const & other) { value(other); return *this; } + using Base::operator=; }; /** \brief Parse an Ethernet packet diff --git a/senf/Packets/DefaultBundle/IPv4Packet.hh b/senf/Packets/DefaultBundle/IPv4Packet.hh index 819e080..39eaffb 100644 --- a/senf/Packets/DefaultBundle/IPv4Packet.hh +++ b/senf/Packets/DefaultBundle/IPv4Packet.hh @@ -39,21 +39,15 @@ namespace senf { \see INet4Address */ - struct INet4AddressParser : public PacketParserBase + struct INet4AddressParser + : public ValueParserBase { - INet4AddressParser(data_iterator i, state_type s) : PacketParserBase(i,s,fixed_bytes) {} - - /////////////////////////////////////////////////////////////////////////// - - typedef INet4Address value_type; - static const size_type fixed_bytes = 4u; + INet4AddressParser(data_iterator i, state_type s) : Base(i,s) {} value_type value() const { return value_type::from_data(i()); } void value(value_type const & v) { std::copy(v.begin(), v.end(), i()); } - operator value_type() const { return value(); } - byte & operator[](size_type index) const { return *boost::next(i(),index); } - INet4AddressParser const & operator= (value_type const & other) - { value(other); return *this; } + + using Base::operator=; }; /** \brief Parse an IPv4 packet diff --git a/senf/Packets/DefaultBundle/IPv6Packet.hh b/senf/Packets/DefaultBundle/IPv6Packet.hh index ef8663d..ac9560b 100644 --- a/senf/Packets/DefaultBundle/IPv6Packet.hh +++ b/senf/Packets/DefaultBundle/IPv6Packet.hh @@ -40,21 +40,15 @@ namespace senf { \see INet6Address */ - struct INet6AddressParser : public PacketParserBase + struct INet6AddressParser + : public ValueParserBase { - INet6AddressParser(data_iterator i, state_type s) : PacketParserBase(i,s,fixed_bytes) {} - - /////////////////////////////////////////////////////////////////////////// - - typedef INet6Address value_type; - static const size_type fixed_bytes = 16u; + INet6AddressParser(data_iterator i, state_type s) : Base(i,s) {} value_type value() const { return value_type::from_data(i()); } void value(value_type const & v) { std::copy(v.begin(), v.end(), i()); } - operator value_type() const { return value(); } - byte & operator[](size_type index) const { return *boost::next(i(),index); } - INet6AddressParser const & operator= (value_type const & other) - { value(other); return *this; } + + using Base::operator=; }; /** \brief Parse an IPv6 packet diff --git a/senf/Packets/PacketParser.cti b/senf/Packets/PacketParser.cti index fb53bb1..ca2a4c4 100644 --- a/senf/Packets/PacketParser.cti +++ b/senf/Packets/PacketParser.cti @@ -113,6 +113,36 @@ senf::detail::packetParserSize(Parser p, int, senf::mpl::take_uint + +template +prefix_ senf::ValueParserBase::ValueParserBase(data_iterator i, state_type s) + : PacketParserBase(i, s, FixedBytes) +{ } + +template +prefix_ senf::ValueParserBase::operator value_type () + const +{ + return static_cast(this)->value(); +} + +template +prefix_ senf::PacketParserBase::byte & +senf::ValueParserBase::operator[](size_type index) +{ + return *boost::next(i(), index); +} + +template +prefix_ Parser const & senf::ValueParserBase::operator= (value_type const & other) +{ + static_cast(this)->value(other); + return *static_cast(this); +} + ///////////////////////////////cti.e/////////////////////////////////////// #undef prefix_ diff --git a/senf/Packets/PacketParser.hh b/senf/Packets/PacketParser.hh index 2e8547c..93311c0 100644 --- a/senf/Packets/PacketParser.hh +++ b/senf/Packets/PacketParser.hh @@ -518,6 +518,22 @@ namespace senf { SENF_PARSER_FINALIZE(VoidPacketParser); }; + + template + struct ValueParserBase : public PacketParserBase + { + typedef ValueParserBase Base; + + static size_type const fixed_bytes = FixedBytes; + typedef ValueType value_type; + + ValueParserBase(data_iterator i, state_type s); + + operator value_type () const; + byte & operator[](size_type index); + Parser const & operator= (value_type const & other); + }; + } ///////////////////////////////hh.e////////////////////////////////////////