4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@berlios.de>
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 \brief VariantParser inline template implementation */
26 #include "VariantParser.ih"
29 #include "../Utils/senfassert.hh"
30 #include <boost/mpl/size.hpp>
32 #define prefix_ inline
33 ///////////////////////////////cti.p///////////////////////////////////////
35 ///////////////////////////////////////////////////////////////////////////
36 // senf::VariantParser<VariantPolicy,SENF_PARSE_VARIANT_TPL_ARGS(P)>
38 template <class VariantPolicy, SENF_PARSE_VARIANT_TPL_ARGS(class P)>
39 prefix_ senf::VariantParser<VariantPolicy,SENF_PARSE_VARIANT_TPL_ARGS(P)>::
40 VariantParser(data_iterator i, state_type s)
41 : PacketParserBase(i,s)
44 template <class VariantPolicy, SENF_PARSE_VARIANT_TPL_ARGS(class P)>
45 prefix_ senf::VariantParser<VariantPolicy,SENF_PARSE_VARIANT_TPL_ARGS(P)>::
46 VariantParser(VariantPolicy policy, data_iterator i, state_type s)
47 : PacketParserBase(i,s), VariantPolicy(policy)
50 template <class VariantPolicy, SENF_PARSE_VARIANT_TPL_ARGS(class P)>
51 prefix_ senf::PacketParserBase::size_type
52 senf::VariantParser<VariantPolicy,SENF_PARSE_VARIANT_TPL_ARGS(P)>::bytes()
55 return detail::VariantBytes< VariantParser, boost::mpl::size<parsers>::value - 1 >
56 ::bytes(*this, variant()) + VariantPolicy::bytes(i(),state());
59 template <class VariantPolicy, SENF_PARSE_VARIANT_TPL_ARGS(class P)>
61 senf::VariantParser<VariantPolicy,SENF_PARSE_VARIANT_TPL_ARGS(P)>::init()
63 VariantPolicy::variant(0,i(),state());
67 template <class VariantPolicy, SENF_PARSE_VARIANT_TPL_ARGS(class P)>
68 prefix_ unsigned senf::VariantParser<VariantPolicy,SENF_PARSE_VARIANT_TPL_ARGS(P)>::variant()
71 return VariantPolicy::variant(i(),state());
74 template <class VariantPolicy, SENF_PARSE_VARIANT_TPL_ARGS(class P)>
76 prefix_ typename boost::mpl::at<
77 typename senf::VariantParser<VariantPolicy,SENF_PARSE_VARIANT_TPL_ARGS(P)>::parsers,
78 boost::mpl::int_<N> >::type
79 senf::VariantParser<VariantPolicy,SENF_PARSE_VARIANT_TPL_ARGS(P)>::get()
82 SENF_ASSERT( variant() == N );
83 return typename boost::mpl::at<parsers, boost::mpl::int_<N> >::type(
84 VariantPolicy::begin(i(), state()), state() );
87 /////////////////////////////////////////////////////////////////////////
88 // senf::detail::VariantBytes<Variant,N>
90 template <class Variant, unsigned N>
91 prefix_ senf::PacketParserBase::size_type
92 senf::detail::VariantBytes<Variant,N>::bytes(Variant const & v, unsigned n)
95 return senf::bytes(v.template get<N>());
97 return VariantBytes<Variant, N-1>::bytes(v, n);
100 template <class Variant>
101 prefix_ senf::PacketParserBase::size_type
102 senf::detail::VariantBytes<Variant,0>::bytes(Variant const & v, unsigned n)
104 return senf::bytes(v.template get<0>());
107 ///////////////////////////////cti.e///////////////////////////////////////
114 // comment-column: 40
115 // c-file-style: "senf"
116 // indent-tabs-mode: nil
117 // ispell-local-dictionary: "american"
118 // compile-command: "scons -u test"