00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00026
00027
00028
00029 #include "Packets.hh"
00030
00031
00032 #define prefix_
00033
00034
00035
00036
00037
00038
00039
00040 prefix_ senf::PacketInterpreterBase::~PacketInterpreterBase()
00041 {}
00042
00043 prefix_ senf::PacketInterpreterBase::ptr senf::PacketInterpreterBase::clone()
00044 {
00045 detail::PacketImpl::Guard p (new detail::PacketImpl(begin(),end()));
00046 ptr pi (appendClone(p.p,begin(),p.p->begin()));
00047 for (ptr i (next()); i; i = i->next())
00048 i->appendClone(p.p,begin(),p.p->begin());
00049 pi->impl().assignAnnotations( impl());
00050 return pi;
00051 }
00052
00053
00054
00055 prefix_ senf::PacketInterpreterBase::ptr senf::PacketInterpreterBase::append(ptr packet)
00056 {
00057 if (next())
00058 impl().truncateInterpreters(next().get());
00059
00060 optional_range r (nextPacketRange());
00061 if (!r)
00062 throw InvalidPacketChainException();
00063
00064 ptr rv (packet->appendClone(&impl(), *r));
00065 rv->data().resize(packet->data().size());
00066 std::copy(packet->data().begin(), packet->data().end(), rv->data().begin());
00067
00068 for (ptr p (packet->next()) ; p ; p = p->next())
00069 p->appendClone(&impl(), packet->data().begin(), rv->data().begin());
00070
00071 return rv;
00072 }
00073
00074 prefix_ void senf::PacketInterpreterBase::reparse()
00075 {
00076 if (next())
00077 impl().truncateInterpreters(next().get());
00078 }
00079
00080
00081
00082 prefix_ void senf::PacketInterpreterBase::dump(std::ostream & os)
00083 {
00084 try {
00085 if (detail::AnnotationRegistry::instance().begin()
00086 != detail::AnnotationRegistry::instance().end()) {
00087 os << "Annotations:\n";
00088 impl().dumpAnnotations(os);
00089 }
00090 v_dump(os);
00091 for (ptr i (next()); i; i = i->next())
00092 i->v_dump(os);
00093 }
00094 catch (senf::Exception & e) {
00095 os << "[Exception: " << e.message() << "]\n";
00096 }
00097 }
00098
00099 prefix_ void senf::PacketInterpreterBase::finalizeThis()
00100 {
00101 v_finalize();
00102 }
00103
00104 prefix_ void senf::PacketInterpreterBase::finalizeTo(ptr other)
00105 {
00106 for (ptr i (other); i.get() != this && i.get(); i = i->prev())
00107 i->finalizeThis();
00108 finalizeThis();
00109 }
00110
00111
00112
00113 prefix_ void senf::PacketInterpreterBase::add_ref()
00114 {
00115 if (impl_ && !refcount())
00116 impl_->add_ref();
00117 intrusive_refcount_t<PacketInterpreterBase>::add_ref();
00118 }
00119
00120 prefix_ void senf::PacketInterpreterBase::release()
00121 {
00122 if (impl_ && refcount()==1)
00123
00124 impl_->release();
00125 if (intrusive_refcount_t<PacketInterpreterBase>::release() && !impl_)
00126 delete this;
00127 }
00128
00129
00130
00131
00132 prefix_ senf::PacketInterpreterBase::Factory::~Factory()
00133 {}
00134
00135
00136 #undef prefix_
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148