X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Packets%2FIntParser.hh;h=eb51170b63a3b6084f248fba8c6b88bef08e15ef;hb=a4ebeef29f8eb69dc2dad10668d762540002b924;hp=098b218fd6defa613f234ee4ef2223bb2943eacb;hpb=f73fa16ed5abdce272ac77f8b8b9ef2b9922c266;p=senf.git diff --git a/Packets/IntParser.hh b/Packets/IntParser.hh index 098b218..eb51170 100644 --- a/Packets/IntParser.hh +++ b/Packets/IntParser.hh @@ -1,8 +1,8 @@ // $Id$ // // Copyright (C) 2006 -// Fraunhofer Institute for Open Communication Systems (FOKUS) -// Competence Center NETwork research (NET), St. Augustin, GERMANY +// Fraunhofer Institute for Open Communication Systems (FOKUS) +// Competence Center NETwork research (NET), St. Augustin, GERMANY // Stefan Bund // // This program is free software; you can redistribute it and/or modify @@ -284,8 +284,60 @@ namespace senf { inline std::ostream & operator<<(std::ostream & os, UInt32Parser const & i) { os << i.value(); return os; } + /** \brief Parse 64bit signed byte aligned integer + \see parseint + \ingroup parseint + */ + struct Int64Parser + : public detail::packet::IntParserOps, + public PacketParserBase + { + Int64Parser(data_iterator i, state_type s) : PacketParserBase(i,s,fixed_bytes) {} + + /////////////////////////////////////////////////////////////////////////// + + typedef boost::int64_t value_type; + static size_type const fixed_bytes = 8; + + value_type value() const { return detail::packet::parse_uint64(i()); } + void value(value_type v) { detail::packet::write_uint64(i(),v); } + Int64Parser const & operator= (value_type other) { value(other); return *this; } + }; + /** \brief Write parsed value to stream + \related Int64Parser + */ + inline std::ostream & operator<<(std::ostream & os, Int64Parser const & i) + { os << i.value(); return os; } + + + /** \brief Parse 64bit unsigned byte aligned integer + \see parseint + \ingroup parseint + */ + struct UInt64Parser + : public detail::packet::IntParserOps, + public PacketParserBase + { + UInt64Parser(data_iterator i, state_type s) : PacketParserBase(i,s,fixed_bytes) {} + + /////////////////////////////////////////////////////////////////////////// + + typedef boost::uint64_t value_type; + static size_type const fixed_bytes = 8; + + value_type value() const { return detail::packet::parse_uint64(i()); } + void value(value_type v) { detail::packet::write_uint64(i(),v); } + UInt64Parser const & operator= (value_type other) { value(other); return *this; } + }; + /** \brief Write parsed value to stream + \related UInt64Parser + */ + inline std::ostream & operator<<(std::ostream & os, UInt64Parser const & i) + { os << i.value(); return os; } + + /** \brief Parse signed bitfield with up to 32bit's - + This parser will parse a bitfield beginning at the bit \a Start and ending \e before \a End. Bits are numbered most significant bit first as this is the customary numbering used when defining packet data structures. \a Start and \a End can be \e @@ -303,7 +355,7 @@ namespace senf { compile-time constants, the compiler will create optimized bit-masks to directly access the value. The parser is also optimized to access the minimum number of data bytes necessary. - + \ingroup parseint */ template @@ -343,7 +395,7 @@ namespace senf { { os << i.value(); return os; } /** \brief Parse unsigned bitfield with up to 32bit's - + This parser will parse a bitfield beginning at the bit \a Start and ending \e before \a End. Bits are numbered most significant bit first as this is the customary numbering used when defining packet data structures. \a Start and \a End can be \e @@ -361,7 +413,7 @@ namespace senf { compile-time constants, the compiler will create optimized bit-masks to directly access the value. The parser is also optimized to access the minimum number of data bytes necessary. - + \ingroup parseint */ template @@ -426,8 +478,8 @@ namespace senf { 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))); + if (v) i()[Bit/8] |= 1<<(7-(Bit%8)); + else i()[Bit/8] &= ~(1<<(7-(Bit%8))); } FlagParser const & operator= (value_type other) { value(other); return *this; } }; @@ -449,7 +501,7 @@ namespace senf { //#include "IntParser.cti" #endif - + // Local Variables: // mode: c++ // fill-column: 100