00001 // $Id: Packet.cci 1762 2011-01-13 12:20:09Z tho $ 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 // Custom includes 00027 #include <senf/Utils/senfassert.hh> 00028 00029 #define prefix_ inline 00030 //-///////////////////////////////////////////////////////////////////////////////////////////////// 00031 00032 //-///////////////////////////////////////////////////////////////////////////////////////////////// 00033 // senf::Packet 00034 00035 // protected members 00036 00037 prefix_ senf::Packet::Packet(PacketInterpreterBase::ptr const & packet) 00038 : packet_(packet) 00039 {} 00040 00041 prefix_ senf::PacketInterpreterBase::ptr const & senf::Packet::ptr() 00042 const 00043 { 00044 SENF_ASSERT(packet_, "Invalid operation (dereferencing) on in-valid() Packet"); 00045 return packet_; 00046 } 00047 00048 // public structors 00049 00050 prefix_ senf::Packet::Packet() 00051 {} 00052 00053 // public members 00054 00055 prefix_ senf::Packet senf::Packet::clone() 00056 const 00057 { 00058 return Packet(ptr()->clone()); 00059 } 00060 00061 // Interpreter chain access 00062 00063 prefix_ senf::Packet senf::Packet::next(NoThrow_t) 00064 const 00065 { 00066 PacketInterpreterBase::ptr p (ptr()->next()); 00067 if (p) return Packet(p); 00068 PacketInterpreterBase::optional_range r (ptr()->nextPacketRange()); 00069 return (r && ! r->empty()) ? getNext() : Packet(); 00070 } 00071 00072 prefix_ senf::Packet senf::Packet::next() 00073 const 00074 { 00075 Packet p (next(nothrow)); 00076 if (!p) throw InvalidPacketChainException(); 00077 return p; 00078 } 00079 00080 prefix_ senf::Packet senf::Packet::prev(NoThrow_t) 00081 const 00082 { 00083 return Packet(ptr()->prev()); 00084 } 00085 00086 prefix_ senf::Packet senf::Packet::prev() 00087 const 00088 { 00089 Packet p (prev(nothrow)); 00090 if (!p) throw InvalidPacketChainException(); 00091 return p; 00092 } 00093 00094 prefix_ senf::Packet senf::Packet::first() 00095 const 00096 { 00097 return Packet(ptr()->first()); 00098 } 00099 00100 prefix_ senf::Packet senf::Packet::last() 00101 const 00102 { 00103 Packet p (ptr()->last()); 00104 return p.next(nothrow) ? getLast() : p; 00105 } 00106 00107 prefix_ senf::Packet senf::Packet::parseNextAs(factory_t factory) 00108 const 00109 { 00110 return Packet(ptr()->parseNextAs(factory)); 00111 } 00112 00113 prefix_ senf::Packet senf::Packet::append(Packet const & packet) 00114 const 00115 { 00116 return Packet(ptr()->append(packet.ptr())); 00117 } 00118 00119 // Data access 00120 00121 prefix_ senf::PacketData & senf::Packet::data() 00122 const 00123 { 00124 return ptr()->data(); 00125 } 00126 00127 prefix_ senf::Packet::size_type senf::Packet::size() 00128 const 00129 { 00130 return data().size(); 00131 } 00132 00133 // Other methods 00134 00135 prefix_ bool senf::Packet::operator==(Packet const & other) 00136 const 00137 { 00138 return ptr() == other.ptr(); 00139 } 00140 00141 prefix_ void senf::Packet::finalizeThis() 00142 { 00143 ptr()->finalizeThis(); 00144 } 00145 00146 prefix_ void senf::Packet::finalizeTo(Packet const & other) 00147 { 00148 ptr()->finalizeTo(other.ptr()); 00149 } 00150 00151 prefix_ void senf::Packet::finalizeAll() 00152 { 00153 ptr()->finalizeTo(last().ptr()); 00154 } 00155 00156 prefix_ senf::TypeIdValue senf::Packet::typeId() 00157 const 00158 { 00159 return ptr()->typeId(); 00160 } 00161 00162 prefix_ senf::Packet::factory_t senf::Packet::factory() 00163 const 00164 { 00165 return ptr()->factory(); 00166 } 00167 00168 prefix_ unsigned long senf::Packet::id() 00169 const 00170 { 00171 return reinterpret_cast<unsigned long>(&ptr()->impl()); 00172 } 00173 00174 prefix_ bool senf::Packet::boolean_test() 00175 const 00176 { 00177 return packet_ && packet_->valid(); 00178 } 00179 00180 prefix_ bool senf::Packet::valid() 00181 const 00182 { 00183 return *this; 00184 } 00185 00186 prefix_ bool senf::Packet::is_shared() 00187 const 00188 { 00189 return ptr()->is_shared() || (ptr()->impl().refcount() > 1); 00190 } 00191 00192 prefix_ void senf::Packet::reparse() 00193 const 00194 { 00195 return ptr()->reparse(); 00196 } 00197 00198 prefix_ void senf::Packet::clearAnnotations() 00199 { 00200 return ptr()->clearAnnotations(); 00201 } 00202 00203 template <class PacketType, class Parser> 00204 prefix_ Parser senf::operator<<(Parser target, ConcretePacket<PacketType> const & packet) 00205 { 00206 target << packet.parser(); 00207 return target; 00208 } 00209 00210 //-///////////////////////////////////////////////////////////////////////////////////////////////// 00211 #undef prefix_ 00212 00213 00214 // Local Variables: 00215 // mode: c++ 00216 // fill-column: 100 00217 // c-file-style: "senf" 00218 // indent-tabs-mode: nil 00219 // ispell-local-dictionary: "american" 00220 // compile-command: "scons -u test" 00221 // comment-column: 40 00222 // End: