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