Fixed whitespace in all files (no tabs)
[senf.git] / Packets / Packet.mpp
1 // $Id$
2 //
3 // Copyright (C) 2006
4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
6 //     Stefan Bund <stefan.bund@fokus.fraunhofer.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 #if !BOOST_PP_IS_ITERATING
24
25 // Custom includes
26 #include <boost/preprocessor/iteration/iterate.hpp>
27 #include <boost/preprocessor/enum.hpp>
28 #include <boost/preprocessor/cat.hpp>
29
30 #  ifndef MPP_Packet_
31 #    define MPP_Packet_
32 #    define pkARG(z,n,data) BOOST_PP_CAT(A,n) const & BOOST_PP_CAT(a,n)
33 #  else
34 #    undef pkARG
35 #  endif
36
37 #else
38 //////////////////////////////mpp.p////////////////////////////////////////
39
40 #if BOOST_PP_ITERATION_DEPTH()==1 && BOOST_PP_ITERATION_FLAGS()==1
41 ///////////////////////////////////////////////////////////////////////////
42 // Packet::reinterpret member template declaration
43
44 template < class OtherPacket, BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), class A) >
45 typename ptr_t<OtherPacket>::ptr reinterpret( BOOST_PP_ENUM( BOOST_PP_ITERATION(), pkARG, ) );
46
47 #elif BOOST_PP_ITERATION_DEPTH()==1 && BOOST_PP_ITERATION_FLAGS()==2
48 ///////////////////////////////////////////////////////////////////////////
49 // Packet::reinterpret implementation
50
51 template <class OtherPacket, BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), class A) >
52 prefix_ typename senf::Packet::ptr_t<OtherPacket>::ptr
53 senf::Packet::reinterpret( BOOST_PP_ENUM( BOOST_PP_ITERATION(), pkARG, ) )
54 {
55     if (!OtherPacket::check(begin(),end()))
56         throw TruncatedPacketException();
57     typename ptr_t<OtherPacket>::ptr p (
58         new OtherPacket(PacketOp_replace(this),
59                         BOOST_PP_ENUM_PARAMS( BOOST_PP_ITERATION(), a ) ),
60         false);
61     return p;
62 }
63
64 #elif BOOST_PP_ITERATION_DEPTH()==1 && BOOST_PP_ITERATION_FLAGS()==3
65 ///////////////////////////////////////////////////////////////////////////
66 // Packet::registerInterpreter member template declaration
67
68 template < class OtherPacket, BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), class A) >
69 typename ptr_t<OtherPacket>::ptr registerInterpreter(
70     raw_container::iterator begin, raw_container::iterator end,
71     BOOST_PP_ENUM( BOOST_PP_ITERATION(), pkARG, ) ) const;
72
73 #elif BOOST_PP_ITERATION_DEPTH()==1 && BOOST_PP_ITERATION_FLAGS()==4
74 ///////////////////////////////////////////////////////////////////////////
75 // Packet::registerIterpreter implementation
76
77 template <class OtherPacket, BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), class A) >
78 prefix_ typename senf::Packet::ptr_t<OtherPacket>::ptr
79 senf::Packet::registerInterpreter(raw_container::iterator begin,
80                                          raw_container::iterator end,
81                                          BOOST_PP_ENUM( BOOST_PP_ITERATION(), pkARG, ) )
82     const
83 {
84     if (!OtherPacket::check(begin,end))
85         throw TruncatedPacketException();
86     typename ptr_t<OtherPacket>::ptr p (
87         new OtherPacket(PacketOp_register(begin-impl_->data_.begin(),
88                                           end-impl_->data_.begin(),
89                                           this),
90                         BOOST_PP_ENUM_PARAMS( BOOST_PP_ITERATION(), a) ),
91         false);
92     return p;
93 }
94
95 #elif BOOST_PP_ITERATION_DEPTH()==1 && BOOST_PP_ITERATION_FLAGS()==5
96 ///////////////////////////////////////////////////////////////////////////
97 // Packet::create declaration
98
99 template < class OtherPacket, class InputIterator,
100            BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), class A) >
101 static typename senf::Packet::ptr_t<OtherPacket>::ptr create(
102     InputIterator b, InputIterator e,
103     BOOST_PP_ENUM( BOOST_PP_ITERATION(), pkARG, ) );
104
105 #elif BOOST_PP_ITERATION_DEPTH()==1 && BOOST_PP_ITERATION_FLAGS()==6
106 ///////////////////////////////////////////////////////////////////////////
107 // Packet::create implementation
108
109 template < class OtherPacket, class InputIterator,
110            BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), class A) >
111 typename senf::Packet::ptr_t<OtherPacket>::ptr senf::Packet::create(
112     InputIterator b, InputIterator e,
113     BOOST_PP_ENUM( BOOST_PP_ITERATION(), pkARG, ) )
114 {
115     boost::intrusive_ptr<impl::PacketImpl> impl (new impl::PacketImpl(b,e),false);
116     if (!OtherPacket::check(impl->data_.begin(), impl->data_.end()))
117         throw TruncatedPacketException();
118     typename ptr_t<OtherPacket>::ptr p (
119         new OtherPacket(PacketOp_set(impl.get()),
120                         BOOST_PP_ENUM_PARAMS( BOOST_PP_ITERATION(), a) ),
121         false);
122     return p;
123 }
124
125 #endif
126
127 //////////////////////////////mpp.e////////////////////////////////////////
128 #endif
129
130 \f
131 // Local Variables:
132 // mode: c++
133 // fill-column: 100
134 // c-file-style: "senf"
135 // indent-tabs-mode: nil
136 // ispell-local-dictionary: "american"
137 // End: