X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Packets%2FPacketInterpreter.cti;h=8dd19a97093b2fa78b435adbebfdd5dc6974383d;hb=a1fdb7bb122f0b05be809a922d4b7ef5e125fa67;hp=672436ffe1df66392b1c0cc0c0ddc67e4b99131b;hpb=35dc9a1d15908130991a87d5614ed1f81671d9b4;p=senf.git diff --git a/Packets/PacketInterpreter.cti b/Packets/PacketInterpreter.cti index 672436f..8dd19a9 100644 --- a/Packets/PacketInterpreter.cti +++ b/Packets/PacketInterpreter.cti @@ -50,15 +50,15 @@ prefix_ typename senf::PacketInterpreter::ptr senf::PacketInterpreterBase: static_cast< PacketInterpreter* >(this)); } -/////////////////////////////////////////////////////////////////////////// -// senf::PacketInterpreter - -template -prefix_ senf::PacketInterpreter::~PacketInterpreter() +template +prefix_ Annotation & senf::PacketInterpreterBase::annotation() { - parser_p()->~parser(); + return impl().annotation(); } +/////////////////////////////////////////////////////////////////////////// +// senf::PacketInterpreter + template prefix_ typename senf::PacketInterpreter::factory_t senf::PacketInterpreter::factory() @@ -126,32 +126,6 @@ senf::PacketInterpreter::fields() return parser (data().begin(),&data()); } -template -prefix_ typename senf::PacketInterpreter::parser * -senf::PacketInterpreter::fields_p() -{ - // This is somewhat awkward. We want to allow the user to access the packet's field using the - // 'operator->' member of the packet class (the handle). Now, 'operator->' *must* return a - // pointer to a non-dynamically allocated object. So where should it point to? We need to return - // a pointer to a parser instance, but parser instances are designed to be transient (they are - // invalidated whenever a packet's size is changed). - - // What we do is the following: parserStorage_ is an (initialy uninitialized) storage area - // within the interpreter with enough space (and correct alignment) to take hold of a parser - // instance. In the constructor we use placement new to construct a parser in this area which we - // explicit dispose of in the destructor. Now, whenever the fields_p() member is called, we - // destroy the parser object and recreate it. - - // This does introduce one additional problem: It is not safe for multiple threads to - // concurrently read from the same packet. On the other hand, the packet classes are not - // syncronized in any way and are not safe to use from multiple threads anyways (e.g. the lazy - // packet chain makes some read-only operations change the packet which is not thread safe). - - parser_p()->~parser(); - new (parser_p()) parser (data().begin(),&data()); - return parser_p(); -} - //////////////////////////////////////// // private members @@ -177,17 +151,13 @@ template prefix_ senf::PacketInterpreter::PacketInterpreter(detail::PacketImpl * impl, iterator b, iterator e, Append_t) : PacketInterpreterBase(impl,b,e,Append) -{ - new (parser_p()) parser (data().begin(),&data()); -} +{} template prefix_ senf::PacketInterpreter::PacketInterpreter(detail::PacketImpl * impl, iterator b, iterator e, Prepend_t) : PacketInterpreterBase(impl,b,e,Prepend) -{ - new (parser_p()) parser (data().begin(),&data()); -} +{} // PacketType access @@ -212,13 +182,6 @@ prefix_ void senf::PacketInterpreter::init() return type::init(ConcretePacket(ptr(this))); } -template -prefix_ typename senf::PacketInterpreter::parser * -senf::PacketInterpreter::parser_p() -{ - return reinterpret_cast(&parserStorage_); -} - ///////////////////////////////cti.e/////////////////////////////////////// #undef prefix_