// $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 <g0dil@berlios.de>
//
// This program is free software; you can redistribute it and/or modify
/** \file
\brief IntParser public header */
-#ifndef HH_IntParser_
-#define HH_IntParser_ 1
+#ifndef HH_SENF_Packets_IntParser_
+#define HH_SENF_Packets_IntParser_ 1
// Custom includes
#include <iostream>
inline std::ostream & operator<<(std::ostream & os, Int16Parser const & i)
{ os << i.value(); return os; }
+ /** \brief Parse 16bit signed byte aligned integer LSB
+ \see parseint
+ \ingroup parseint
+ */
+ struct Int16LSBParser
+ : public detail::packet::IntParserOps<Int16LSBParser,boost::int16_t>,
+ public PacketParserBase
+ {
+ Int16LSBParser(data_iterator i, state_type s) : PacketParserBase(i,s,fixed_bytes) {}
+
+ ///////////////////////////////////////////////////////////////////////////
+
+ typedef boost::int16_t value_type;
+ static size_type const fixed_bytes = 2;
+ static value_type const min_value = -32768;
+ static value_type const max_value = 32767;
+
+
+ value_type value() const { return detail::packet::parse_uint16LSB(i()); }
+ void value(value_type v) { detail::packet::write_uint16LSB(i(),v); }
+ Int16LSBParser const & operator= (value_type other) { value(other); return *this; }
+ };
+ /** \brief Write parsed value to stream
+ \related Int16Parser
+ */
+ inline std::ostream & operator<<(std::ostream & os, Int16LSBParser const & i)
+ { os << i.value(); return os; }
+
/** \brief Parse 16bit unsigned byte aligned integer
\see parseint
\ingroup parseint
inline std::ostream & operator<<(std::ostream & os, UInt16Parser const & i)
{ os << i.value(); return os; }
+ /** \brief Parse 16bit unsigned byte aligned integer LSB
+ \see parseint
+ \ingroup parseint
+ */
+ struct UInt16LSBParser
+ : public detail::packet::IntParserOps<UInt16LSBParser,boost::uint16_t>,
+ public PacketParserBase
+ {
+ UInt16LSBParser(data_iterator i, state_type s) : PacketParserBase(i,s,fixed_bytes) {}
+
+ ///////////////////////////////////////////////////////////////////////////
+
+ typedef boost::uint16_t value_type;
+ static size_type const fixed_bytes = 2;
+ static value_type const min_value = 0u;
+ static value_type const max_value = 65535u;
+
+ value_type value() const { return detail::packet::parse_uint16LSB(i()); }
+ void value(value_type v) { detail::packet::write_uint16LSB(i(),v); }
+ UInt16LSBParser const & operator= (value_type other) { value(other); return *this; }
+ };
+ /** \brief Write parsed value to stream
+ \related UInt16LSBParser
+ */
+ inline std::ostream & operator<<(std::ostream & os, UInt16LSBParser const & i)
+ { os << i.value(); return os; }
+
/** \brief Parse 24bit signed byte aligned integer
\see parseint
\ingroup parseint
inline std::ostream & operator<<(std::ostream & os, UInt32Parser const & i)
{ os << i.value(); return os; }
+ struct UInt32LSBParser
+ : public detail::packet::IntParserOps<UInt32LSBParser,boost::uint32_t>,
+ public PacketParserBase
+ {
+ UInt32LSBParser(data_iterator i, state_type s) : PacketParserBase(i,s,fixed_bytes) {}
+
+ ///////////////////////////////////////////////////////////////////////////
+
+ typedef boost::uint32_t value_type;
+ static size_type const fixed_bytes = 4;
+ static value_type const min_value = 0u;
+ static value_type const max_value = 4294967295u;
+
+ value_type value() const { return detail::packet::parse_uint32LSB(i()); }
+ void value(value_type v) { detail::packet::write_uint32LSB(i(),v); }
+ UInt32LSBParser const & operator= (value_type other) { value(other); return *this; }
+ };
+ /** \brief Write parsed value to stream
+ \related UInt32LSBParser
+ */
+ inline std::ostream & operator<<(std::ostream & os, UInt32LSBParser const & i)
+ { os << i.value(); return os; }
+
+
+
+
+ /** \brief Parse 64bit signed byte aligned integer
+ \see parseint
+ \ingroup parseint
+ */
+ struct Int64Parser
+ : public detail::packet::IntParserOps<Int64Parser,boost::int64_t>,
+ 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<UInt64Parser,boost::uint64_t>,
+ 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 64bit unsigned byte aligned integer LSB
+ \see parseint
+ \ingroup parseint
+ */
+ struct UInt64LSBParser
+ : public detail::packet::IntParserOps<UInt64LSBParser,boost::uint64_t>,
+ public PacketParserBase
+ {
+ UInt64LSBParser(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_uint64LSB(i()); }
+ void value(value_type v) { detail::packet::write_uint64LSB(i(),v); }
+ UInt64LSBParser const & operator= (value_type other) { value(other); return *this; }
+ };
+ /** \brief Write parsed value to stream
+ \related UInt64LSBParser
+ */
+ inline std::ostream & operator<<(std::ostream & os, UInt64LSBParser 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 <em>most significant bit first</em> as this is the customary
numbering used when defining packet data structures. \a Start and \a End can be \e
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 <unsigned Start, unsigned End>
{ 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 <em>most significant bit first</em> as this is the customary
numbering used when defining packet data structures. \a Start and \a End can be \e
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 <unsigned Start, unsigned End>
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; }
};
///////////////////////////////hh.e////////////////////////////////////////
#endif
-#if !defined(HH_Packets__decls_) && !defined(HH_IntParser_i_)
-#define HH_IntParser_i_
+#if !defined(HH_SENF_Packets_Packets__decls_) && !defined(HH_SENF_Packets_IntParser_i_)
+#define HH_SENF_Packets_IntParser_i_
//#include "IntParser.cci"
//#include "IntParser.ct"
//#include "IntParser.cti"
#endif
-\f
+
// Local Variables:
// mode: c++
// fill-column: 100