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

GenericTLV.cti

Go to the documentation of this file.
00001 // $Id: GenericTLV.cti 1742 2010-11-04 14:51:56Z g0dil $
00002 //
00003 // Copyright (C) 2009
00004 // Fraunhofer (FOKUS)
00005 // Competence Center NETwork research (NET), St. Augustin, GERMANY
00006 //     Thorsten Horstmann <tho@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 "GenericTLV.ih"
00027 
00028 // Custom includes
00029 
00030 #define prefix_ inline
00031 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00032 
00033 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00034 // senf::GenericTLVParserBase<Base>
00035 
00036 template <class Base>
00037 prefix_ senf::PacketParserBase::size_type senf::GenericTLVParserBase<Base>::bytes()
00038     const
00039 {
00040     if (Base::Registry::instance().isRegistered( *this))
00041         return Base::Registry::instance().bytes( *this);
00042     else
00043         return senf::bytes(self()) + this->length();
00044 }
00045 
00046 template <class Base>
00047 prefix_ void senf::GenericTLVParserBase<Base>::init()
00048     const
00049 {
00050     this->defaultInit();
00051 }
00052 
00053 template <class Base>
00054 template <class Parser>
00055 prefix_ Parser senf::GenericTLVParserBase<Base>::as()
00056     const
00057 {
00058     return Parser(this->i(), this->state() );
00059 }
00060 
00061 template <class Base>
00062 template <class Parser>
00063 prefix_ bool senf::GenericTLVParserBase<Base>::is()
00064     const
00065 {
00066     return this->type().value() == Parser::typeId;
00067 }
00068 
00069 template <class Base>
00070 prefix_ Base & senf::GenericTLVParserBase<Base>::self()
00071 {
00072     return *static_cast<Base *>(this);
00073 }
00074 
00075 template <class Base>
00076 prefix_ Base const & senf::GenericTLVParserBase<Base>::self()
00077     const
00078 {
00079     return *static_cast<Base const *>(this);
00080 }
00081 
00082 #ifndef DOXYGEN
00083 
00084 template <class Base>
00085 template <class ForwardReadableRange>
00086 prefix_ void senf::GenericTLVParserBase<Base>::value(
00087         ForwardReadableRange const & val,
00088         typename boost::disable_if<senf::is_pair<ForwardReadableRange> >::type *)
00089 {
00090     value_( val);
00091 }
00092 
00093 template <class Base>
00094 template <class First, class Second>
00095 prefix_ void senf::GenericTLVParserBase<Base>::value(
00096         std::pair<First, Second> const & val,
00097         typename boost::disable_if<boost::is_convertible<First, typename Base::type_t::value_type> >::type *)
00098 {
00099     value_( val);
00100 }
00101 
00102 template <class Base>
00103 template <class Type, class ForwardReadableRange>
00104 prefix_ void senf::GenericTLVParserBase<Base>::value(
00105         std::pair<Type, ForwardReadableRange> const & val,
00106         typename boost::enable_if<boost::is_convertible<Type, typename Base::type_t::value_type> >::type *)
00107 {
00108     this->type() = val.first;
00109     value_( val.second);
00110 }
00111 
00112 #endif
00113 
00114 
00115 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00116 // senf::detail:GenericTLVParserRegistry_Entry<BaseParser, Parser>
00117 
00118 template <class BaseParser, class Parser>
00119 prefix_ void senf::detail::GenericTLVParserRegistry_Entry<BaseParser, Parser>::dump(
00120         GenericTLVParserBase<BaseParser> const & parser, std::ostream & os)
00121     const
00122 {
00123     (parser.template as<Parser>()).dump(os);
00124 }
00125 
00126 template <class BaseParser, class Parser>
00127 prefix_ senf::PacketParserBase::size_type
00128 senf::detail::GenericTLVParserRegistry_Entry<BaseParser, Parser>::bytes(
00129         GenericTLVParserBase<BaseParser> const & parser)
00130     const
00131 {
00132     return senf::bytes( parser.template as<Parser>());
00133 }
00134 
00135 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00136 // senf::GenericTLVParserRegistry<BaseParser,Keytype>
00137 
00138 template <class BaseParser, class Keytype>
00139 prefix_ bool senf::GenericTLVParserRegistry<BaseParser,Keytype>::isRegistered(
00140         GenericTLVParser const & parser)
00141     const
00142 {
00143     typename Map::const_iterator i (map_.find( parser.type()));
00144     return i != map_.end();
00145 }
00146 
00147 template <class BaseParser, class Keytype>
00148 prefix_ bool senf::GenericTLVParserRegistry<BaseParser,Keytype>::isRegistered(Keytype const & key)
00149     const
00150 {
00151     typename Map::const_iterator i (map_.find( key));
00152     return i != map_.end();
00153 }
00154 
00155 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00156 // senf::GenericTLVParserRegistry<BaseParser,Keytype>::RegistrationProxy<PacketParser>
00157 
00158 template <class BaseParser, class Keytype>
00159 template <class PacketParser>
00160 prefix_ senf::GenericTLVParserRegistry<BaseParser,Keytype>::RegistrationProxy<PacketParser>::RegistrationProxy()
00161 {
00162     GenericTLVParserRegistry<BaseParser,Keytype>::instance().registerParser<PacketParser>();
00163 };
00164 
00165 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00166 #undef prefix_
00167 
00168 
00169 // Local Variables:
00170 // mode: c++
00171 // fill-column: 100
00172 // comment-column: 40
00173 // c-file-style: "senf"
00174 // indent-tabs-mode: nil
00175 // ispell-local-dictionary: "american"
00176 // compile-command: "scons -u test"
00177 // End:

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