Search:

SENF Extensible Network Framework

  • Home
  • Download
  • Wiki
  • BerliOS
  • ChangeLog
  • Browse SVN
  • Bug Tracker
  • Overview
  • Examples
  • HowTos
  • Glossary
  • PPI
  • Packets
  • Scheduler
  • Socket
  • Utils
  • Console
  • Daemon
  • Logger
  • Termlib
  • Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

PacketInterpreter.cci

Go to the documentation of this file.
00001 // $Id: PacketInterpreter.cci 1742 2010-11-04 14:51:56Z g0dil $
00002 //
00003 // Copyright (C) 2007
00004 // Fraunhofer (FOKUS)
00005 // Competence Center NETwork research (NET), St. Augustin, GERMANY
00006 //     Stefan Bund <g0dil@berlios.de>
00007 //
00008 // This program is free software; you can redistribute it and/or modify
00009 // it under the terms of the GNU General Public License as published by
00010 // the Free Software Foundation; either version 2 of the License, or
00011 // (at your option) any later version.
00012 //
00013 // This program is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 // GNU General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU General Public License
00019 // along with this program; if not, write to the
00020 // Free Software Foundation, Inc.,
00021 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00022 
00026 // Custom includes
00027 #include <senf/Utils/senfassert.hh>
00028 #include <boost/utility.hpp>
00029 
00030 #define prefix_ inline
00031 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00032 
00033 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00034 // senf::PacketInterpreterBase
00035 
00036 // Structors and default members
00037 
00038 prefix_ senf::PacketInterpreterBase::factory_t senf::PacketInterpreterBase::no_factory()
00039 {
00040     return 0;
00041 }
00042 
00043 // Interpreter chain access
00044 
00045 prefix_ senf::PacketInterpreterBase::ptr senf::PacketInterpreterBase::next()
00046 {
00047     return ptr(impl().next(this));
00048 }
00049 
00050 prefix_ senf::PacketInterpreterBase::ptr senf::PacketInterpreterBase::prev()
00051 {
00052     return ptr(impl().prev(this));
00053 }
00054 
00055 prefix_ senf::PacketInterpreterBase::ptr senf::PacketInterpreterBase::first()
00056 {
00057     return ptr(impl().first());
00058 }
00059 
00060 prefix_ senf::PacketInterpreterBase::ptr senf::PacketInterpreterBase::last()
00061 {
00062     return ptr(impl().last());
00063 }
00064 
00065 prefix_ senf::PacketInterpreterBase::ptr
00066 senf::PacketInterpreterBase::parseNextAs(factory_t factory)
00067 {
00068     return factory->parseNext(ptr(this));
00069 }
00070 
00071 // Data access
00072 
00073 prefix_ senf::PacketData & senf::PacketInterpreterBase::data()
00074 {
00075     return (*this);
00076 }
00077 
00078 // Access to the abstract interface
00079 
00080 prefix_ senf::PacketInterpreterBase::optional_range
00081 senf::PacketInterpreterBase::nextPacketRange()
00082 {
00083     return v_nextPacketRange();
00084 }
00085 
00086 prefix_ senf::TypeIdValue senf::PacketInterpreterBase::typeId()
00087 {
00088     return v_type();
00089 }
00090 
00091 prefix_ senf::PacketInterpreterBase::factory_t senf::PacketInterpreterBase::factory()
00092 {
00093     return v_factory();
00094 }
00095 
00096 prefix_ senf::PacketInterpreterBase::factory_t senf::PacketInterpreterBase::nextPacketType()
00097 {
00098     return v_nextPacketType();
00099 }
00100 
00101 prefix_ void senf::PacketInterpreterBase::clearAnnotations()
00102 {
00103     return impl().clearAnnotations();
00104 }
00105 
00106 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00107 // protected members
00108 
00109 // protected structors
00110 
00111 prefix_ senf::PacketInterpreterBase::PacketInterpreterBase(detail::PacketImpl * impl,
00112                                                            iterator b, iterator e, Append_t)
00113     : PacketData(std::distance(impl->begin(),b),
00114                  std::distance(impl->begin(),e))
00115 {
00116     impl->appendInterpreter(this);
00117 }
00118 
00119 prefix_ senf::PacketInterpreterBase::PacketInterpreterBase(detail::PacketImpl * impl,
00120                                                            iterator b, iterator e, Prepend_t)
00121     : PacketData(std::distance(impl->begin(),b),
00122                  std::distance(impl->begin(),e))
00123 {
00124     impl->prependInterpreter(this);
00125 }
00126 
00127 prefix_ senf::PacketInterpreterBase::PacketInterpreterBase(detail::PacketImpl * impl,
00128                                                            iterator b, iterator e, ptr before)
00129     : PacketData(std::distance(impl->begin(),b),
00130                  std::distance(impl->begin(),e))
00131 {
00132     impl->prependInterpreter(this, before.get());
00133 }
00134 
00135 prefix_ senf::PacketInterpreterBase::ptr
00136 senf::PacketInterpreterBase::appendClone(detail::PacketImpl * impl, iterator base,
00137                                          iterator new_base)
00138 {
00139     return v_appendClone(impl,base,new_base);
00140 }
00141 
00142 prefix_ senf::PacketInterpreterBase::ptr
00143 senf::PacketInterpreterBase::appendClone(detail::PacketImpl * impl, range r)
00144 {
00145     return v_appendClone(impl,r);
00146 }
00147 
00148 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00149 // private members
00150 
00151 // containment management. Only to be called by PacketImpl.
00152 
00153 prefix_ void senf::PacketInterpreterBase::assignImpl(detail::PacketImpl * impl)
00154 {
00155     SENF_ASSERT(!impl_, "Internal failure: PacketInterpreter added to two Packets");
00156     impl_ = impl;
00157     if (refcount())
00158         impl_->add_ref();
00159 }
00160 
00161 prefix_ void senf::PacketInterpreterBase::releaseImpl()
00162 {
00163     SENF_ASSERT(impl_, "Internal failure: release of lone PacketInterpreter");
00164     if (refcount()) {
00165         detail::PacketImpl * i (impl_);
00166         impl_ = 0;
00167         // This call might delete this ...
00168         i->release();
00169     } else {
00170         impl_ = 0;
00171         delete this;
00172     }
00173 }
00174 
00175 prefix_ void senf::intrusive_ptr_add_ref(PacketInterpreterBase const * p)
00176 {
00177     if (! p->refcount())
00178         const_cast<PacketInterpreterBase *>(p)->add_ref();
00179     else
00180         const_cast<PacketInterpreterBase *>(p)->intrusive_refcount_base::add_ref();
00181 }
00182 
00183 prefix_ void senf::intrusive_ptr_release(PacketInterpreterBase const * p)
00184 {
00185     if (p->refcount() <= 1)
00186         const_cast<PacketInterpreterBase *>(p)->release();
00187     else
00188         const_cast<PacketInterpreterBase *>(p)->intrusive_refcount_base::release();
00189 }
00190 
00191 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00192 #undef prefix_
00193 
00194 
00195 // Local Variables:
00196 // mode: c++
00197 // fill-column: 100
00198 // c-file-style: "senf"
00199 // indent-tabs-mode: nil
00200 // ispell-local-dictionary: "american"
00201 // compile-command: "scons -u test"
00202 // comment-column: 40
00203 // End:

Contact: senf-dev@lists.berlios.de | © 2006-2010 Fraunhofer Institute for Open Communication Systems, Network Research