Merged revisions 262,264-265,267-282,284-298,300-311 via svnmerge from
[senf.git] / Packets / PacketInterpreter.cc
1 // Copyright (C) 2007 
2 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
3 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
4 //     Stefan Bund <g0dil@berlios.de>
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the
18 // Free Software Foundation, Inc.,
19 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20
21 /** \file
22     \brief PacketInterpreter non-inline non-template implementation */
23
24 #include "PacketInterpreter.hh"
25 //#include "PacketInterpreter.ih"
26
27 // Custom includes
28
29 //#include "PacketInterpreter.mpp"
30 #define prefix_
31 ///////////////////////////////cc.p////////////////////////////////////////
32
33 ///////////////////////////////////////////////////////////////////////////
34 // senf::PacketInterpreterBase
35
36 // structors and default members
37
38 prefix_  senf::PacketInterpreterBase::~PacketInterpreterBase()
39 {}
40
41 prefix_ senf::PacketInterpreterBase::ptr senf::PacketInterpreterBase::clone()
42 {
43     detail::PacketImpl::Guard p (new detail::PacketImpl(begin(),end()));
44     ptr pi (appendClone(p.p,begin(),p.p->begin()));
45     for (ptr i (next()); i; i = i->next())
46         i->appendClone(p.p,begin(),p.p->begin());
47     return pi;
48 }
49
50 // Interpreter chain access
51
52 prefix_ senf::PacketInterpreterBase::ptr senf::PacketInterpreterBase::append(ptr packet)
53 {
54     if (next())
55         impl().truncateInterpreters(next().get());
56     
57     optional_range r (nextPacketRange());
58     if (!r)
59         throw InvalidPacketChainException();
60     
61     ptr rv (packet->appendClone(&impl(), *r));
62     rv->data().resize(packet->data().size());
63     std::copy(packet->data().begin(), packet->data().end(), rv->data().begin());
64
65     for (ptr p (packet->next()) ; p ; p = p->next())
66         p->appendClone(&impl(), packet->data().begin(), rv->data().begin());
67
68     return rv;
69 }
70
71 // Access to the abstract interface
72
73 prefix_ void senf::PacketInterpreterBase::dump(std::ostream & os)
74 {
75     v_dump(os);
76     for (ptr i (next()); i; i = i->next())
77         i->v_dump(os);
78 }
79
80 prefix_ void senf::PacketInterpreterBase::finalize()
81 {
82     for (ptr i (last()) ; i.get() != this ; i = i->prev())
83         i->v_finalize();
84     v_finalize();
85 }
86
87 ///////////////////////////////////////////////////////////////////////////
88 // senf::PacketInterpreterBase::Factory
89
90 prefix_  senf::PacketInterpreterBase::Factory::~Factory()
91 {}
92
93 ///////////////////////////////cc.e////////////////////////////////////////
94 #undef prefix_
95 //#include "PacketInterpreter.mpp"
96
97 \f
98 // Local Variables:
99 // mode: c++
100 // fill-column: 100
101 // c-file-style: "senf"
102 // indent-tabs-mode: nil
103 // ispell-local-dictionary: "american"
104 // End: