Search:

SENF Extensible Network Framework

  • Home
  • Download
  • Wiki
  • BerliOS
  • ChangeLog
  • Browse SVN
  • Bug Tracker
  • Overview
  • Examples
  • HowTos
  • Glossary
  • PPI
  • Packets
  • Scheduler
  • Socket
  • Utils
  • Console
  • Daemon
  • Logger
  • Termlib
  • Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

VariantParser.cti

Go to the documentation of this file.
00001 // $Id: VariantParser.cti 1742 2010-11-04 14:51:56Z g0dil $
00002 //
00003 // Copyright (C) 2007
00004 // Fraunhofer (FOKUS)
00005 // Competence Center NETwork research (NET), St. Augustin, GERMANY
00006 //     Stefan Bund <g0dil@berlios.de>
00007 //
00008 // This program is free software; you can redistribute it and/or modify
00009 // it under the terms of the GNU General Public License as published by
00010 // the Free Software Foundation; either version 2 of the License, or
00011 // (at your option) any later version.
00012 //
00013 // This program is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 // GNU General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU General Public License
00019 // along with this program; if not, write to the
00020 // Free Software Foundation, Inc.,
00021 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00022 
00026 #include "VariantParser.ih"
00027 
00028 // Custom includes
00029 #include <senf/Utils/senfassert.hh>
00030 #include <boost/mpl/size.hpp>
00031 
00032 #define prefix_ inline
00033 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00034 
00035 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00036 // senf::VariantParser<AuxPolicy,Parsers>
00037 
00038 template <class AuxPolicy, class Parsers>
00039 prefix_ senf::VariantParser<AuxPolicy,Parsers>::
00040 VariantParser(data_iterator i, state_type s)
00041     : PacketParserBase(i,s)
00042 {}
00043 
00044 template <class AuxPolicy, class Parsers>
00045 prefix_ senf::VariantParser<AuxPolicy,Parsers>::
00046 VariantParser(AuxPolicy policy, data_iterator i, state_type s)
00047     : PacketParserBase(i,s), AuxPolicy(policy)
00048 {}
00049 
00050 template <class AuxPolicy, class Parsers>
00051 prefix_ senf::PacketParserBase::size_type
00052 senf::VariantParser<AuxPolicy,Parsers>::bytes()
00053     const
00054 {
00055     return detail::VariantBytes< VariantParser, boost::mpl::size<parsers>::value - 1 >
00056         ::bytes(*this, variant()) + AuxPolicy::aux_bytes;
00057 }
00058 
00059 template <class AuxPolicy, class Parsers>
00060 prefix_ void
00061 senf::VariantParser<AuxPolicy,Parsers>::init()
00062 {
00063     AuxPolicy::aux(0,i(),state());
00064     get<0>().init();
00065 }
00066 
00067 template <class AuxPolicy, class Parsers>
00068 prefix_ unsigned senf::VariantParser<AuxPolicy,Parsers>::variant()
00069     const
00070 {
00071     return AuxPolicy::aux(i(),state());
00072 }
00073 
00074 template <class AuxPolicy, class Parsers>
00075 template <unsigned N>
00076 prefix_ typename boost::mpl::at<
00077     typename senf::VariantParser<AuxPolicy,Parsers>::parsers,
00078     boost::mpl::int_<N> >::type
00079 senf::VariantParser<AuxPolicy,Parsers>::get()
00080     const
00081 {
00082     SENF_ASSERT( variant() == N, "Access to non-active variant member" );
00083     return typename boost::mpl::at<parsers, boost::mpl::int_<N> >::type(
00084         AuxPolicy::adjust(i(), state()), state() );
00085 }
00086 
00087 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00088 // senf::detail::VariantBytes<Variant,N>
00089 
00090 template <class Variant, unsigned N>
00091 prefix_ senf::PacketParserBase::size_type
00092 senf::detail::VariantBytes<Variant,N>::bytes(Variant const & v, unsigned n)
00093 {
00094     if (n == N)
00095         return senf::bytes(v.template get<N>());
00096     else
00097         return VariantBytes<Variant, N-1>::bytes(v, n);
00098 }
00099 
00100 template <class Variant>
00101 prefix_ senf::PacketParserBase::size_type
00102 senf::detail::VariantBytes<Variant,0>::bytes(Variant const & v, unsigned n)
00103 {
00104     return senf::bytes(v.template get<0>());
00105 }
00106 
00107 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00108 // senf::detail::VariantKeyTransform<T,Keys>
00109 
00110 template <class T, class Keys>
00111 prefix_ unsigned senf::detail::VariantKeyTransform<T,Keys>::get(input_type v)
00112 {
00113     return VariantKeyTransformCheck<
00114         input_type, value_type, Keys, boost::mpl::size<Keys>::type::value-1>::get(v);
00115 }
00116 
00117 template <class T, class Keys>
00118 prefix_ typename senf::detail::VariantKeyTransform<T,Keys>::input_type
00119 senf::detail::VariantKeyTransform<T,Keys>::set(unsigned v)
00120 {
00121     return VariantKeyTransformCheck<
00122         input_type, value_type, Keys, boost::mpl::size<Keys>::type::value-1>::set(v);
00123 }
00124 
00125 template <class In, class Out, class Keys, unsigned N>
00126 prefix_ Out senf::detail::VariantKeyTransformCheck<In,Out,Keys,N>::get(In v)
00127 {
00128     if (boost::mpl::at<Keys, boost::mpl::int_<N> >::type::key() == v)
00129         return N;
00130     else
00131         return VariantKeyTransformCheck<In, Out, Keys, N-1>::get(v);
00132 }
00133 
00134 template <class In, class Out, class Keys, unsigned N>
00135 prefix_ In senf::detail::VariantKeyTransformCheck<In,Out,Keys,N>::set(Out v)
00136 {
00137     if (v == N)
00138         return boost::mpl::at<Keys, boost::mpl::int_<N> >::type::key();
00139     else
00140         return VariantKeyTransformCheck<In, Out, Keys, N-1>::set(v);
00141 }
00142 
00143 template <class In, class Out, class Keys>
00144 prefix_ Out senf::detail::VariantKeyTransformCheck<In, Out, Keys, 0>::get(In v)
00145 {
00146     return 0;
00147 }
00148 
00149 template <class In, class Out, class Keys>
00150 prefix_ In senf::detail::VariantKeyTransformCheck<In, Out, Keys, 0>::set(Out v)
00151 {
00152     return boost::mpl::at<Keys, boost::mpl::int_<0> >::type::key();
00153 }
00154 
00155 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00156 #undef prefix_
00157 
00158 
00159 // Local Variables:
00160 // mode: c++
00161 // fill-column: 100
00162 // comment-column: 40
00163 // c-file-style: "senf"
00164 // indent-tabs-mode: nil
00165 // ispell-local-dictionary: "american"
00166 // compile-command: "scons -u test"
00167 // End:

Contact: senf-dev@lists.berlios.de | © 2006-2010 Fraunhofer Institute for Open Communication Systems, Network Research