X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Packets%2FPacket.cci;h=001f69c4db60bb67c5765f85323ffb44e657588d;hb=a1fdb7bb122f0b05be809a922d4b7ef5e125fa67;hp=7c4ae37530ee3c262ae25bfc677aa2e14e5dda50;hpb=6116cb96ea7bdcb42b7d12165a05fcbe0687226d;p=senf.git diff --git a/Packets/Packet.cci b/Packets/Packet.cci index 7c4ae37..001f69c 100644 --- a/Packets/Packet.cci +++ b/Packets/Packet.cci @@ -1,8 +1,8 @@ // $Id$ // -// Copyright (C) 2007 -// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) -// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// Copyright (C) 2007 +// Fraunhofer Institute for Open Communication Systems (FOKUS) +// Competence Center NETwork research (NET), St. Augustin, GERMANY // Stefan Bund // // This program is free software; you can redistribute it and/or modify @@ -24,6 +24,7 @@ \brief Packet inline non-template implementation */ // Custom includes +#include "../Utils/senfassert.hh" #define prefix_ inline ///////////////////////////////cci.p/////////////////////////////////////// @@ -31,11 +32,26 @@ /////////////////////////////////////////////////////////////////////////// // 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 { @@ -44,19 +60,35 @@ prefix_ senf::Packet senf::Packet::clone() // Interpreter chain access -prefix_ senf::Packet senf::Packet::next() +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::prev() +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 { @@ -67,7 +99,7 @@ prefix_ senf::Packet senf::Packet::last() const { Packet p (ptr()->last()); - return p.next() ? checkLast() : p; + return p.next(nothrow) ? checkLast() : p; } prefix_ senf::Packet senf::Packet::parseNextAs(factory_t factory) @@ -76,7 +108,7 @@ prefix_ senf::Packet senf::Packet::parseNextAs(factory_t factory) return Packet(ptr()->parseNextAs(factory)); } -prefix_ senf::Packet senf::Packet::append(Packet packet) +prefix_ senf::Packet senf::Packet::append(Packet const & packet) const { return Packet(ptr()->append(packet.ptr())); @@ -99,17 +131,25 @@ prefix_ senf::Packet::size_type senf::Packet::size() // Other methods -prefix_ bool senf::Packet::operator==(Packet other) +prefix_ bool senf::Packet::operator==(Packet const & other) const { return ptr() == other.ptr(); } -prefix_ void senf::Packet::finalize() - const +prefix_ void senf::Packet::finalizeThis() { - last(); // Make sure the packet is complete - ptr()->finalize(); + 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) @@ -137,17 +177,17 @@ prefix_ bool senf::Packet::boolean_test() return packet_ && packet_->valid(); } -// protected members - -prefix_ senf::Packet::Packet(PacketInterpreterBase::ptr packet) - : packet_(packet) -{} - -prefix_ senf::PacketInterpreterBase::ptr senf::Packet::ptr() +prefix_ bool senf::Packet::valid() const { - BOOST_ASSERT(packet_); - return packet_; + return *this; +} + +template +prefix_ Parser senf::operator<<(Parser target, ConcretePacket const & packet) +{ + target << packet.parser(); + return target; } ///////////////////////////////cci.e///////////////////////////////////////