// $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>();
}
///////////////////////////////////////////////////////////////////////////
template <class PacketType>
prefix_ senf::ConcretePacket<PacketType>
-senf::ConcretePacket<PacketType>::create(NoInit_t)
+senf::ConcretePacket<PacketType>::create(senf::NoInit_t)
{
- return ConcretePacket(interpreter::create(interpreter::noinit));
+ return ConcretePacket(interpreter::create(senf::noinit));
}
template <class PacketType>
template <class PacketType>
prefix_ senf::ConcretePacket<PacketType>
-senf::ConcretePacket<PacketType>::create(size_type size, NoInit_t)
+senf::ConcretePacket<PacketType>::create(size_type size, senf::NoInit_t)
{
- return ConcretePacket(interpreter::create(size,interpreter::noinit));
+ return ConcretePacket(interpreter::create(size,senf::noinit));
}
template <class PacketType>
template <class PacketType>
prefix_ senf::ConcretePacket<PacketType>
-senf::ConcretePacket<PacketType>::createAfter(Packet packet, NoInit_t)
+senf::ConcretePacket<PacketType>::createAfter(Packet packet, senf::NoInit_t)
{
- return ConcretePacket(interpreter::createAfter(packet.ptr(),interpreter::noinit));
+ return ConcretePacket(interpreter::createAfter(packet.ptr(),senf::noinit));
}
template <class PacketType>
template <class PacketType>
prefix_ senf::ConcretePacket<PacketType>
-senf::ConcretePacket<PacketType>::createAfter(Packet packet, size_type size, NoInit_t)
+senf::ConcretePacket<PacketType>::createAfter(Packet packet, size_type size, senf::NoInit_t)
{
- return ConcretePacket(interpreter::createAfter(packet.ptr(), size, interpreter::noinit));
+ return ConcretePacket(interpreter::createAfter(packet.ptr(), size, senf::noinit));
}
template <class PacketType>
template <class PacketType>
prefix_ senf::ConcretePacket<PacketType>
-senf::ConcretePacket<PacketType>::createBefore(Packet packet, NoInit_t)
+senf::ConcretePacket<PacketType>::createBefore(Packet packet, senf::NoInit_t)
{
- return ConcretePacket(interpreter::createBefore(packet.ptr(), interpreter::noinit));
+ return ConcretePacket(interpreter::createBefore(packet.ptr(), senf::noinit));
}
// Create a clone of the current packet
// Field access
template <class PacketType>
-prefix_ typename senf::ConcretePacket<PacketType>::type::parser *
+prefix_ typename senf::ConcretePacket<PacketType>::Parser *
senf::ConcretePacket<PacketType>::operator->()
const
{
return ptr()->fields_p();
}
+template <class PacketType>
+prefix_ typename senf::ConcretePacket<PacketType>::Parser
+senf::ConcretePacket<PacketType>::parser()
+ const
+{
+ return ptr()->fields();
+}
+
// private members
template <class PacketType>