4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@berlios.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.
24 \brief PacketImpl public header */
26 #ifndef HH_PacketImpl_
27 #define HH_PacketImpl_ 1
32 #include <boost/utility.hpp>
33 #include "../Utils/pool_alloc_mixin.hh"
34 #include "PacketTypes.hh"
35 #include "../Utils/singleton.hh"
37 //#include "PacketImpl.mpp"
38 ///////////////////////////////hh.p////////////////////////////////////////
43 struct AnnotationIndexerBase
45 static unsigned maxAnnotations;
46 static std::vector<bool> & small();
49 template <class Annotation>
50 struct AnnotationIndexer
51 : public senf::singleton< AnnotationIndexer<Annotation> >,
52 public AnnotationIndexerBase
56 static unsigned index();
57 static bool const Small = (sizeof(Annotation) <= sizeof(void*));
62 virtual ~AnnotationP();
65 template <class Annotation>
69 Annotation annotation;
72 template <class Annotation, bool Small = AnnotationIndexer<Annotation>::Small>
75 static Annotation & get(AnnotationP * & p);
79 template <class Annotation>
80 struct GetAnnotation<Annotation, true>
82 static Annotation & get(AnnotationP * & p);
86 /** \brief Internal: Packet data storage
90 This is the class holding the packet data and the interpreter chain. All manipulations of
91 the packet data are performed via the interface exported here. This is very important, since
92 PacketImpl will update the interpreters (that is the vector indices stored therein) whenever
97 public pool_alloc_mixin<PacketImpl>
100 typedef senf::detail::packet::byte byte;
101 typedef senf::detail::packet::raw_container raw_container;
102 typedef senf::detail::packet::size_type size_type;
103 typedef senf::detail::packet::difference_type difference_type;
104 typedef senf::detail::packet::interpreter_list interpreter_list;
105 typedef senf::detail::packet::iterator iterator;
106 typedef senf::detail::packet::const_iterator const_iterator;
107 typedef senf::detail::packet::refcount_t refcount_t;
112 PacketImpl(size_type size, byte initValue);
113 template <class InputIterator>
114 PacketImpl(InputIterator b, InputIterator e);
117 // rerference/memory management
119 void add_ref(refcount_t n=1);
120 void release(refcount_t n=1);
121 refcount_t refcount() const;
125 PacketInterpreterBase * first();
126 PacketInterpreterBase * last();
128 PacketInterpreterBase * next(PacketInterpreterBase * p);
129 PacketInterpreterBase * prev(PacketInterpreterBase * p);
131 void appendInterpreter (PacketInterpreterBase * p);
132 void prependInterpreter (PacketInterpreterBase * p);
133 void truncateInterpreters (PacketInterpreterBase * p);
134 void truncateInterpretersBackwards (PacketInterpreterBase * p);
142 void insert(PacketData * self, iterator pos, byte v);
143 void insert(PacketData * self, iterator pos, size_type n, byte v);
144 template <class ForwardIterator>
145 void insert(PacketData * self, iterator pos, ForwardIterator f, ForwardIterator l);
147 void erase(PacketData * self, iterator pos);
148 void erase(PacketData * self, iterator first, iterator last);
149 void clear(PacketData * self);
152 template <class Annotation>
153 Annotation & annotation();
155 /** \brief Internal: Keep PacketImpl instance alive
159 The Guard will keep the PacketImpl instance alive during a members execution time
160 It the refcount should drop to 0, PacketImpl will be deleted after the member
161 has completed executing.
164 Guard(PacketImpl * impl);
170 refcount_t refcount_;
172 interpreter_list interpreters_;
174 typedef std::vector<AnnotationP*> Annotations;
175 Annotations annotations_;
177 void eraseInterpreters(interpreter_list::iterator b, interpreter_list::iterator e);
178 void updateIterators(PacketData * self, difference_type pos, difference_type n);
183 ///////////////////////////////hh.e////////////////////////////////////////
185 #if !defined(HH_Packets__decls_) && !defined(HH_PacketImpl_i_)
186 #define HH_PacketImpl_i_
187 #include "PacketImpl.cci"
188 //#include "PacketImpl.ct"
189 #include "PacketImpl.cti"
196 // c-file-style: "senf"
197 // indent-tabs-mode: nil
198 // ispell-local-dictionary: "american"
199 // compile-command: "scons -u test"
200 // comment-column: 40