Move sourcecode into 'senf/' directory
[senf.git] / senf / Packets / PacketType.cti
diff --git a/senf/Packets/PacketType.cti b/senf/Packets/PacketType.cti
new file mode 100644 (file)
index 0000000..1b7e693
--- /dev/null
@@ -0,0 +1,117 @@
+// $Id$
+//
+// Copyright (C) 2007
+// Fraunhofer Institute for Open Communication Systems (FOKUS)
+// Competence Center NETwork research (NET), St. Augustin, GERMANY
+//     Stefan Bund <g0dil@berlios.de>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the
+// Free Software Foundation, Inc.,
+// 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+
+/** \file
+    \brief PacketType inline template implementation */
+
+//#include "PacketType.ih"
+
+// Custom includes
+#include <boost/utility.hpp>
+#include "PacketRegistry.hh"
+
+#define prefix_ inline
+///////////////////////////////cti.p///////////////////////////////////////
+
+///////////////////////////////////////////////////////////////////////////
+// senf::PacketTypeBase
+
+template <class PacketType>
+prefix_ senf::PacketTypeBase::factory_t senf::PacketTypeBase::factory()
+{
+    return PacketInterpreter<PacketType>::factory();
+}
+
+///////////////////////////////////////////////////////////////////////////
+// senf::PacketTypeMixin<Self,Registry>
+
+template <class Self, class Registry>
+prefix_ senf::PacketInterpreterBase::optional_range
+senf::PacketTypeMixin<Self,Registry>::nextPacketRange(Packet const & p)
+{
+    // Call the member defined in the specialization below
+    return PacketTypeMixin<Self>::nextPacketRange(p);
+}
+
+template <class Self, class Registry>
+prefix_ senf::PacketInterpreterBase::factory_t
+senf::PacketTypeMixin<Self,Registry>::nextPacketType(Packet const & p)
+{
+    if (p.data().size() < Self::initSize())
+        return Self::no_factory();
+    return lookup( Self::nextPacketKey(p.as< ConcretePacket<Self> >()) );
+}
+
+template <class Self, class Registry>
+prefix_ senf::PacketInterpreterBase::size_type senf::PacketTypeMixin<Self,Registry>::initSize()
+{
+    return senf::init_bytes< typename Self::parser >::value;
+}
+
+template <class Self, class Registry>
+prefix_ void senf::PacketTypeMixin<Self,Registry>::init(Packet const & p)
+{
+    p.as< ConcretePacket<Self> >()->init();
+}
+
+template <class Self, class Registry>
+prefix_ typename senf::PacketTypeMixin<Self,Registry>::optional_key_t
+senf::PacketTypeMixin<Self,Registry>::key(Packet const & p)
+{
+    return p ? PacketRegistry<Registry>::key(p, nothrow) : optional_key_t();
+}
+
+template <class Self, class Registry>
+prefix_ senf::PacketTypeBase::factory_t senf::PacketTypeMixin<Self,Registry>::lookup(key_t key)
+{
+    PkReg_Entry const * entry (PacketRegistry<Registry>::lookup( key, senf::nothrow ));
+    return entry ? entry->factory() : PacketTypeBase::no_factory();
+}
+
+///////////////////////////////////////////////////////////////////////////
+// senf::PacketTypeMixin<Self,void>
+
+template <class Self>
+prefix_ senf::PacketInterpreterBase::size_type senf::PacketTypeMixin<Self,void>::initSize()
+{
+    return senf::init_bytes< typename Self::parser >::value;
+}
+
+template <class Self>
+prefix_ void senf::PacketTypeMixin<Self,void>::init(Packet const & p)
+{
+    p.as< ConcretePacket<Self> >()->init();
+}
+
+///////////////////////////////cti.e///////////////////////////////////////
+#undef prefix_
+
+\f
+// Local Variables:
+// mode: c++
+// fill-column: 100
+// c-file-style: "senf"
+// indent-tabs-mode: nil
+// ispell-local-dictionary: "american"
+// compile-command: "scons -u test"
+// comment-column: 40
+// End: