2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
15 \brief VariantParser inline template implementation */
17 #include "VariantParser.ih"
20 #include <senf/Utils/senfassert.hh>
21 #include <boost/mpl/size.hpp>
23 #define prefix_ inline
24 //-/////////////////////////////////////////////////////////////////////////////////////////////////
26 //-/////////////////////////////////////////////////////////////////////////////////////////////////
27 // senf::VariantParser<AuxPolicy,Parsers>
29 template <class AuxPolicy, class Parsers>
30 prefix_ senf::VariantParser<AuxPolicy,Parsers>::
31 VariantParser(data_iterator i, state_type s)
32 : PacketParserBase(i,s)
35 template <class AuxPolicy, class Parsers>
36 prefix_ senf::VariantParser<AuxPolicy,Parsers>::
37 VariantParser(AuxPolicy policy, data_iterator i, state_type s)
38 : PacketParserBase(i,s), AuxPolicy(policy)
41 template <class AuxPolicy, class Parsers>
42 prefix_ senf::PacketParserBase::size_type
43 senf::VariantParser<AuxPolicy,Parsers>::bytes()
46 return detail::VariantBytes< VariantParser, boost::mpl::size<parsers>::value - 1 >
47 ::bytes(*this, variant()) + AuxPolicy::aux_bytes;
50 template <class AuxPolicy, class Parsers>
52 senf::VariantParser<AuxPolicy,Parsers>::init()
54 AuxPolicy::aux(0,i(),state());
58 template <class AuxPolicy, class Parsers>
59 prefix_ unsigned senf::VariantParser<AuxPolicy,Parsers>::variant()
62 return AuxPolicy::aux(i(),state());
65 template <class AuxPolicy, class Parsers>
67 prefix_ typename boost::mpl::at<
68 typename senf::VariantParser<AuxPolicy,Parsers>::parsers,
69 boost::mpl::int_<N> >::type
70 senf::VariantParser<AuxPolicy,Parsers>::get()
73 SENF_ASSERT( variant() == N, "Access to non-active variant member" );
74 return typename boost::mpl::at<parsers, boost::mpl::int_<N> >::type(
75 AuxPolicy::adjust(i(), state()), state() );
78 //-/////////////////////////////////////////////////////////////////////////////////////////////////
79 // senf::detail::VariantBytes<Variant,N>
81 template <class Variant, unsigned N>
82 prefix_ senf::PacketParserBase::size_type
83 senf::detail::VariantBytes<Variant,N>::bytes(Variant const & v, unsigned n)
86 return senf::bytes(v.template get<N>());
88 return VariantBytes<Variant, N-1>::bytes(v, n);
91 template <class Variant>
92 prefix_ senf::PacketParserBase::size_type
93 senf::detail::VariantBytes<Variant,0>::bytes(Variant const & v, unsigned n)
95 return senf::bytes(v.template get<0>());
98 //-/////////////////////////////////////////////////////////////////////////////////////////////////
99 // senf::detail::VariantKeyTransform<T,Keys>
101 template <class T, class Keys>
102 prefix_ unsigned senf::detail::VariantKeyTransform<T,Keys>::get(input_type v)
104 return VariantKeyTransformCheck<
105 input_type, value_type, Keys, boost::mpl::size<Keys>::type::value-1>::get(v);
108 template <class T, class Keys>
109 prefix_ typename senf::detail::VariantKeyTransform<T,Keys>::input_type
110 senf::detail::VariantKeyTransform<T,Keys>::set(unsigned v)
112 return VariantKeyTransformCheck<
113 input_type, value_type, Keys, boost::mpl::size<Keys>::type::value-1>::set(v);
116 template <class In, class Out, class Keys, unsigned N>
117 prefix_ Out senf::detail::VariantKeyTransformCheck<In,Out,Keys,N>::get(In v)
119 if (boost::mpl::at<Keys, boost::mpl::int_<N> >::type::key() == v)
122 return VariantKeyTransformCheck<In, Out, Keys, N-1>::get(v);
125 template <class In, class Out, class Keys, unsigned N>
126 prefix_ In senf::detail::VariantKeyTransformCheck<In,Out,Keys,N>::set(Out v)
129 return boost::mpl::at<Keys, boost::mpl::int_<N> >::type::key();
131 return VariantKeyTransformCheck<In, Out, Keys, N-1>::set(v);
134 template <class In, class Out, class Keys>
135 prefix_ Out senf::detail::VariantKeyTransformCheck<In, Out, Keys, 0>::get(In v)
140 template <class In, class Out, class Keys>
141 prefix_ In senf::detail::VariantKeyTransformCheck<In, Out, Keys, 0>::set(Out v)
143 return boost::mpl::at<Keys, boost::mpl::int_<0> >::type::key();
146 //-/////////////////////////////////////////////////////////////////////////////////////////////////
153 // comment-column: 40
154 // c-file-style: "senf"
155 // indent-tabs-mode: nil
156 // ispell-local-dictionary: "american"
157 // compile-command: "scons -u test"