\see MACAddress \n
EthernetPacket
*/
- struct MACAddressParser : public PacketParserBase
+ struct MACAddressParser
+ : public ValueParserBase<MACAddressParser, MACAddress, 6u>
{
- 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
\see INet4Address
*/
- struct INet4AddressParser : public PacketParserBase
+ struct INet4AddressParser
+ : public ValueParserBase<INet4AddressParser, INet4Address, 4u>
{
- 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
\see INet6Address
*/
- struct INet6AddressParser : public PacketParserBase
+ struct INet6AddressParser
+ : public ValueParserBase<INet6AddressParser, INet6Address, 16u>
{
- 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
return Parser::fixed_bytes;
}
+
+///////////////////////////////////////////////////////////////////////////
+// senf::ValueParserBase<Parser, ValueType, FixedBytes>
+
+template <class Parser, typename ValueType, senf::PacketParserBase::size_type FixedBytes>
+prefix_ senf::ValueParserBase<Parser, ValueType, FixedBytes>::ValueParserBase(data_iterator i, state_type s)
+ : PacketParserBase(i, s, FixedBytes)
+{ }
+
+template <class Parser, typename ValueType, senf::PacketParserBase::size_type FixedBytes>
+prefix_ senf::ValueParserBase<Parser, ValueType, FixedBytes>::operator value_type ()
+ const
+{
+ return static_cast<Parser const *>(this)->value();
+}
+
+template <class Parser, typename ValueType, senf::PacketParserBase::size_type FixedBytes>
+prefix_ senf::PacketParserBase::byte &
+senf::ValueParserBase<Parser, ValueType, FixedBytes>::operator[](size_type index)
+{
+ return *boost::next(i(), index);
+}
+
+template <class Parser, typename ValueType, senf::PacketParserBase::size_type FixedBytes>
+prefix_ Parser const & senf::ValueParserBase<Parser, ValueType, FixedBytes>::operator= (value_type const & other)
+{
+ static_cast<Parser*>(this)->value(other);
+ return *static_cast<Parser const *>(this);
+}
+
///////////////////////////////cti.e///////////////////////////////////////
#undef prefix_
SENF_PARSER_FINALIZE(VoidPacketParser);
};
+
+ template <class Parser, typename ValueType, PacketParserBase::size_type FixedBytes>
+ struct ValueParserBase : public PacketParserBase
+ {
+ typedef ValueParserBase<Parser, ValueType, FixedBytes> 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////////////////////////////////////////