4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
6 // Stefan Bund <stefan.bund@fokus.fraunhofer.de>
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.
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.
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.
23 // Definition of inline non-template functions
29 #define prefix_ inline
30 ///////////////////////////////cci.p///////////////////////////////////////
32 prefix_ satcom::pkf::impl::PacketImpl::PacketImpl()
33 : data_(), interpreters_(), refcount_(1)
35 SATCOM_PKF_REFC_MSG("] PacketImpl::PacketImpl (" << this << "): refcount_ = 1\n");
38 prefix_ satcom::pkf::impl::PacketImpl::PacketImpl(unsigned size, Packet::byte initValue)
39 : data_(size,initValue), interpreters_(), refcount_(1)
41 SATCOM_PKF_REFC_MSG("] PacketImpl::PacketImpl (" << this << "): refcount_ = 1\n");
44 prefix_ satcom::pkf::impl::PacketImpl::~PacketImpl()
46 BOOST_ASSERT( !refcount_ );
47 SATCOM_PKF_REFC_MSG("] PacketImpl::~PacketImpl (" << this << ")\n");
50 // PacketImpl::add_ref and PacketImpl::release are only called from
51 // intrusive_ptr_add_ref and intrusive_ptr_release
52 prefix_ void satcom::pkf::impl::PacketImpl::add_ref()
55 SATCOM_PKF_REFC_MSG("] PacketImpl::add_ref (" << this << "): refcount_ = " << refcount_ << "\n");
58 prefix_ bool satcom::pkf::impl::PacketImpl::release()
60 BOOST_ASSERT( refcount_ > 0 );
62 SATCOM_PKF_REFC_MSG("] PacketImpl::release (" << this << "): refcount_ = " << refcount_ << "\n");
66 prefix_ void satcom::pkf::impl::PacketImpl::truncateInterpreters(Packet const * p)
68 BOOST_ASSERT( p->impl_ == this );
69 this->interpreters_.erase(p->self_,this->interpreters_.end());
72 prefix_ void satcom::pkf::impl::PacketImpl::truncateInterpretersAfter(Packet const * p)
74 BOOST_ASSERT( p->impl_ == this );
75 this->interpreters_.erase(boost::next(p->self_),this->interpreters_.end());
78 prefix_ satcom::pkf::impl::PacketImpl* satcom::pkf::impl::PacketImpl::impl(Packet const * p)
84 prefix_ std::ostream & satcom::pkf::operator<<(std::ostream & os, Packet const & packet)
91 // These methods are called by the user codes Packet::ptr's. They
92 // refcount both the Packet and the owning PacketImpl.
93 prefix_ void satcom::pkf::intrusive_ptr_add_ref(Packet const * p)
95 impl::PacketImpl::packet_add_ref(p);
98 prefix_ void satcom::pkf::intrusive_ptr_release(Packet * p)
100 impl::PacketImpl::packet_release(p);
103 prefix_ void satcom::pkf::impl::intrusive_ptr_add_ref(PacketImpl * p)
108 prefix_ void satcom::pkf::impl::intrusive_ptr_release(PacketImpl * p)
114 ///////////////////////////////////////////////////////////////////////////
117 prefix_ satcom::pkf::Packet::iterator satcom::pkf::Packet::begin()
120 return impl_->data_.begin()+begin_;
123 prefix_ satcom::pkf::Packet::iterator satcom::pkf::Packet::end()
126 return impl_->data_.begin()+end_;
129 prefix_ size_t satcom::pkf::Packet::size()
135 prefix_ satcom::pkf::Packet::ptr satcom::pkf::Packet::prev()
138 if (this->self_ == this->impl_->interpreters_.begin())
140 // Re-converting the to a smart pointer is correct here, since the
141 // shared_ptr really uses the intrusive refcount which makes this
142 // operation safe ...
143 return ptr(boost::prior(this->self_)->get(),true);
146 prefix_ satcom::pkf::Packet::ptr satcom::pkf::Packet::head()
149 // Re-converting the to a smart pointer is correct here, since the
150 // shared_ptr really uses the intrusive refcount which makes this
151 // operation safe ...
152 return ptr(this->impl_->interpreters_.front().get(),true);
155 prefix_ satcom::pkf::Packet::~Packet()
157 // FIXME: This is bad ... we cannot check this since this
158 // assertion fails at the moment if the Packet constructor throws
159 // ... hrmpf ... we really need to initialize refcount_ to 0 and
160 // remove the 'false' argument to the ptr constructor in ::create
161 // BOOST_ASSERT( !this->refcount_ && !this->impl_ );
162 SATCOM_PKF_REFC_MSG("] Packet::~Packet (" << this << ")\n");
165 prefix_ void satcom::pkf::Packet::add_ref()
169 SATCOM_PKF_REFC_MSG("] Packet::add_ref (" << this << "): refcount_ = " << this->refcount_ << "\n");
172 prefix_ bool satcom::pkf::Packet::release()
174 BOOST_ASSERT( this->refcount_ > 0 );
176 SATCOM_PKF_REFC_MSG("] Packet::release (" << this << "): refcount_ = " << this->refcount_ << "\n");
177 return !this->refcount_ && !this->impl_;
180 prefix_ bool satcom::pkf::Packet::unlink()
182 SATCOM_PKF_REFC_MSG("] Packet::unlink (" << this << "): refcount_ = " << this->refcount_ << "\n");
184 this->begin_ = this->end_;
185 return !this->refcount_;
188 ///////////////////////////////cci.e///////////////////////////////////////
194 // c-file-style: "satcom"