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

PacketParser.ih

Go to the documentation of this file.
00001 // $Id: PacketParser.ih 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 #ifndef IH_SENF_Packets_PacketParser_
00027 #define IH_SENF_Packets_PacketParser_ 1
00028 
00029 // Custom includes
00030 #include <senf/Utils/mpl.hh>
00031 
00032 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00033 
00034 namespace senf {
00035 namespace detail {
00036 
00037     // PLEASE don't add this to doxygen ... it just looks to weird and does not help ...
00038 
00039 #   ifndef DOXYGEN
00040 
00041     // Use SFINAE to check, if Parser has an integer-valued init_bytes member. If not,
00042     // 'Parser_TakeNum<Parser::init_bytes>' fails and the overload is removed from the overload
00043     // set.
00044     template <class Parser>
00045     PacketParserBase::size_type packetParserSize(
00046         Parser p, int, senf::mpl::take_uint<Parser::init_bytes> * = 0);
00047 
00048     // An ellipsis is always the worst match. A call 'packetParserSize(p,0) will prefer above
00049     // overload if that is not disabled by SFINAE.
00050     template <class Parser>
00051     PacketParserBase::size_type packetParserSize(Parser p, ...);
00052 
00053     // Same as above: This overload is only enabled, if Parser has an integer values 'init_bytes'
00054     // member.
00055     template <class Parser>
00056     senf::mpl::rv<0> ParserInitBytes_Choose_(senf::mpl::take_uint<Parser::init_bytes> *);
00057 
00058     template <class Parser>
00059     senf::mpl::rv<1> ParserInitBytes_Choose_(...);
00060 
00061     // This version of ParserInitBytes_Choose uses 'Parser::init_bytes' to provide 'value' (via
00062     // 'boost::integral_constant')
00063     template <class Parser, unsigned _>
00064     struct ParserInitBytes_Choose
00065         : public boost::integral_constant<PacketParserBase::size_type, Parser::init_bytes> {};
00066     // ^^-- g++ error signaled here:
00067     //    error: 'fixed_bytes' is not a member of 'some-class-name'
00068     //
00069     // The 'some-class-name' class (as given in the error message) does not seem to be a parser at
00070     // all (it has neither a 'fixed_bytes' nor an 'init_bytes' member).
00071     //
00072     // Either 'some-class-name' is not the class you wanted to use (it really is no parser) or you
00073     // left out either 'init_bytes' or 'fixed_bytes' when defining the parser. This will also
00074     // happen, if you forget to call 'SENF_PARSER_FINALIZE()' when defining a composite parser.
00075     //-/////////////////////////////////////////////////////////////////////////////////////////////
00076 
00077     // If Parser::init_bytes is not defined, this specialization is chosen which instead uses
00078     // 'Parser::fixed_bytes'
00079     template <class Parser>
00080     struct ParserInitBytes_Choose<Parser, 1>
00081         : public boost::integral_constant<PacketParserBase::size_type, Parser::fixed_bytes> {};
00082 
00083     template <class Parser>
00084     struct ParserInitBytes
00085         : public ParserInitBytes_Choose<Parser,SENF_MPL_RV(ParserInitBytes_Choose_<Parser>(0))> {};
00086 
00087     template <class Parser, unsigned _>
00088     struct ParserIsFixed_Choose
00089         : public boost::false_type {};
00090 
00091     template <class Parser>
00092     struct ParserIsFixed_Choose<Parser, 1>
00093         : public boost::true_type {};
00094 
00095     template <class Parser>
00096     struct ParserIsFixed
00097         : public ParserIsFixed_Choose<Parser,SENF_MPL_RV(ParserInitBytes_Choose_<Parser>(0))> {};
00098 
00099 #   endif
00100 
00101 }}
00102 
00103 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00104 #endif
00105 
00106 
00107 // Local Variables:
00108 // mode: c++
00109 // fill-column: 100
00110 // c-file-style: "senf"
00111 // indent-tabs-mode: nil
00112 // ispell-local-dictionary: "american"
00113 // compile-command: "scons -u test"
00114 // comment-column: 40
00115 // End:

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