4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at
9 // http://senf.berlios.de/license.html
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on,
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
15 // Software distributed under the License is distributed on an "AS IS" basis,
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
17 // for the specific language governing rights and limitations under the License.
19 // The Original Code is Fraunhofer FOKUS code.
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V.
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
26 // Stefan Bund <g0dil@berlios.de>
29 \brief VariantParser inline template implementation */
31 #include "VariantParser.ih"
34 #include <senf/Utils/senfassert.hh>
35 #include <boost/mpl/size.hpp>
37 #define prefix_ inline
38 //-/////////////////////////////////////////////////////////////////////////////////////////////////
40 //-/////////////////////////////////////////////////////////////////////////////////////////////////
41 // senf::VariantParser<AuxPolicy,Parsers>
43 template <class AuxPolicy, class Parsers>
44 prefix_ senf::VariantParser<AuxPolicy,Parsers>::
45 VariantParser(data_iterator i, state_type s)
46 : PacketParserBase(i,s)
49 template <class AuxPolicy, class Parsers>
50 prefix_ senf::VariantParser<AuxPolicy,Parsers>::
51 VariantParser(AuxPolicy policy, data_iterator i, state_type s)
52 : PacketParserBase(i,s), AuxPolicy(policy)
55 template <class AuxPolicy, class Parsers>
56 prefix_ senf::PacketParserBase::size_type
57 senf::VariantParser<AuxPolicy,Parsers>::bytes()
60 return detail::VariantBytes< VariantParser, boost::mpl::size<parsers>::value - 1 >
61 ::bytes(*this, variant()) + AuxPolicy::aux_bytes;
64 template <class AuxPolicy, class Parsers>
66 senf::VariantParser<AuxPolicy,Parsers>::init()
68 AuxPolicy::aux(0,i(),state());
72 template <class AuxPolicy, class Parsers>
73 prefix_ unsigned senf::VariantParser<AuxPolicy,Parsers>::variant()
76 return AuxPolicy::aux(i(),state());
79 template <class AuxPolicy, class Parsers>
81 prefix_ typename boost::mpl::at<
82 typename senf::VariantParser<AuxPolicy,Parsers>::parsers,
83 boost::mpl::int_<N> >::type
84 senf::VariantParser<AuxPolicy,Parsers>::get()
87 SENF_ASSERT( variant() == N, "Access to non-active variant member" );
88 return typename boost::mpl::at<parsers, boost::mpl::int_<N> >::type(
89 AuxPolicy::adjust(i(), state()), state() );
92 //-/////////////////////////////////////////////////////////////////////////////////////////////////
93 // senf::detail::VariantBytes<Variant,N>
95 template <class Variant, unsigned N>
96 prefix_ senf::PacketParserBase::size_type
97 senf::detail::VariantBytes<Variant,N>::bytes(Variant const & v, unsigned n)
100 return senf::bytes(v.template get<N>());
102 return VariantBytes<Variant, N-1>::bytes(v, n);
105 template <class Variant>
106 prefix_ senf::PacketParserBase::size_type
107 senf::detail::VariantBytes<Variant,0>::bytes(Variant const & v, unsigned n)
109 return senf::bytes(v.template get<0>());
112 //-/////////////////////////////////////////////////////////////////////////////////////////////////
113 // senf::detail::VariantKeyTransform<T,Keys>
115 template <class T, class Keys>
116 prefix_ unsigned senf::detail::VariantKeyTransform<T,Keys>::get(input_type v)
118 return VariantKeyTransformCheck<
119 input_type, value_type, Keys, boost::mpl::size<Keys>::type::value-1>::get(v);
122 template <class T, class Keys>
123 prefix_ typename senf::detail::VariantKeyTransform<T,Keys>::input_type
124 senf::detail::VariantKeyTransform<T,Keys>::set(unsigned v)
126 return VariantKeyTransformCheck<
127 input_type, value_type, Keys, boost::mpl::size<Keys>::type::value-1>::set(v);
130 template <class In, class Out, class Keys, unsigned N>
131 prefix_ Out senf::detail::VariantKeyTransformCheck<In,Out,Keys,N>::get(In v)
133 if (boost::mpl::at<Keys, boost::mpl::int_<N> >::type::key() == v)
136 return VariantKeyTransformCheck<In, Out, Keys, N-1>::get(v);
139 template <class In, class Out, class Keys, unsigned N>
140 prefix_ In senf::detail::VariantKeyTransformCheck<In,Out,Keys,N>::set(Out v)
143 return boost::mpl::at<Keys, boost::mpl::int_<N> >::type::key();
145 return VariantKeyTransformCheck<In, Out, Keys, N-1>::set(v);
148 template <class In, class Out, class Keys>
149 prefix_ Out senf::detail::VariantKeyTransformCheck<In, Out, Keys, 0>::get(In v)
154 template <class In, class Out, class Keys>
155 prefix_ In senf::detail::VariantKeyTransformCheck<In, Out, Keys, 0>::set(Out v)
157 return boost::mpl::at<Keys, boost::mpl::int_<0> >::type::key();
160 //-/////////////////////////////////////////////////////////////////////////////////////////////////
167 // comment-column: 40
168 // c-file-style: "senf"
169 // indent-tabs-mode: nil
170 // ispell-local-dictionary: "american"
171 // compile-command: "scons -u test"