Added SENF_NO_DEBUG symbol and removed dependency on NDEBUG
[senf.git] / Packets / Packet.cci
index a65c653..b026e16 100644 (file)
@@ -1,6 +1,8 @@
+// $Id$
+//
 // Copyright (C) 2007 
-// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
-// Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
+// 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
@@ -22,6 +24,7 @@
     \brief Packet inline non-template implementation */
 
 // Custom includes
+#include "../Utils/senfassert.hh"
 
 #define prefix_ inline
 ///////////////////////////////cci.p///////////////////////////////////////
@@ -45,6 +48,14 @@ prefix_ senf::Packet senf::Packet::clone()
 prefix_ senf::Packet senf::Packet::next()
     const
 {
+    Packet p (next(nothrow));
+    if (!p) throw InvalidPacketChainException();
+    return p;
+}
+
+prefix_ senf::Packet senf::Packet::next(NoThrow_t)
+    const
+{
     PacketInterpreterBase::ptr p (ptr()->next());
     return !p && ptr()->nextPacketRange() ? checkNext() : Packet(p);
 }
@@ -52,6 +63,14 @@ prefix_ senf::Packet senf::Packet::next()
 prefix_ senf::Packet senf::Packet::prev()
     const
 {
+    Packet p (prev(nothrow));
+    if (!p) throw InvalidPacketChainException();
+    return p;
+}
+
+prefix_ senf::Packet senf::Packet::prev(NoThrow_t)
+    const
+{
     return Packet(ptr()->prev());
 }
 
@@ -65,7 +84,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)
@@ -106,6 +125,7 @@ prefix_ bool senf::Packet::operator==(Packet other)
 prefix_ void senf::Packet::finalize()
     const
 {
+    last(); // Make sure the packet is complete
     ptr()->finalize();
 }
 
@@ -143,7 +163,7 @@ prefix_  senf::Packet::Packet(PacketInterpreterBase::ptr packet)
 prefix_ senf::PacketInterpreterBase::ptr senf::Packet::ptr()
     const
 {
-    BOOST_ASSERT(packet_);
+    SENF_ASSERT(packet_);
     return packet_;
 }
 
@@ -158,4 +178,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: