+// $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
prefix_ OtherPacket senf::Packet::as()
const
{
+ if (!is<OtherPacket>())
+ throw std::bad_cast();
return OtherPacket(ptr()->as<typename OtherPacket::type>());
}
prefix_ OtherPacket senf::Packet::next()
const
{
- OtherPacket p (next<OtherPacket>(nothrow));
- if (!p) throw InvalidPacketChainException();
- return p;
+ return next().as<OtherPacket>();
}
-
template <class OtherPacket>
prefix_ OtherPacket senf::Packet::next(NoThrow_t)
const
{
- Packet p (next());
- return p ? p.findNext<OtherPacket>(nothrow) : OtherPacket();
+ Packet p (next(nothrow));
+ return p && p.is<OtherPacket>() ? p.as<OtherPacket>() : OtherPacket();
}
template <class OtherPacket>
-prefix_ OtherPacket senf::Packet::prev()
+prefix_ OtherPacket senf::Packet::find()
const
{
- OtherPacket p (prev<OtherPacket>(nothrow));
+ OtherPacket p (find<OtherPacket>(nothrow));
if (!p) throw InvalidPacketChainException();
return p;
}
template <class OtherPacket>
-prefix_ OtherPacket senf::Packet::prev(NoThrow_t)
+prefix_ OtherPacket senf::Packet::prev()
const
{
- Packet p (prev());
- return p ? p.findPrev<OtherPacket>(nothrow) : OtherPacket();
+ return prev().as<OtherPacket>();
}
template <class OtherPacket>
-prefix_ OtherPacket senf::Packet::findNext()
+prefix_ OtherPacket senf::Packet::prev(NoThrow_t)
const
{
- OtherPacket p (findNext<OtherPacket>(nothrow));
- if (!p) throw InvalidPacketChainException();
- return p;
+ Packet p (prev(nothrow));
+ return p && p.is<OtherPacket>() ? p.as<OtherPacket>() : OtherPacket();
}
template <class OtherPacket>
-prefix_ OtherPacket senf::Packet::findPrev()
+prefix_ OtherPacket senf::Packet::rfind()
const
{
- OtherPacket p (findPrev<OtherPacket>(nothrow));
+ OtherPacket p (rfind<OtherPacket>(nothrow));
if (!p) throw InvalidPacketChainException();
return p;
}
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>();
}
///////////////////////////////////////////////////////////////////////////