// $Id$
//
-// Copyright (C) 2007
-// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
-// Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
+// Copyright (C) 2007
+// Fraunhofer Institute for Open Communication Systems (FOKUS)
+// Competence Center NETwork research (NET), St. Augustin, GERMANY
// Stefan Bund <g0dil@berlios.be>
//
// This program is free software; you can redistribute it and/or modify
here. The size of the interpreted is given by
<tt>senf::bytes(</tt><em>parser
instance</em><tt>)</tt>. */
+
+ data_iterator i(size_type offset) const; ///< Return iterator \a offset bytes from the start
+ /**< The return value is the same as i() + \a
+ offset. However, the parser checks, that the iterator is
+ still within range of the raw data
+ container. Otherwise a TruncatedPacketException is
+ thrown.
+
+ \throws TruncatedPacketException if the raw data
+ container does not hold at least \a offset bytes
+ starting at i(). */
+
state_type state() const; ///< Return state of this parser
/**< The value returned should be interpreted as an opaque
value provided just to be forwarded to other
parsers. */
+
PacketData & data() const; ///< Access the packets raw data container
/**< This member will return the raw data container holding
the data which is parsed by \c this parser. */
/**< This is the constructor used by most parsers. The
parameters are just forwarded from the derived classes
constructor parameters. */
+
PacketParserBase(data_iterator i, state_type s, size_type size);
///< Size checking constructor
/**< In addition to the standard constructor, this
bool check(size_type size) const; ///< Check size of data container
/**< \returns \c true, if the data container holds at least
\a size beginning at i(), \c false otherwise. */
+
void validate(size_type size) const; ///< Validate size of data container
/**< \throws TruncatedPacketException if the raw data
container does not hold at least \a size bytes
/**< Creates a new instance of \a Parser to parse data
beginning at \a i. Automatically passes \a state() to
the new parser. */
+
template <class Parser> Parser parse(size_type n) const; ///< Create sub-parser
/**< Creates a new instance of \a Parser to parse data
* beginning at i()<tt> + </tt>\a n. Automatically passes \a
parsers if needed. */
Packet packet() const; ///< Get packet this parser is parsing from
- /**< \important This member should only be used from packet
+ /**< \note This member should only be used from packet
parsers when access to previous or following packets is
needed e.g. for calculating checksums etc. */
SENF_PARSER_FINALIZE(VoidPacketParser);
};
- /** \brief Iterator re-validating Parser wrapper
-
- An ordinary parser will be invalidated whenever the raw data container's size is
- changed. This can complicate some algorithms considerably.
-
- This wrapper will update the parsers iterator (the value returned by the i() member) on
- every access. This ensures that the iterator will stay valid.
-
- \attention Beware however, if you insert or remove data before the safe wrapper, the
- location will \e not be updated accordingly and therefore the parser will be
- invalid.
-
- Additionally a SafePacketParserWrapper has an uninitialized state. The only allowed operations in
- this state are the boolean test for validity and assigning another parser.
-
- \ingroup packetparser
- */
- template <class Parser>
- class SafePacketParserWrapper
- : public safe_bool< SafePacketParserWrapper<Parser> >
- {
- public:
- ///////////////////////////////////////////////////////////////////////////
- // Types
-
- ///////////////////////////////////////////////////////////////////////////
- ///\name Structors and default members
- ///@{
-
- // default copy constructor
- // default copy assignment
- // default destructor
- SafePacketParserWrapper(); ///< Create an empty uninitialized SafePacketParserWrapper
-
- // conversion constructors
- SafePacketParserWrapper(Parser parser); ///< Initialize SafePacketParserWrapper from \a parser
-
- SafePacketParserWrapper & operator=(Parser parser); ///< Assign \a parser to \c this
-
- ///@}
- ///////////////////////////////////////////////////////////////////////////
-
- Parser operator*() const; ///< Access the stored parser
- /**< On every access, the stored parsers iterator will be
- updated / re-validated. */
- Parser const * operator->() const; ///< Access the stored parser
- /**< On every access, the stored parsers iterator will be
- updated / re-validated. */
- bool boolean_test() const; ///< Check validity
-
- protected:
-
- private:
- mutable boost::optional<Parser> parser_;
- senf::safe_data_iterator i_;
- };
-
}
///////////////////////////////hh.e////////////////////////////////////////