X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Packets%2FParseInt.hh;h=86a3730695f7b03fd089e114199fc91cd0df03a3;hb=2c10a733c69cd95e10a312a471c84d07d52b7755;hp=ba13aafcc47deaa51f38a22978bd0d67043a4f46;hpb=ac6a813d9d99f7add4e13aff7a4bcd314d5604a6;p=senf.git diff --git a/Packets/ParseInt.hh b/Packets/ParseInt.hh index ba13aaf..86a3730 100644 --- a/Packets/ParseInt.hh +++ b/Packets/ParseInt.hh @@ -1,6 +1,6 @@ // $Id$ // -// Copyright (C) 2006 +// Copyright (C) 2006 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) // Kompetenzzentrum fuer Satelitenkommunikation (SatCom) // Stefan Bund @@ -24,10 +24,11 @@ #define HH_ParseInt_ 1 // Custom includes -#include "ParserBase.hh" +#include #include #include #include +#include "PacketParser.hh" //#include "ParseInt.mpp" ///////////////////////////////hh.p//////////////////////////////////////// @@ -35,275 +36,225 @@ namespace senf { - - template struct Parse_Int8 - : public impl::ParseIntOps,boost::int8_t>, - public ParserBase - { - template - struct rebind { typedef Parse_Int8 parser; }; - typedef Iterator byte_iterator; - - static unsigned bytes() { return 1; } - - Parse_Int8() {} - explicit Parse_Int8(Iterator const & i) : ParserBase(i) {} + : public detail::packet::ParseIntOps, + public PacketParserBase + { + Parse_Int8(data_iterator i, state_type s) : PacketParserBase(i,s,fixed_bytes) {} /////////////////////////////////////////////////////////////////////////// typedef boost::int8_t value_type; + static size_type const fixed_bytes = 1; - value_type value() const { return this->i()[0]; } - void value(value_type v) { this->i()[0] = v; } + value_type value() const { return i()[0]; } + void value(value_type v) { i()[0] = v; } Parse_Int8 const & operator= (value_type other) { value(other); return *this; } }; + inline std::ostream & operator<<(std::ostream & os, Parse_Int8 const & i) + { os << i.value(); return os; } - template struct Parse_UInt8 - : public impl::ParseIntOps,boost::uint8_t>, - public ParserBase + : public detail::packet::ParseIntOps, + public PacketParserBase { - template - struct rebind { typedef Parse_UInt8 parser; }; - typedef Iterator byte_iterator; - - static unsigned bytes() { return 1; } - - Parse_UInt8() {} - explicit Parse_UInt8(Iterator const & i) : ParserBase(i) {} + Parse_UInt8(data_iterator i, state_type s) : PacketParserBase(i,s,fixed_bytes) {} /////////////////////////////////////////////////////////////////////////// typedef boost::uint8_t value_type; + static size_type const fixed_bytes = 1; - value_type value() const { return this->i()[0]; } - void value(value_type v) { this->i()[0] = v; } + value_type value() const { return i()[0]; } + void value(value_type v) { i()[0] = v; } Parse_UInt8 const & operator= (value_type other) { value(other); return *this; } }; + inline std::ostream & operator<<(std::ostream & os, Parse_UInt8 const & i) + { os << i.value(); return os; } - template struct Parse_Int16 - : public impl::ParseIntOps,boost::int16_t>, - public ParserBase + : public detail::packet::ParseIntOps, + public PacketParserBase { - template - struct rebind { typedef Parse_Int16 parser; }; - typedef Iterator byte_iterator; - - static unsigned bytes() { return 2; } - - Parse_Int16() {} - explicit Parse_Int16(Iterator const & i) : ParserBase(i) {} + Parse_Int16(data_iterator i, state_type s) : PacketParserBase(i,s,fixed_bytes) {} /////////////////////////////////////////////////////////////////////////// typedef boost::int16_t value_type; + static size_type const fixed_bytes = 2; - value_type value() const { return impl::parse_uint16(this->i()); } - void value(value_type v) { impl::write_uint16(this->i(),v); } + value_type value() const { return detail::packet::parse_uint16(i()); } + void value(value_type v) { detail::packet::write_uint16(i(),v); } Parse_Int16 const & operator= (value_type other) { value(other); return *this; } }; + inline std::ostream & operator<<(std::ostream & os, Parse_Int16 const & i) + { os << i.value(); return os; } - template struct Parse_UInt16 - : public impl::ParseIntOps,boost::uint16_t>, - public ParserBase + : public detail::packet::ParseIntOps, + public PacketParserBase { - template - struct rebind { typedef Parse_UInt16 parser; }; - typedef Iterator byte_iterator; - - static unsigned bytes() { return 2; } - - Parse_UInt16() {} - explicit Parse_UInt16(Iterator const & i) : ParserBase(i) {} + Parse_UInt16(data_iterator i, state_type s) : PacketParserBase(i,s,fixed_bytes) {} /////////////////////////////////////////////////////////////////////////// typedef boost::uint16_t value_type; + static size_type const fixed_bytes = 2; - value_type value() const { return impl::parse_uint16(this->i()); } - void value(value_type v) { impl::write_uint16(this->i(),v); } + value_type value() const { return detail::packet::parse_uint16(i()); } + void value(value_type v) { detail::packet::write_uint16(i(),v); } Parse_UInt16 const & operator= (value_type other) { value(other); return *this; } }; + inline std::ostream & operator<<(std::ostream & os, Parse_UInt16 const & i) + { os << i.value(); return os; } - template struct Parse_Int24 - : public impl::ParseIntOps,boost::int32_t>, - public ParserBase + : public detail::packet::ParseIntOps, + public PacketParserBase { - template - struct rebind { typedef Parse_Int24 parser; }; - typedef Iterator byte_iterator; - - static unsigned bytes() { return 3; } - - Parse_Int24() {} - explicit Parse_Int24(Iterator const & i) : ParserBase(i) {} + Parse_Int24(data_iterator i, state_type s) : PacketParserBase(i,s,fixed_bytes) {} /////////////////////////////////////////////////////////////////////////// typedef boost::int32_t value_type; + static size_type const fixed_bytes = 3; - value_type value() const { - value_type v (impl::parse_uint24(this->i())); return v&0x800000 ? v|0xff000000 : v; } - void value(value_type v) { impl::write_uint24(this->i(),v); } + value_type value() const { + value_type v (detail::packet::parse_uint24(i())); return v&0x800000 ? v|0xff000000 : v; } + void value(value_type v) { detail::packet::write_uint24(i(),v); } Parse_Int24 const & operator= (value_type other) { value(other); return *this; } }; + inline std::ostream & operator<<(std::ostream & os, Parse_Int24 const & i) + { os << i.value(); return os; } - template struct Parse_UInt24 - : public impl::ParseIntOps,boost::uint32_t>, - public ParserBase + : public detail::packet::ParseIntOps, + public PacketParserBase { - template - struct rebind { typedef Parse_UInt24 parser; }; - typedef Iterator byte_iterator; - - static unsigned bytes() { return 3; } - - Parse_UInt24() {} - explicit Parse_UInt24(Iterator const & i) : ParserBase(i) {} + Parse_UInt24(data_iterator i, state_type s) : PacketParserBase(i,s,fixed_bytes) {} /////////////////////////////////////////////////////////////////////////// typedef boost::uint32_t value_type; + static size_type const fixed_bytes = 3; - value_type value() const { return impl::parse_uint24(this->i()); } - void value(value_type v) { impl::write_uint24(this->i(),v); } + value_type value() const { return detail::packet::parse_uint24(i()); } + void value(value_type v) { detail::packet::write_uint24(i(),v); } Parse_UInt24 const & operator= (value_type other) { value(other); return *this; } }; + inline std::ostream & operator<<(std::ostream & os, Parse_UInt24 const & i) + { os << i.value(); return os; } - template struct Parse_Int32 - : public impl::ParseIntOps,boost::int32_t>, - public ParserBase + : public detail::packet::ParseIntOps, + public PacketParserBase { - template - struct rebind { typedef Parse_Int32 parser; }; - typedef Iterator byte_iterator; - - static unsigned bytes() { return 4; } - - Parse_Int32() {} - explicit Parse_Int32(Iterator const & i) : ParserBase(i) {} + Parse_Int32(data_iterator i, state_type s) : PacketParserBase(i,s,fixed_bytes) {} /////////////////////////////////////////////////////////////////////////// typedef boost::int32_t value_type; + static size_type const fixed_bytes = 4; - value_type value() const { return impl::parse_uint32(this->i()); } - void value(value_type v) { impl::write_uint32(this->i(),v); } + value_type value() const { return detail::packet::parse_uint32(i()); } + void value(value_type v) { detail::packet::write_uint32(i(),v); } Parse_Int32 const & operator= (value_type other) { value(other); return *this; } }; + inline std::ostream & operator<<(std::ostream & os, Parse_Int32 const & i) + { os << i.value(); return os; } - template struct Parse_UInt32 - : public impl::ParseIntOps,boost::uint32_t>, - public ParserBase + : public detail::packet::ParseIntOps, + public PacketParserBase { - template - struct rebind { typedef Parse_UInt32 parser; }; - typedef Iterator byte_iterator; - - static unsigned bytes() { return 4; } - - Parse_UInt32() {} - explicit Parse_UInt32(Iterator const & i) : ParserBase(i) {} + Parse_UInt32(data_iterator i, state_type s) : PacketParserBase(i,s,fixed_bytes) {} /////////////////////////////////////////////////////////////////////////// typedef boost::uint32_t value_type; + static size_type const fixed_bytes = 4; - value_type value() const { return impl::parse_uint32(this->i()); } - void value(value_type v) { impl::write_uint32(this->i(),v); } + value_type value() const { return detail::packet::parse_uint32(i()); } + void value(value_type v) { detail::packet::write_uint32(i(),v); } Parse_UInt32 const & operator= (value_type other) { value(other); return *this; } }; + inline std::ostream & operator<<(std::ostream & os, Parse_UInt32 const & i) + { os << i.value(); return os; } - template + template struct Parse_IntField - : public impl::ParseIntOps,boost::int32_t>, - public ParserBase + : public detail::packet::ParseIntOps,boost::int32_t>, + public PacketParserBase { - template - struct rebind { typedef Parse_IntField parser; }; - typedef Iterator byte_iterator; - - static unsigned bytes() { return (end-1)/8+1; } - - Parse_IntField() {} - explicit Parse_IntField(Iterator const & i) : ParserBase(i) {} + Parse_IntField(data_iterator i, state_type s) : PacketParserBase(i,s,fixed_bytes) {} /////////////////////////////////////////////////////////////////////////// typedef boost::int32_t value_type; + static size_type const fixed_bytes = (End-1)/8+1; - value_type value() const { - value_type v (impl::parse_bitfield::parse(this->i())); - return v&boost::high_bit_mask_t::high_bit ? - v | ~boost::low_bits_mask_t::sig_bits : v; + value_type value() const { + value_type v (detail::packet::parse_bitfield::parse(i())); + return v&boost::high_bit_mask_t::high_bit ? + v | ~boost::low_bits_mask_t::sig_bits : v; } - void value(value_type v) { impl::parse_bitfield::write(this->i(),v); } + void value(value_type v) { detail::packet::parse_bitfield::write(i(),v); } Parse_IntField const & operator= (value_type other) { value(other); return *this; } private: - BOOST_STATIC_ASSERT( start + inline std::ostream & operator<<(std::ostream & os, Parse_IntField const & i) + { os << i.value(); return os; } - template + template struct Parse_UIntField - : public impl::ParseIntOps,boost::uint32_t>, - public ParserBase + : public detail::packet::ParseIntOps,boost::uint32_t>, + public PacketParserBase { - template - struct rebind { typedef Parse_UIntField parser; }; - typedef Iterator byte_iterator; - - static unsigned bytes() { return (end-1)/8+1; } - - Parse_UIntField() {} - explicit Parse_UIntField(Iterator const & i) : ParserBase(i) {} + Parse_UIntField(data_iterator i, state_type s) : PacketParserBase(i,s,fixed_bytes) {} /////////////////////////////////////////////////////////////////////////// typedef boost::uint32_t value_type; + static size_type const fixed_bytes = (End-1)/8+1; - value_type value() const { return impl::parse_bitfield::parse(this->i()); } - void value(value_type v) { impl::parse_bitfield::write(this->i(),v); } + value_type value() const { return detail::packet::parse_bitfield::parse(i()); } + void value(value_type v) { detail::packet::parse_bitfield::write(i(),v); } Parse_UIntField const & operator= (value_type other) { value(other); return *this; } private: - BOOST_STATIC_ASSERT( start + inline std::ostream & operator<<(std::ostream & os, Parse_UIntField const & i) + { os << i.value(); return os; } - template + template struct Parse_Flag - : public impl::ParseIntOps,bool>, - public ParserBase + : public detail::packet::ParseIntOps,bool>, + public PacketParserBase { - template - struct rebind { typedef Parse_Flag parser; }; - typedef Iterator byte_iterator; - - static unsigned bytes() { return 1; } - - Parse_Flag() {} - explicit Parse_Flag(Iterator const & i) : ParserBase(i) {} + Parse_Flag(data_iterator i, state_type s) : PacketParserBase(i,s,fixed_bytes) {} /////////////////////////////////////////////////////////////////////////// typedef bool value_type; + static size_type const fixed_bytes = bit/8+1; - value_type value() const { return this->i()[bit/8] & (1<<(7-(bit%8))); } - void value(value_type v) { - if (v) this->i()[0] |= 1<<(7-(bit%8)); - else this->i()[0] &= ~(1<<(7-(bit%8))); + value_type value() const { return i()[bit/8] & (1<<(7-(bit%8))); } + void value(value_type v) { + if (v) i()[0] |= 1<<(7-(bit%8)); + else i()[0] &= ~(1<<(7-(bit%8))); } Parse_Flag const & operator= (value_type other) { value(other); return *this; } }; + template + inline std::ostream & operator<<(std::ostream & os, Parse_Flag const & i) + { os << i.value(); return os; } } @@ -316,5 +267,10 @@ namespace senf { // Local Variables: // mode: c++ +// fill-column: 100 // c-file-style: "senf" +// indent-tabs-mode: nil +// ispell-local-dictionary: "american" +// compile-command: "scons -u test" +// comment-column: 40 // End: