X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Packets%2FPacket.cci;h=001f69c4db60bb67c5765f85323ffb44e657588d;hb=92f8630b75f3ef50e73c48cde58645dcd1534e27;hp=a65c653ee0f5d35c04ad9c85bf60420175c036c5;hpb=47368f306a577d1e46df69a7f729bd3893cbe5e7;p=senf.git diff --git a/Packets/Packet.cci b/Packets/Packet.cci index a65c653..001f69c 100644 --- a/Packets/Packet.cci +++ b/Packets/Packet.cci @@ -1,6 +1,8 @@ -// Copyright (C) 2007 -// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) -// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// $Id$ +// +// 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 @@ -22,6 +24,7 @@ \brief Packet inline non-template implementation */ // Custom includes +#include "../Utils/senfassert.hh" #define prefix_ inline ///////////////////////////////cci.p/////////////////////////////////////// @@ -29,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 { @@ -42,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 { @@ -65,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) @@ -74,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())); @@ -97,16 +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() +{ + ptr()->finalizeThis(); +} + +prefix_ void senf::Packet::finalizeTo(Packet const & other) +{ + ptr()->finalizeTo(other.ptr()); +} + +prefix_ void senf::Packet::finalizeAll() { - ptr()->finalize(); + ptr()->finalizeTo(last().ptr()); } prefix_ void senf::Packet::dump(std::ostream & os) @@ -134,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/////////////////////////////////////// @@ -158,4 +201,5 @@ prefix_ senf::PacketInterpreterBase::ptr senf::Packet::ptr() // indent-tabs-mode: nil // ispell-local-dictionary: "american" // compile-command: "scons -u test" +// comment-column: 40 // End: