Move sourcecode into 'senf/' directory
[senf.git] / senf / Packets / Packet.cci
diff --git a/senf/Packets/Packet.cci b/senf/Packets/Packet.cci
new file mode 100644 (file)
index 0000000..6e9d735
--- /dev/null
@@ -0,0 +1,211 @@
+// $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 Packet inline non-template implementation */
+
+// Custom includes
+#include "../Utils/senfassert.hh"
+
+#define prefix_ inline
+///////////////////////////////cci.p///////////////////////////////////////
+
+///////////////////////////////////////////////////////////////////////////
+// senf::Packet
+
+// protected members
+
+prefix_  senf::Packet::Packet(PacketInterpreterBase::ptr packet)
+    : packet_(packet)
+{}
+
+prefix_ senf::PacketInterpreterBase::ptr senf::Packet::ptr()
+    const
+{
+    SENF_ASSERT(packet_);
+    return packet_;
+}
+
+// public structors
+
+prefix_ senf::Packet::Packet()
+{}
+
+// public members
+
+prefix_ senf::Packet senf::Packet::clone()
+    const
+{
+    return Packet(ptr()->clone());
+}
+
+// Interpreter chain access
+
+prefix_ senf::Packet senf::Packet::next(NoThrow_t)
+    const
+{
+    PacketInterpreterBase::ptr p (ptr()->next());
+    return !p && ptr()->nextPacketRange() ? checkNext() : Packet(p);
+}
+
+prefix_ senf::Packet senf::Packet::next()
+    const
+{
+    Packet p (next(nothrow));
+    if (!p) throw InvalidPacketChainException();
+    return p;
+}
+
+prefix_ senf::Packet senf::Packet::prev(NoThrow_t)
+    const
+{
+    return Packet(ptr()->prev());
+}
+
+prefix_ senf::Packet senf::Packet::prev()
+    const
+{
+    Packet p (prev(nothrow));
+    if (!p) throw InvalidPacketChainException();
+    return p;
+}
+
+prefix_ senf::Packet senf::Packet::first()
+    const
+{
+    return Packet(ptr()->first());
+}
+
+prefix_ senf::Packet senf::Packet::last()
+    const
+{
+    Packet p (ptr()->last());
+    return p.next(nothrow) ? checkLast() : p;
+}
+
+prefix_ senf::Packet senf::Packet::parseNextAs(factory_t factory)
+    const
+{
+    return Packet(ptr()->parseNextAs(factory));
+}
+
+prefix_ senf::Packet senf::Packet::append(Packet const & packet)
+    const
+{
+    return Packet(ptr()->append(packet.ptr()));
+}
+
+// Data access
+
+prefix_ senf::PacketData & senf::Packet::data()
+    const
+{
+    return ptr()->data();
+}
+
+prefix_ senf::Packet::size_type senf::Packet::size()
+    const
+{
+    return data().size();
+}
+
+
+// Other methods
+
+prefix_ bool senf::Packet::operator==(Packet const & other)
+    const
+{
+    return ptr() == other.ptr();
+}
+
+prefix_ void senf::Packet::finalizeThis()
+{
+    ptr()->finalizeThis();
+}
+
+prefix_ void senf::Packet::finalizeTo(Packet const & other)
+{
+    ptr()->finalizeTo(other.ptr());
+}
+
+prefix_ void senf::Packet::finalizeAll()
+{
+    ptr()->finalizeTo(last().ptr());
+}
+
+prefix_ void senf::Packet::dump(std::ostream & os)
+    const
+{
+    last(); // Make sure the packet is complete
+    ptr()->dump(os);
+}
+
+prefix_ senf::TypeIdValue senf::Packet::typeId()
+    const
+{
+    return ptr()->typeId();
+}
+
+prefix_ senf::Packet::factory_t senf::Packet::factory()
+    const
+{
+    return ptr()->factory();
+}
+
+prefix_ unsigned long senf::Packet::id()
+    const
+{
+    return reinterpret_cast<unsigned long>(&ptr()->impl());
+}
+
+prefix_ bool senf::Packet::boolean_test()
+    const
+{
+    return packet_ && packet_->valid();
+}
+
+prefix_ bool senf::Packet::valid()
+    const
+{
+    return *this;
+}
+
+template <class PacketType, class Parser>
+prefix_ Parser senf::operator<<(Parser target, ConcretePacket<PacketType> const & packet)
+{
+    target << packet.parser();
+    return target;
+}
+
+///////////////////////////////cci.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: