X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Packets%2FParseInt.ih;h=a1e961c97a096f5bde6121a5c0291e935dca2fdf;hb=05150cf5e05d2dc2c41fd531649131de7acdd2f1;hp=fd58b04bcf6ef4902ae8271e77f4fdbc6bff4c65;hpb=1835b928b179302ecb716d697fbf3fa24b415ba4;p=senf.git diff --git a/Packets/ParseInt.ih b/Packets/ParseInt.ih index fd58b04..a1e961c 100644 --- a/Packets/ParseInt.ih +++ b/Packets/ParseInt.ih @@ -1,6 +1,6 @@ // $Id$ // -// Copyright (C) 2006 +// Copyright (C) 2006 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) // Kompetenzzentrum fuer Satelitenkommunikation (SatCom) // Stefan Bund @@ -24,13 +24,14 @@ #define IH_ParseInt_ 1 // Custom includes +#include "PacketTypes.hh" ///////////////////////////////ih.p//////////////////////////////////////// -namespace satcom { -namespace pkf { -namespace impl { - +namespace senf { +namespace detail { +namespace packet { + /////////////////////////////////////////////////////////////////////////// // Integer operators @@ -43,7 +44,7 @@ namespace impl { operator Value () const { return derived().value(); } # define unary(op) \ - Value operator op () const { return op derived().value(); } + Value operator op () const { return op derived().value(); } # define mutator(op) \ template Derived const & operator op ## = (Other other) \ { derived().value( derived().value() op other ); return derived(); } @@ -65,60 +66,54 @@ namespace impl { # undef unary # undef mutator - + Derived const & operator ++ () - { derived().value( derived.value()+1 ); return derived(); } + { derived().value( derived().value()+1 ); return derived(); } Derived const & operator -- () - { derived().value( derived.value()-1 ); return derived(); } + { derived().value( derived().value()-1 ); return derived(); } - Derived const & operator ++ (int) - { Value v (derived.value()); derived().value( v+1 ); return v; } - Derived const & operator -- (int) - { Value v (derived.value()); derived().value( v-1 ); return v; } + Value operator ++ (int) + { Value v (derived().value()); derived().value( v+1 ); return v; } + Value operator -- (int) + { Value v (derived().value()); derived().value( v-1 ); return v; } private: Derived & derived() { return *static_cast(this); } Derived const & derived() const { return *static_cast(this); }; }; - + /////////////////////////////////////////////////////////////////////////// // Network byte order integer extraction - - template - boost::uint16_t parse_uint16(Iterator const & i) + + inline boost::uint16_t parse_uint16(iterator i) { return i[1] | i[0]<<8; } - template - void write_uint16(Iterator const & i, boost::uint16_t v) + inline void write_uint16(iterator i, boost::uint16_t v) { i[0] = ( v >> 8 ) & 0xff; i[1] = ( v ) & 0xff; } - template - boost::uint32_t parse_uint24(Iterator const & i) + inline boost::uint32_t parse_uint24(iterator i) { return i[2] | i[1]<<8 | i[0]<<16; } - template - void write_uint24(Iterator const & i, boost::uint32_t v) + inline void write_uint24(iterator i, boost::uint32_t v) { i[0] = ( v >> 16 ) & 0xff; i[1] = ( v >> 8 ) & 0xff; i[2] = ( v ) & 0xff; } - template - boost::uint32_t parse_uint32(Iterator const & i) + inline boost::uint32_t parse_uint32(iterator i) { return i[3] | i[2]<<8 | i[1]<<16 | i[0]<<24; } - template - void write_uint32(Iterator const & i, boost::uint32_t v) + inline void write_uint32(iterator i, boost::uint32_t v) { i[0] = ( v >> 24 ) & 0xff; i[1] = ( v >> 16 ) & 0xff; @@ -129,18 +124,22 @@ namespace impl { /////////////////////////////////////////////////////////////////////////// // bitfield extraction - template + // Doxygen doesn't like this stuff ... + +# ifndef DOXYGEN + + template struct parse_bitfield_i { - static boost::uint32_t parse(Iterator const & i) { + static boost::uint32_t parse(iterator i) { return ( ( ( parse_uint32(i+offset+1)>>(40-end) ) // Beware of sign extension !! - & boost::low_bits_mask_t<32-(40-end)>::sig_bits ) + & boost::low_bits_mask_t<32-(40-end)>::sig_bits ) | (i[offset]<<(32-(40-end))) ) & boost::low_bits_mask_t::sig_bits; } - static void write(Iterator const & i, boost::uint32_t v) { - write_uint32(i+offset+1, + static void write(iterator i, boost::uint32_t v) { + write_uint32(i+offset+1, (parse_uint32(i+offset+1) & ~(boost::low_bits_mask_t::sig_bits<<(40-end))) | ((v & boost::low_bits_mask_t::sig_bits) << (40-end))); i[offset] = (i[offset] & ~(boost::low_bits_mask_t<8-start>::sig_bits)) @@ -148,68 +147,70 @@ namespace impl { } }; - template - struct parse_bitfield_i + template + struct parse_bitfield_i { - static boost::uint32_t parse(Iterator const & i) { + static boost::uint32_t parse(iterator i) { return ( parse_uint32(i+offset)>>(32-end) ) & boost::low_bits_mask_t::sig_bits; } - static void write(Iterator const & i, boost::uint32_t v) { - write_uint32(i+offset, + static void write(iterator i, boost::uint32_t v) { + write_uint32(i+offset, (parse_uint32(i+offset) & ~(boost::low_bits_mask_t::sig_bits<<(32-end))) | ((v & boost::low_bits_mask_t::sig_bits) << (32-end))); } }; - template - struct parse_bitfield_i + template + struct parse_bitfield_i { - static boost::uint32_t parse(Iterator const & i) { + static boost::uint32_t parse(iterator i) { return ( parse_uint24(i+offset)>>(24-end) ) & boost::low_bits_mask_t::sig_bits; } - static void write(Iterator const & i, boost::uint32_t v) { - write_uint24(i+offset, + static void write(iterator i, boost::uint32_t v) { + write_uint24(i+offset, (parse_uint24(i+offset) & ~(boost::low_bits_mask_t::sig_bits<<(24-end))) | ((v & boost::low_bits_mask_t::sig_bits) << (24-end))); } }; - template - struct parse_bitfield_i + template + struct parse_bitfield_i { - static boost::uint32_t parse(Iterator const & i) { + static boost::uint32_t parse(iterator i) { return ( parse_uint16(i+offset)>>(16-end) ) & boost::low_bits_mask_t::sig_bits; } - static void write(Iterator const & i, boost::uint32_t v) { - write_uint16(i+offset, + static void write(iterator i, boost::uint32_t v) { + write_uint16(i+offset, (parse_uint16(i+offset) & ~(boost::low_bits_mask_t::sig_bits<<(16-end))) | ((v & boost::low_bits_mask_t::sig_bits) << (16-end))); } }; - template - struct parse_bitfield_i + template + struct parse_bitfield_i { - static boost::uint32_t parse(Iterator const & i) { - return ( i[offset]>>(8-end) ) + static boost::uint32_t parse(iterator i) { + return ( i[offset]>>(8-end) ) & boost::low_bits_mask_t::sig_bits; } - static void write(Iterator const & i, boost::uint32_t v) { + static void write(iterator i, boost::uint32_t v) { i[offset] = (i[offset] & ~(boost::low_bits_mask_t::sig_bits<<(8-end))) | ((v & boost::low_bits_mask_t::sig_bits) << (8-end)); } }; - template - struct parse_bitfield - : public parse_bitfield_i +# endif + + template + struct parse_bitfield + : public parse_bitfield_i {}; }}} @@ -220,5 +221,10 @@ namespace impl { // Local Variables: // mode: c++ -// c-file-style: "satcom" +// fill-column: 100 +// c-file-style: "senf" +// indent-tabs-mode: nil +// ispell-local-dictionary: "american" +// compile-command: "scons -u test" +// comment-column: 40 // End: