Packets: BUGFIX: next<> and prev<> now correctly handle in-valid() returns
[senf.git] / Packets / Packet.cti
index c17dc6f..ed032da 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
@@ -58,6 +60,8 @@ template <class OtherPacket>
 prefix_ OtherPacket senf::Packet::as()
     const
 {
+    if (!is<OtherPacket>())
+        throw std::bad_cast();
     return OtherPacket(ptr()->as<typename OtherPacket::type>());
 }
 
@@ -65,81 +69,30 @@ template <class OtherPacket>
 prefix_ OtherPacket senf::Packet::next()
     const
 {
-    OtherPacket p (next<OtherPacket>(nothrow));
-    if (!p) throw InvalidPacketChainException();
-    return p;
-}
-
-
-template <class OtherPacket>
-prefix_ OtherPacket senf::Packet::next(NoThrow_t)
-    const
-{
-    Packet p (next());
-    return p ? p.findNext<OtherPacket>(nothrow) : OtherPacket();
+    Packet p (next())
+    return p ? p.as<OtherPacket>() : OtherPacket();
 }
 
 template <class OtherPacket>
 prefix_ OtherPacket senf::Packet::prev()
     const
 {
-    OtherPacket p (prev<OtherPacket>(nothrow));
-    if (!p) throw InvalidPacketChainException();
-    return p;
-}
-
-template <class OtherPacket>
-prefix_ OtherPacket senf::Packet::prev(NoThrow_t)
-    const
-{
     Packet p (prev());
-    return p ? p.findPrev<OtherPacket>(nothrow) : OtherPacket();
-}
-
-template <class OtherPacket>
-prefix_ OtherPacket senf::Packet::findNext()
-    const
-{
-    OtherPacket p (findNext<OtherPacket>(nothrow));
-    if (!p) throw InvalidPacketChainException();
-    return p;
-}
-
-template <class OtherPacket>
-prefix_ OtherPacket senf::Packet::findPrev()
-    const
-{
-    OtherPacket p (findPrev<OtherPacket>(nothrow));
-    if (!p) throw InvalidPacketChainException();
-    return p;
+    return p ? p.as<OtherPacket>() : OtherPacket();
 }
 
 template <class OtherPacket>
 prefix_ OtherPacket senf::Packet::last()
     const
 {
-    return last().findPrev<OtherPacket>();
-}
-
-template <class OtherPacket>
-prefix_ OtherPacket senf::Packet::last(NoThrow_t)
-    const
-{
-    return last().findPrev<OtherPacket>(nothrow);
+    return last().as<OtherPacket>();
 }
 
 template <class OtherPacket>
 prefix_ OtherPacket senf::Packet::first()
     const
 {
-    return first().findNext<OtherPacket>();
-}
-
-template <class OtherPacket>
-prefix_ OtherPacket senf::Packet::first(NoThrow_t)
-    const
-{
-    return first().findNext<OtherPacket>(nothrow);
+    return first().as<OtherPacket>();
 }
 
 ///////////////////////////////////////////////////////////////////////////
@@ -263,7 +216,7 @@ senf::ConcretePacket<PacketType>::clone()
 // Field access
 
 template <class PacketType>
-prefix_ typename senf::ConcretePacket<PacketType>::interpreter::parser *
+prefix_ typename senf::ConcretePacket<PacketType>::type::parser *
 senf::ConcretePacket<PacketType>::operator->()
     const
 {
@@ -296,4 +249,5 @@ senf::ConcretePacket<PacketType>::ptr()
 // indent-tabs-mode: nil
 // ispell-local-dictionary: "american"
 // compile-command: "scons -u test"
+// comment-column: 40
 // End: