//
// Copyright (C) 2007
// 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
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; either version 2 of the License, or
-// (at your option) any later version.
+// The contents of this file are subject to the Fraunhofer FOKUS Public License
+// Version 1.0 (the "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+// http://senf.berlios.de/license.html
//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
+// The Fraunhofer FOKUS Public License Version 1.0 is based on,
+// but modifies the Mozilla Public License Version 1.1.
+// See the full license text for the amendments.
//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the
-// Free Software Foundation, Inc.,
-// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+// Software distributed under the License is distributed on an "AS IS" basis,
+// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+// for the specific language governing rights and limitations under the License.
+//
+// The Original Code is Fraunhofer FOKUS code.
+//
+// The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V.
+// (registered association), Hansastraße 27 c, 80686 Munich, Germany.
+// All Rights Reserved.
+//
+// Contributor(s):
+// Stefan Bund <g0dil@berlios.de>
/** \file
\brief VariantParser public header */
#include "PacketParser.hh"
//#include "VariantParser.mpp"
-///////////////////////////////hh.p////////////////////////////////////////
+//-/////////////////////////////////////////////////////////////////////////////////////////////////
namespace senf {
defined condition. This is the parser to use, if the type and/or number of fields of a
packet change depending on some condition.
\code
- typedef senf::VariantParser<
- MyAuxPolicy,
+ typedef senf::VariantParser<
+ MyAuxPolicy,
senf::mpl::vector<senf::VoidPacketParser, TypeAParser, TypeBParser> > MyVariantParser;
\endcode
This typedef defines a variant parser choosing one of three sub
When creating a new packet containing a variant parser, the variant parser will always be
initialized to the first sub-parser.
- \see
+ \see
ExampleAuxPolicy on how to implement the \a AuxPolicy \n
\ref SENF_PARSER_VARIANT() on how to integrate the parser into another parser
\ingroup parsecollection
*/
template <class AuxPolicy, class Parsers>
- class VariantParser
+ class VariantParser
: public PacketParserBase, private AuxPolicy
{
typedef Parsers parsers;
public:
///\name Parser interface
- ///\{
+ //\{
VariantParser(data_iterator i, state_type s);
VariantParser(AuxPolicy policy, data_iterator i, state_type s);
size_type bytes() const;
void init();
-
- static const size_type init_bytes = senf::init_bytes<
- typename boost::mpl::at<parsers, boost::mpl::int_<0> >::type>::value
+
+ static const size_type init_bytes = senf::init_bytes<
+ typename boost::mpl::at<parsers, boost::mpl::int_<0> >::type>::value
+ AuxPolicy::aux_bytes;
- ///\}
- ///////////////////////////////////////////////////////////////////////////
+ //\}
+ //-////////////////////////////////////////////////////////////////////////
unsigned variant() const; ///< Get current variant
/**< Get the currently selected variant index. The returned
\returns Index of currently selected variant. Integer
in the range from 0 to (number-of-sub-parsers - 1)
*/
-
+
template <unsigned N>
typename boost::mpl::at< parsers, boost::mpl::int_<N> >::type get() const;
///< Access sub-parser
struct SomeParser : public PacketParserBase
{
# include SENF_PARSER()
-
+
SENF_PARSER_PRIVATE_FIELD( type, senf::UInt8Parser );
SENF_PARSER_VARIANT( content, type,
(novalue( disable, senf::VoidPacketParser ))
SENF_PARSER_FINALIZE(SomeParser);
};
- \endcode
-
+ \endcode
+
The variant \c content chooses one of the sub parsers depending on the \c type field. If \c
- type is 0, senf::VoidPacketParser is selected, if it is 1, senf::UInt8Parser and so on.
+ type is 0, senf::VoidPacketParser is selected, if it is 1, senf::UInt8Parser and so on.
\warning Realize, that the \a chooser field is controlled by the variant parser. This field
should therefore be declared either read-only or private and must be changed only via
<tr><td><tt>void</tt> <tt>init_</tt><em>name</em>()</td><td>Set the variant to have a value
of this type. If the field is \c novalue, the \c init_ prefix is omitted.</td></tr>
-
+
<tr><td><tt>bool</tt> <tt>has_</tt><em>name</em>()</td><td>Return \c true, if the variant
currently holds this kind of value, \c false otherwise. Only if not \c novalue.</td></tr>
</table>
(senf::UInt24Parser)
(senf::UInt32Parser) );
\endcode
-
+
\param[in] name name of the field
\param[in] chooser name of the field choosing the variant to use
\param[in] types a Boost.Preprocessor style sequence of sub-parser types
- \see
- senf::VariantParser for the VariantParser API\n
+ \see
+ senf::VariantParser for the VariantParser API\n
\ref SENF_PARSER_PRIVATE_VARIANT()
\hideinitializer
\ingroup packetparsermacros
SENF_PARSER_VARIANT_I(public, name, chooser, types)
/** \brief Define private VariantParser field
-
+
\see \ref SENF_PARSER_VARIANT()
\hideinitializer
\ingroup packetparsermacros
SENF_PARSER_VARIANT_I(protected, name, chooser, types)
}
-///////////////////////////////hh.e////////////////////////////////////////
+//-/////////////////////////////////////////////////////////////////////////////////////////////////
#endif
#if !defined(HH_SENF_Packets_Packets__decls_) && !defined(HH_SENF_Packets_VariantParser_i_)
#define HH_SENF_Packets_VariantParser_i_