747c7940663e6a404649cef32169bb82925a8a2f
[senf.git] / senf / Packets / PacketData.cci
1 // $Id$
2 //
3 // Copyright (C) 2007
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Stefan Bund <g0dil@berlios.de>
7 //
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.
12 //
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.
17 //
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.
22
23 /** \file
24     \brief PacketData inline non-template implementation */
25
26 // Custom includes
27 #include <senf/Utils/senfassert.hh>
28 #include <iterator>
29 #include "PacketImpl.hh"
30 // #include "PacketParser.hh"
31
32 #define prefix_ inline
33 ///////////////////////////////cci.p///////////////////////////////////////
34
35 ///////////////////////////////////////////////////////////////////////////
36 // senf::PacketData
37
38 prefix_ senf::detail::PacketImpl & senf::PacketData::impl()
39     const
40 {
41     SENF_ASSERT(
42         impl_,
43         "Internal failure: PacketData (PacketInterpreter) instance not part of any Packet?");
44     return *impl_;
45 }
46
47 prefix_ senf::PacketData::iterator senf::PacketData::begin()
48     const
49 {
50     SENF_ASSERT(begin_ <= impl().size(),
51                 "Internal failure: PacketInterpreter range outside of data container");
52     return boost::next(impl().begin(),begin_);
53 }
54
55 prefix_ senf::PacketData::iterator senf::PacketData::end()
56     const
57 {
58     SENF_ASSERT(end_ <= impl().size(),
59                 "Internal failure: PacketInterpreter range outside of data container");
60     return boost::next(impl().begin(),end_);
61 }
62
63 prefix_ senf::PacketData::size_type senf::PacketData::size()
64     const
65 {
66     return end_ - begin_;
67 }
68
69 prefix_ bool senf::PacketData::empty()
70     const
71 {
72     return begin_ == end_;
73 }
74
75 prefix_ senf::PacketData::byte senf::PacketData::operator[](size_type n)
76     const
77 {
78     SENF_ASSERT( n < size(), "Access out of container range" );
79     return *( boost::next(begin(),n) );
80 }
81
82 prefix_ senf::PacketData::byte & senf::PacketData::operator[](size_type n)
83 {
84     SENF_ASSERT( n < size(), "Access out of container range" );
85     return *( boost::next(begin(),n) );
86 }
87
88 // Modifying the raw packet data
89
90 prefix_ void senf::PacketData::insert(iterator pos, byte v)
91 {
92     impl().insert(this,pos,v);
93 }
94
95 prefix_ void senf::PacketData::insert(iterator pos, size_type n, byte v)
96 {
97     impl().insert(this,pos,n,v);
98 }
99
100 prefix_ void senf::PacketData::erase(iterator pos)
101 {
102     impl().erase(this,pos);
103 }
104
105 prefix_ void senf::PacketData::erase(iterator first, iterator last)
106 {
107     impl().erase(this,first,last);
108 }
109
110 prefix_ void senf::PacketData::clear()
111 {
112     impl().clear(this);
113 }
114
115 prefix_ void senf::PacketData::reserve(size_type n)
116 {
117     impl().reserve(n + size() - impl().size());
118 }
119
120 prefix_ senf::PacketData::size_type senf::PacketData::capacity()
121     const
122 {
123     return impl().capacity() - (impl().size() - size());
124 }
125
126 prefix_ bool senf::PacketData::valid()
127 {
128     return impl_;
129 }
130
131 // protected members
132
133 prefix_ senf::PacketData::PacketData(size_type b, size_type e)
134     : impl_(), begin_(b), end_(e)
135 {}
136
137 ///////////////////////////////cci.e///////////////////////////////////////
138 #undef prefix_
139
140 \f
141 // Local Variables:
142 // mode: c++
143 // fill-column: 100
144 // c-file-style: "senf"
145 // indent-tabs-mode: nil
146 // ispell-local-dictionary: "american"
147 // compile-command: "scons -u test"
148 // comment-column: 40
149 // End: