Packets: Completely restructured #includes, introduced central Packets.hh file
[senf.git] / Packets / PacketImpl.hh
1 // Copyright (C) 2007 
2 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
3 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
4 //     Stefan Bund <g0dil@berlios.de>
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the
18 // Free Software Foundation, Inc.,
19 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20
21 /** \file
22     \brief PacketImpl public header */
23
24 #ifndef HH_PacketImpl_
25 #define HH_PacketImpl_ 1
26
27 // Custom includes
28 #include <memory>
29 #include <boost/utility.hpp>
30 #include "Utils/pool_alloc_mixin.hh"
31 #include "PacketTypes.hh"
32
33 //#include "PacketImpl.mpp"
34 ///////////////////////////////hh.p////////////////////////////////////////
35
36 namespace senf {
37 namespace detail {
38     
39     class PacketImpl 
40         : boost::noncopyable,
41           public pool_alloc_mixin<PacketImpl>
42     {
43     public:
44         typedef senf::detail::packet::byte byte;
45         typedef senf::detail::packet::raw_container raw_container;
46         typedef senf::detail::packet::size_type size_type;
47         typedef senf::detail::packet::difference_type difference_type;
48         typedef senf::detail::packet::interpreter_list interpreter_list;
49         typedef senf::detail::packet::iterator iterator;
50         typedef senf::detail::packet::const_iterator const_iterator;
51         typedef senf::detail::packet::refcount_t refcount_t;
52
53         // structors
54
55         PacketImpl();
56         PacketImpl(size_type size, byte initValue);
57         template <class InputIterator>
58         PacketImpl(InputIterator b, InputIterator e);
59         ~PacketImpl();
60
61         // rerference/memory management
62  
63         void add_ref(refcount_t n=1);
64         void release(refcount_t n=1);
65         refcount_t refcount() const;
66
67         // Interpreter chain
68
69         PacketInterpreterBase * first();
70         PacketInterpreterBase * last();
71
72         PacketInterpreterBase * next(PacketInterpreterBase * p);
73         PacketInterpreterBase * prev(PacketInterpreterBase * p);
74
75         void appendInterpreter    (PacketInterpreterBase * p);
76         void prependInterpreter   (PacketInterpreterBase * p);
77         void truncateInterpreters (PacketInterpreterBase * p);
78         void truncateInterpretersBackwards (PacketInterpreterBase * p);
79
80         // Data container
81
82         iterator begin();
83         iterator end();
84         size_type size();
85
86         void insert(PacketData * self, iterator pos, byte v);
87         void insert(PacketData * self, iterator pos, size_type n, byte v);
88         template <class ForwardIterator>
89         void insert(PacketData * self, iterator pos, ForwardIterator f, ForwardIterator l);
90
91         void erase(PacketData * self, iterator pos);
92         void erase(PacketData * self, iterator first, iterator last);
93         void clear(PacketData * self);
94
95         // The Guard will keep the PacketImpl instance alive during a members execution time
96         // It the refcount should drop to 0, PacketImpl will be deleted after the member
97         // has completed executing.
98         struct Guard {
99             Guard(PacketImpl * impl);
100             ~Guard();
101             PacketImpl * p;
102         };
103
104     private:
105         refcount_t refcount_;
106         raw_container data_;
107         interpreter_list interpreters_;
108
109         void eraseInterpreters(interpreter_list::iterator b, interpreter_list::iterator e);
110         void updateIterators(PacketData * self, iterator pos, difference_type n);
111
112     };
113
114 }}
115
116 ///////////////////////////////hh.e////////////////////////////////////////
117 #endif
118 #if !defined(SENF_PACKETS_DECL_ONLY) && !defined(HH_PacketImpl_i_)
119 #define HH_PacketImpl_i_
120 #include "PacketImpl.cci"
121 //#include "PacketImpl.ct"
122 #include "PacketImpl.cti"
123 #endif
124
125 \f
126 // Local Variables:
127 // mode: c++
128 // fill-column: 100
129 // c-file-style: "senf"
130 // indent-tabs-mode: nil
131 // ispell-local-dictionary: "american"
132 // compile-command: "scons -u test"
133 // comment-column: 40
134 // End: