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

PacketImpl.cti

Go to the documentation of this file.
00001 // $Id: PacketImpl.cti 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 #include "PacketImpl.ih"
00027 
00028 // Custom includes
00029 
00030 #define prefix_ inline
00031 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00032 
00033 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00034 // senf::detail::AnnotationRegistry
00035 
00036 template <class Annotation>
00037 prefix_ senf::detail::AnnotationRegistry::key_type
00038 senf::detail::AnnotationRegistry::registerAnnotation()
00039 {
00040     key_type key (simpleAnnotationCount_ >= SENF_PACKET_ANNOTATION_SLOTS
00041                || IsComplexAnnotation<Annotation>::value
00042                ? - ++complexAnnotationCount_
00043                : simpleAnnotationCount_ ++);
00044     std::pair<Registry::iterator, bool> reg (
00045         registry_.insert(key, new Registration<Annotation>()));
00046     SENF_ASSERT(reg.second, "internal error: duplicate annotation key");
00047     index_.insert(std::make_pair(reg.first->second->v_name(), key));
00048     return key;
00049 }
00050 
00051 template <class Annotation>
00052 prefix_ senf::detail::AnnotationRegistry::key_type senf::detail::AnnotationRegistry::lookup()
00053 {
00054     SENF_ASSERT(
00055         -instance().complexAnnotationCount_ <= AnnotationRegistry::Entry<Annotation>::key()
00056         && AnnotationRegistry::Entry<Annotation>::key() < instance().simpleAnnotationCount_,
00057         "internal error: annotation key not registered" );
00058     SENF_ASSERT(
00059         AnnotationRegistry::Entry<Annotation>::key() < 0
00060         || ! IsComplexAnnotation<Annotation>::value,
00061         "internal error: complex annotation registered with invalid key" );
00062     SENF_ASSERT(
00063         AnnotationRegistry::Entry<Annotation>::key() < SENF_PACKET_ANNOTATION_SLOTS,
00064         "internal error: annotation key out of valid range" );
00065     return AnnotationRegistry::Entry<Annotation>::key();
00066 }
00067 
00068 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00069 // senf::detail::PacketImpl
00070 
00071 // Data container
00072 
00073 template <class ForwardIterator>
00074 prefix_ void senf::detail::PacketImpl::insert(PacketData * self, iterator pos, ForwardIterator f,
00075                                               ForwardIterator l)
00076 {
00077     difference_type ix (std::distance(begin(),pos));
00078     data_.insert(pos,f,l);
00079     updateIterators(self,ix,std::distance(f,l));
00080 }
00081 
00082 template <class InputIterator>
00083 prefix_ senf::detail::PacketImpl::PacketImpl(InputIterator first, InputIterator last)
00084     : refcount_(0), data_(first,last)
00085 {
00086     ::memset(simpleAnnotations_, 0, sizeof(simpleAnnotations_));
00087 }
00088 
00089 // Annotations
00090 
00091 template <class Annotation>
00092 prefix_ Annotation & senf::detail::PacketImpl::annotation()
00093 {
00094     AnnotationRegistry::key_type key (AnnotationRegistry::lookup<Annotation>());
00095     void * antn (key >= 0 ? & simpleAnnotations_[key] : complexAnnotation<Annotation>());
00096     SENF_ASSERT( antn, "internal error: null annotation pointer" );
00097     return * static_cast<Annotation*>(antn);
00098 }
00099 
00100 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00101 #undef prefix_
00102 
00103 
00104 // Local Variables:
00105 // mode: c++
00106 // fill-column: 100
00107 // c-file-style: "senf"
00108 // indent-tabs-mode: nil
00109 // ispell-local-dictionary: "american"
00110 // compile-command: "scons -u test"
00111 // comment-column: 40
00112 // End:

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