Packet.ct
Go to the documentation of this file.
1 //
2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
6 //
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
11 //
12 
13 
14 /** \file
15  \brief Packet non-inline template implementation */
16 
17 //#include "Packet.ih"
18 
19 // Custom includes
20 
21 #define prefix_
22 //-/////////////////////////////////////////////////////////////////////////////////////////////////
23 
24 //-/////////////////////////////////////////////////////////////////////////////////////////////////
25 // senf::Packet
26 
27 template <class OtherPacket>
28 prefix_ OtherPacket senf::Packet::find(NoThrow_t)
29  const
30 {
31  Packet p (*this);
32  while (p && ! p.is<OtherPacket>())
33  p = p.next(nothrow);
34  if (p)
35  return p.as<OtherPacket>();
36  else
37  return OtherPacket();
38 }
39 
40 template <class OtherPacket>
41 prefix_ OtherPacket senf::Packet::rfind(NoThrow_t)
42  const
43 {
44  Packet p (*this);
45  while (p && ! p.is<OtherPacket>())
46  p = p.prev(nothrow);
47  if (p)
48  return p.as<OtherPacket>();
49  else
50  return OtherPacket();
51 }
52 
53 //-/////////////////////////////////////////////////////////////////////////////////////////////////
54 // senf::ConcretePacket<PacketType>
55 
56 template <class PacketType>
57 template <class OtherPacket>
58 prefix_ OtherPacket senf::ConcretePacket<PacketType>::next(NoThrow_t)
59  const
60 {
61  PacketInterpreterBase::ptr p (Packet::ptr()->next());
62  if (p)
63  return (p->typeId() == typeIdValue<OtherPacket>()) ?
64  OtherPacket(p->as<typename OtherPacket::type>()) : OtherPacket();
65  PacketInterpreterBase::optional_range r (type::nextPacketRange(*this));
66  if (r && ! r->empty()) {
67  PacketInterpreterBase::ptr nxt (getNext(r));
68  if (nxt && nxt->typeId() == typeIdValue<OtherPacket>())
69  return OtherPacket(nxt->as<typename OtherPacket::type>());
70  }
71  return OtherPacket();
72 }
73 
74 //-/////////////////////////////////////////////////////////////////////////////////////////////////
75 #undef prefix_
76 
77 
78 // Local Variables:
79 // mode: c++
80 // fill-column: 100
81 // c-file-style: "senf"
82 // indent-tabs-mode: nil
83 // ispell-local-dictionary: "american"
84 // compile-command: "scons -u test"
85 // comment-column: 40
86 // End: