7004c7acdc29097ae6d62d5b2f4db70e2243ee85
[senf.git] / Packets / PacketInterpreter.cci
1 // $Id$
2 //
3 // Copyright (C) 2007 
4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
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 inline non-template implementation */
25
26 // Custom includes
27 #include <boost/utility.hpp>
28
29 #define prefix_ inline
30 ///////////////////////////////cci.p///////////////////////////////////////
31
32 ///////////////////////////////////////////////////////////////////////////
33 // senf::PacketInterpreterBase
34
35 // Structors and default members
36
37 prefix_ senf::PacketInterpreterBase::factory_t senf::PacketInterpreterBase::no_factory()
38 {
39     return 0;
40 }
41
42 // Interpreter chain access
43
44 prefix_ senf::PacketInterpreterBase::ptr senf::PacketInterpreterBase::next()
45 {
46     return ptr(impl().next(this));
47 }
48
49 prefix_ senf::PacketInterpreterBase::ptr senf::PacketInterpreterBase::prev()
50 {
51     return ptr(impl().prev(this));
52 }
53
54 prefix_ senf::PacketInterpreterBase::ptr senf::PacketInterpreterBase::first()
55 {
56     return ptr(impl().first());
57 }
58
59 prefix_ senf::PacketInterpreterBase::ptr senf::PacketInterpreterBase::last()
60 {
61     return ptr(impl().last());
62 }
63
64 prefix_ senf::PacketInterpreterBase::ptr
65 senf::PacketInterpreterBase::parseNextAs(factory_t factory)
66 {
67     return factory->parseNext(ptr(this));
68 }
69
70 // Data access
71
72 prefix_ senf::PacketData & senf::PacketInterpreterBase::data()
73 {
74     return (*this);
75 }
76
77 // Access to the abstract interface
78
79 prefix_ senf::PacketInterpreterBase::optional_range
80 senf::PacketInterpreterBase::nextPacketRange()
81 {
82     return v_nextPacketRange();
83 }
84
85 prefix_ senf::TypeIdValue senf::PacketInterpreterBase::typeId()
86 {
87     return v_type();
88 }
89
90 prefix_ senf::PacketInterpreterBase::factory_t senf::PacketInterpreterBase::factory()
91 {
92     return v_factory();
93 }
94
95 prefix_ senf::PacketInterpreterBase::factory_t senf::PacketInterpreterBase::nextPacketType()
96 {
97     return v_nextPacketType();
98 }
99
100 ////////////////////////////////////////
101 // protected members
102
103 // protected structors
104
105 prefix_ senf::PacketInterpreterBase::PacketInterpreterBase(detail::PacketImpl * impl,
106                                                            iterator b, iterator e, Append_t)
107     : PacketData(std::distance(impl->begin(),b),
108                  std::distance(impl->begin(),e))
109 {
110     impl->appendInterpreter(this);
111 }
112
113 prefix_ senf::PacketInterpreterBase::PacketInterpreterBase(detail::PacketImpl * impl,
114                                                            iterator b, iterator e, Prepend_t)
115     : PacketData(std::distance(impl->begin(),b),
116                  std::distance(impl->begin(),e))
117 {
118         impl->prependInterpreter(this);
119 }
120
121 prefix_ senf::PacketInterpreterBase::ptr
122 senf::PacketInterpreterBase::appendClone(detail::PacketImpl * impl, iterator base,
123                                          iterator new_base)
124 {
125     return v_appendClone(impl,base,new_base);
126 }
127
128 prefix_ senf::PacketInterpreterBase::ptr
129 senf::PacketInterpreterBase::appendClone(detail::PacketImpl * impl, range r)
130 {
131     return v_appendClone(impl,r);
132 }
133
134 ////////////////////////////////////////
135 // private members
136
137 // reference/memory management
138
139 prefix_ void senf::PacketInterpreterBase::add_ref()
140 {
141     intrusive_refcount_t<PacketInterpreterBase>::add_ref();
142     if (impl_)
143         impl_->add_ref();
144 }
145
146 prefix_ bool senf::PacketInterpreterBase::release()
147 {
148     if (impl_) 
149         // This call will set impl_ to 0 if we just removed the last reference ...
150         impl_->release();
151     return intrusive_refcount_t<PacketInterpreterBase>::release() && !impl_;
152 }
153
154 // containment management. Only to be called by PacketImpl.
155
156 prefix_ void senf::PacketInterpreterBase::assignImpl(detail::PacketImpl * impl)
157 {
158     BOOST_ASSERT(!impl_);
159     impl_ = impl;
160     impl_->add_ref(refcount());
161 }
162
163 prefix_ void senf::PacketInterpreterBase::releaseImpl()
164 {
165     BOOST_ASSERT(impl_);
166     refcount_t refc (refcount());
167     if (refc) {
168         impl_->release(refc);
169         impl_ = 0;
170     } else {
171         impl_ = 0;
172         delete this;
173     }
174 }
175
176
177 ///////////////////////////////cci.e///////////////////////////////////////
178 #undef prefix_
179
180 \f
181 // Local Variables:
182 // mode: c++
183 // fill-column: 100
184 // c-file-style: "senf"
185 // indent-tabs-mode: nil
186 // ispell-local-dictionary: "american"
187 // compile-command: "scons -u test"
188 // comment-column: 40
189 // End: