From: g0dil Date: Thu, 4 Dec 2008 14:36:34 +0000 (+0000) Subject: Scheduler/Console: Add missing Node conversion operator for to variable attributor X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=f52075dad8b8291570fa2c61ef9b5ec0a04d1e5e;p=senf.git Scheduler/Console: Add missing Node conversion operator for to variable attributor PPI: Change most Packet arguments to const & Packets: Change most Packet arguments to const & Packets: Replace weird operator-> impleemntation git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1002 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/PPI/CloneSource.cc b/PPI/CloneSource.cc index 9abde73..60f8e86 100644 --- a/PPI/CloneSource.cc +++ b/PPI/CloneSource.cc @@ -32,7 +32,7 @@ #define prefix_ ///////////////////////////////cc.p//////////////////////////////////////// -senf::ppi::module::CloneSource::CloneSource(senf::Packet packet) +senf::ppi::module::CloneSource::CloneSource(senf::Packet const & packet) : packet_(packet) { noroute(output); @@ -43,7 +43,7 @@ void senf::ppi::module::CloneSource::request() { output(packet_.clone()); } -void senf::ppi::module::CloneSource::replacePacket(senf::Packet packet) +void senf::ppi::module::CloneSource::replacePacket(senf::Packet const & packet) { packet_ = packet; } diff --git a/PPI/CloneSource.hh b/PPI/CloneSource.hh index 3c767c9..3ce6089 100644 --- a/PPI/CloneSource.hh +++ b/PPI/CloneSource.hh @@ -52,8 +52,8 @@ namespace module { connector::PassiveOutput<> output; - CloneSource(senf::Packet packet); - void replacePacket(senf::Packet packet); + CloneSource(senf::Packet const & packet); + void replacePacket(senf::Packet const & packet); private: void request(); diff --git a/PPI/Connectors.cci b/PPI/Connectors.cci index 122e9e0..3f24b5d 100644 --- a/PPI/Connectors.cci +++ b/PPI/Connectors.cci @@ -258,7 +258,7 @@ prefix_ senf::ppi::connector::InputConnector::InputConnector() //////////////////////////////////////// // private members -prefix_ void senf::ppi::connector::InputConnector::enqueue(Packet p) +prefix_ void senf::ppi::connector::InputConnector::enqueue(Packet const & p) { queue_.push_front(p); v_enqueueEvent(); @@ -273,13 +273,13 @@ prefix_ senf::ppi::connector::InputConnector & senf::ppi::connector::OutputConne return dynamic_cast(Connector::peer()); } -prefix_ void senf::ppi::connector::OutputConnector::operator()(Packet p) +prefix_ void senf::ppi::connector::OutputConnector::operator()(Packet const & p) { if (connected()) peer().enqueue(p); } -prefix_ void senf::ppi::connector::OutputConnector::write(Packet p) +prefix_ void senf::ppi::connector::OutputConnector::write(Packet const & p) { operator()(p); } diff --git a/PPI/Connectors.hh b/PPI/Connectors.hh index 07316b6..2e51e9f 100644 --- a/PPI/Connectors.hh +++ b/PPI/Connectors.hh @@ -350,7 +350,7 @@ namespace connector { InputConnector(); private: - void enqueue(Packet p); + void enqueue(Packet const & p); virtual void v_requestEvent(); virtual void v_enqueueEvent(); @@ -371,9 +371,9 @@ namespace connector { : public virtual Connector { public: - void operator()(Packet p); ///< Send out a packet + void operator()(Packet const & p); ///< Send out a packet - void write(Packet p); ///< Alias for operator()(Packet p) + void write(Packet const & p); ///< Alias for operator()(Packet p) InputConnector & peer() const; diff --git a/PPI/DebugModules.cci b/PPI/DebugModules.cci index d1dc071..1326326 100644 --- a/PPI/DebugModules.cci +++ b/PPI/DebugModules.cci @@ -38,7 +38,7 @@ prefix_ senf::ppi::module::debug::ActiveSource::ActiveSource() noroute(output); } -prefix_ void senf::ppi::module::debug::ActiveSource::submit(Packet packet) +prefix_ void senf::ppi::module::debug::ActiveSource::submit(Packet const & packet) { output(packet); } @@ -68,7 +68,7 @@ prefix_ void senf::ppi::module::debug::PassiveSource::unthrottle() output.unthrottle(); } -prefix_ void senf::ppi::module::debug::PassiveSource::submit(Packet packet) +prefix_ void senf::ppi::module::debug::PassiveSource::submit(Packet const & packet) { packets_.push_back(packet); output.unthrottle(); diff --git a/PPI/DebugModules.hh b/PPI/DebugModules.hh index b826447..1ea0f2b 100644 --- a/PPI/DebugModules.hh +++ b/PPI/DebugModules.hh @@ -84,7 +84,7 @@ namespace debug { ActiveSource(); - void submit(Packet packet); ///< Submit packet + void submit(Packet const & packet); ///< Submit packet /**< \pre boolean_test() is \c true */ bool boolean_test() const; ///< \c true if \a output is not throttled @@ -113,7 +113,7 @@ namespace debug { void throttle(); ///< Throttle output connector void unthrottle(); ///< Unthrottle output connector - void submit(Packet packet); ///< Enqueue packet + void submit(Packet const & packet); ///< Enqueue packet bool empty(); ///< \c true if queue is empty size_type size(); ///< Number of packets in queue diff --git a/PPI/SocketSink.cc b/PPI/SocketSink.cc index 6c03858..f3b724d 100644 --- a/PPI/SocketSink.cc +++ b/PPI/SocketSink.cc @@ -48,7 +48,8 @@ prefix_ void senf::ppi::IPv4SourceForcingDgramWriter::destination(senf::INet4Soc protocolId_ = dest.port(); } -prefix_ void senf::ppi::IPv4SourceForcingDgramWriter::operator()(Handle handle, Packet packet){ +prefix_ void senf::ppi::IPv4SourceForcingDgramWriter::operator()(Handle handle, + Packet const & packet){ sendtoandfrom( handle.fd(), reinterpret_cast (&*packet.data().begin()), @@ -119,7 +120,8 @@ prefix_ void senf::ppi::IPv6SourceForcingDgramWriter::destination(senf::INet6Soc protocolId_ = dest.port(); } -prefix_ void senf::ppi::IPv6SourceForcingDgramWriter::operator()(Handle handle, Packet packet){ +prefix_ void senf::ppi::IPv6SourceForcingDgramWriter::operator()(Handle handle, + Packet const & packet){ sendtoandfrom( handle.fd(), reinterpret_cast (&*packet.data().begin()), diff --git a/PPI/SocketSink.cci b/PPI/SocketSink.cci index 5e1ebda..d34a003 100644 --- a/PPI/SocketSink.cci +++ b/PPI/SocketSink.cci @@ -33,7 +33,8 @@ /////////////////////////////////////////////////////////////////////////// // senf::ppi::ConnectedDgramWriter -prefix_ void senf::ppi::ConnectedDgramWriter::operator()(Handle handle, Packet packet) +prefix_ void senf::ppi::ConnectedDgramWriter::operator()(Handle handle, + Packet const & packet) { handle.write(packet.data()); } diff --git a/PPI/SocketSink.hh b/PPI/SocketSink.hh index 65926d7..742e2db 100644 --- a/PPI/SocketSink.hh +++ b/PPI/SocketSink.hh @@ -57,7 +57,7 @@ namespace ppi { senf::ConnectedCommunicationPolicy>::policy > Handle; ///< Handle type supported by this writer - void operator()(Handle handle, Packet packet); + void operator()(Handle handle, Packet const & packet); ///< Write \a packet to \a handle /**< Write the complete \a packet as a datagram to \a handle. @@ -80,7 +80,7 @@ namespace ppi { void destination(senf::INet4SocketAddress & dest); senf::INet4SocketAddress destination(); - void operator()(Handle handle, Packet packet); + void operator()(Handle handle, Packet const & packet); ///< Write \a packet to \a handle /**< Write the complete \a packet as a datagram to \a handle. @@ -108,7 +108,7 @@ namespace ppi { void destination(senf::INet6SocketAddress & dest); senf::INet6SocketAddress destination(); - void operator()(Handle handle, Packet packet); + void operator()(Handle handle, Packet const & packet); ///< Write \a packet to \a handle /**< Write the complete \a packet as a datagram to \a handle. diff --git a/Packets/Packet.cci b/Packets/Packet.cci index 35bd931..5fb6b13 100644 --- a/Packets/Packet.cci +++ b/Packets/Packet.cci @@ -108,7 +108,7 @@ prefix_ senf::Packet senf::Packet::parseNextAs(factory_t factory) return Packet(ptr()->parseNextAs(factory)); } -prefix_ senf::Packet senf::Packet::append(Packet packet) +prefix_ senf::Packet senf::Packet::append(Packet const & packet) const { return Packet(ptr()->append(packet.ptr())); @@ -131,7 +131,7 @@ prefix_ senf::Packet::size_type senf::Packet::size() // Other methods -prefix_ bool senf::Packet::operator==(Packet other) +prefix_ bool senf::Packet::operator==(Packet const & other) const { return ptr() == other.ptr(); @@ -142,7 +142,7 @@ prefix_ void senf::Packet::finalizeThis() ptr()->finalizeThis(); } -prefix_ void senf::Packet::finalizeTo(Packet other) +prefix_ void senf::Packet::finalizeTo(Packet const & other) { ptr()->finalizeTo(other.ptr()); } diff --git a/Packets/Packet.cti b/Packets/Packet.cti index cfd8919..0eb6ddc 100644 --- a/Packets/Packet.cti +++ b/Packets/Packet.cti @@ -204,28 +204,29 @@ create(ForwardReadableRange const & range, template prefix_ senf::ConcretePacket -senf::ConcretePacket::createAfter(Packet packet) +senf::ConcretePacket::createAfter(Packet const & packet) { return ConcretePacket(interpreter::createAfter(packet.ptr())); } template prefix_ senf::ConcretePacket -senf::ConcretePacket::createAfter(Packet packet, senf::NoInit_t) +senf::ConcretePacket::createAfter(Packet const & packet, senf::NoInit_t) { return ConcretePacket(interpreter::createAfter(packet.ptr(),senf::noinit)); } template prefix_ senf::ConcretePacket -senf::ConcretePacket::createAfter(Packet packet, size_type size) +senf::ConcretePacket::createAfter(Packet const & packet, size_type size) { return ConcretePacket(interpreter::createAfter(packet.ptr(), size)); } template prefix_ senf::ConcretePacket -senf::ConcretePacket::createAfter(Packet packet, size_type size, senf::NoInit_t) +senf::ConcretePacket::createAfter(Packet const & packet, size_type size, + senf::NoInit_t) { return ConcretePacket(interpreter::createAfter(packet.ptr(), size, senf::noinit)); } @@ -235,7 +236,7 @@ senf::ConcretePacket::createAfter(Packet packet, size_type size, sen template template prefix_ senf::ConcretePacket senf::ConcretePacket:: -createAfter(Packet packet, ForwardReadableRange const & range, +createAfter(Packet const & packet, ForwardReadableRange const & range, typename boost::disable_if< boost::is_integral >::type *) { return ConcretePacket(interpreter::createAfter(packet.ptr(), range)); @@ -247,14 +248,14 @@ createAfter(Packet packet, ForwardReadableRange const & range, template prefix_ senf::ConcretePacket -senf::ConcretePacket::createBefore(Packet packet) +senf::ConcretePacket::createBefore(Packet const & packet) { return ConcretePacket(interpreter::createBefore(packet.ptr())); } template prefix_ senf::ConcretePacket -senf::ConcretePacket::createBefore(Packet packet, senf::NoInit_t) +senf::ConcretePacket::createBefore(Packet const & packet, senf::NoInit_t) { return ConcretePacket(interpreter::createBefore(packet.ptr(), senf::noinit)); } @@ -272,19 +273,19 @@ senf::ConcretePacket::clone() // Field access template -prefix_ typename senf::ConcretePacket::Parser * -senf::ConcretePacket::operator->() +prefix_ typename senf::ConcretePacket::Parser +senf::ConcretePacket::parser() const { - return ptr()->fields_p(); + return ptr()->fields(); } template -prefix_ typename senf::ConcretePacket::Parser -senf::ConcretePacket::parser() +prefix_ typename senf::ConcretePacket::ParserProxy +senf::ConcretePacket::operator->() const { - return ptr()->fields(); + return ParserProxy(parser()); } // private members diff --git a/Packets/Packet.hh b/Packets/Packet.hh index 3d51f78..d3b42a4 100644 --- a/Packets/Packet.hh +++ b/Packets/Packet.hh @@ -137,7 +137,7 @@ namespace senf { \ref ConcretePacket for the %type specific interface\n \ref PacketData for the sequence interface\n \ref packetparser for a specification of the parser interface - */ + */ class Packet : public safe_bool, public boost::equality_comparable @@ -148,7 +148,7 @@ namespace senf { typedef void type; ///< Type of the packet. typedef senf::detail::packet::size_type size_type; - ///< Unsigned type to represent packet size + ///< Unsigned type to represent packet size typedef PacketInterpreterBase::factory_t factory_t; ///< Packet factory type (see below) /////////////////////////////////////////////////////////////////////////// @@ -173,9 +173,9 @@ namespace senf { template Packet(ConcretePacket packet); ///< Copy-construct Packet from ConcretePacket - /**< This constructor allows to convert an arbitrary - ConcretePacket into a general Packet, loosing the - protocol specific interface. */ + /**< This constructor allows to convert an arbitrary + ConcretePacket into a general Packet, loosing the + protocol specific interface. */ ///@} /////////////////////////////////////////////////////////////////////////// @@ -183,123 +183,123 @@ namespace senf { ///\name Interpreter chain access ///@{ - Packet next() const; - ///< Get next packet in chain - /**< \throws InvalidPacketChainException if no next packet - exists */ - Packet next(NoThrow_t) const; - ///< Get next packet in chain - /**< \returns in - valid() packet if no next packet - exists */ + Packet next() const; + ///< Get next packet in chain + /**< \throws InvalidPacketChainException if no next packet + exists */ + Packet next(NoThrow_t) const; + ///< Get next packet in chain + /**< \returns in - valid() packet if no next packet + exists */ template OtherPacket next() const; - ///< Get next packet in chain and cast to \a OtherPacket - /**< \throws std::bad_cast if the next() packet is not of - type \a OtherPacket - \throws InvalidPacketChainException if no next packet - exists */ + ///< Get next packet in chain and cast to \a OtherPacket + /**< \throws std::bad_cast if the next() packet is not of + type \a OtherPacket + \throws InvalidPacketChainException if no next packet + exists */ template OtherPacket next(NoThrow_t) const; - ///< Get next packet in chain and cast to \a OtherPacket - /**< \throws std::bad_cast if the next() packet is not of - type \a OtherPacket - \returns in - valid() packet if no next packet - exists */ + ///< Get next packet in chain and cast to \a OtherPacket + /**< \throws std::bad_cast if the next() packet is not of + type \a OtherPacket + \returns in - valid() packet if no next packet + exists */ template OtherPacket find() const; - ///< Search chain forward for packet of type \a OtherPacket - /**< The search will start with the current packet. - \throws InvalidPacketChainException if no packet of - type \a OtherPacket can be found. */ + ///< Search chain forward for packet of type \a OtherPacket + /**< The search will start with the current packet. + \throws InvalidPacketChainException if no packet of + type \a OtherPacket can be found. */ template OtherPacket find(NoThrow_t) const; - ///< Search chain forward for packet of type \a OtherPacket - /**< The search will start with the current packet. - \returns in - valid() packet if no packet of type \a - OtherPacket can be found. */ + ///< Search chain forward for packet of type \a OtherPacket + /**< The search will start with the current packet. + \returns in - valid() packet if no packet of type \a + OtherPacket can be found. */ - Packet prev() const; - ///< Get previous packet in chain - /**< \throws InvalidPacketChainException if no previous - packet exists */ - Packet prev(NoThrow_t) const; - ///< Get previous packet in chain - /**< \returns in - valid() packet if no previous packet - exists */ + Packet prev() const; + ///< Get previous packet in chain + /**< \throws InvalidPacketChainException if no previous + packet exists */ + Packet prev(NoThrow_t) const; + ///< Get previous packet in chain + /**< \returns in - valid() packet if no previous packet + exists */ template OtherPacket prev() const; - ///< Get previous packet in chain and cast to \a OtherPacket - /**< \throws std::bad_cast, if the previous packet is not of - type \a OtherPacket - \throws InvalidPacketChainException if no previous - packet exists */ + ///< Get previous packet in chain and cast to \a OtherPacket + /**< \throws std::bad_cast, if the previous packet is not of + type \a OtherPacket + \throws InvalidPacketChainException if no previous + packet exists */ template OtherPacket prev(NoThrow_t) const; - ///< Get previous packet in chain and cast to \a OtherPacket - /**< \throws std::bad_cast, if the previous packet is not of - type \a OtherPacket - \returns in - valid() packet if no previous packet - exists */ + ///< Get previous packet in chain and cast to \a OtherPacket + /**< \throws std::bad_cast, if the previous packet is not of + type \a OtherPacket + \returns in - valid() packet if no previous packet + exists */ template OtherPacket rfind() const; - ///< Search chain backwards for packet of type \a OtherPacket - /**< The search will start with the current packet. - \throws InvalidPacketChainException if no packet of - type \a OtherPacket can be found. */ + ///< Search chain backwards for packet of type \a OtherPacket + /**< The search will start with the current packet. + \throws InvalidPacketChainException if no packet of + type \a OtherPacket can be found. */ template OtherPacket rfind(NoThrow_t) const; - ///< Search chain backwards for packet of type \a OtherPacket - /**< The search will start with the current packet. - \returns in - valid() packet if no packet of type \a - OtherPacket can be found. */ + ///< Search chain backwards for packet of type \a OtherPacket + /**< The search will start with the current packet. + \returns in - valid() packet if no packet of type \a + OtherPacket can be found. */ - Packet first() const; - ///< Return first packet in chain + Packet first() const; + ///< Return first packet in chain template OtherPacket first() const; - ///< Return first packet in chain and cast - /**< \throws std::bad_cast if the first() packet is not of - type \a OtherPacket */ + ///< Return first packet in chain and cast + /**< \throws std::bad_cast if the first() packet is not of + type \a OtherPacket */ - Packet last() const; - ///< Return last packet in chain + Packet last() const; + ///< Return last packet in chain template OtherPacket last() const; - ///< Return last packet in chain and cast - /**< \throws std::bad_cast if the last() packet is not of - type \a OtherPacket */ + ///< Return last packet in chain and cast + /**< \throws std::bad_cast if the last() packet is not of + type \a OtherPacket */ template OtherPacket parseNextAs() const; - ///< Interpret payload of \c this as \a OtherPacket - /**< parseNextAs() will throw away the packet chain after - the current packet if necessary. It will then parse the - payload section of \c this packet as given by \a - OtherPacket. The new packet is added to the chain after - \c this. - \returns new packet instance sharing the same data and - placed after \c this packet in the chain. */ - Packet parseNextAs(factory_t factory) const; - ///< Interpret payload of \c this as \a factory type packet - /**< parseNextAs() will throw away the packet chain after - the current packet if necessary. It will then parse the - payload section of \c this packet as given by \a - factory. The new packet is added to the chain after - \c this. - \returns new packet instance sharing the same data and - placed after \c this packet in the chain. */ + ///< Interpret payload of \c this as \a OtherPacket + /**< parseNextAs() will throw away the packet chain after + the current packet if necessary. It will then parse the + payload section of \c this packet as given by \a + OtherPacket. The new packet is added to the chain after + \c this. + \returns new packet instance sharing the same data and + placed after \c this packet in the chain. */ + Packet parseNextAs(factory_t factory) const; + ///< Interpret payload of \c this as \a factory type packet + /**< parseNextAs() will throw away the packet chain after + the current packet if necessary. It will then parse the + payload section of \c this packet as given by \a + factory. The new packet is added to the chain after + \c this. + \returns new packet instance sharing the same data and + placed after \c this packet in the chain. */ template bool is() const; - ///< Check, whether \c this packet is of the given type + ///< Check, whether \c this packet is of the given type template OtherPacket as() const; - ///< Cast current packet to the given type - /**< This operations returns a handle to the same packet - header/interpreter however cast to the given - ConcretePacket type. - \throws std::bad_cast if the current packet is not of - type \a OtherPacket */ - - Packet append(Packet packet) const; ///< Append the given packet to \c this packet - /**< This operation will replace the payload section of \c - this packet with \a packet. This operation will replace - the packet chain after \c this packet with a clone of - \a packet and will replace the raw data of the payload - of \c this with the raw data of \a packet. \c this - packet will not share any date with \a packet. - \returns Packet handle to the cloned \a packet, placed - after \c this in the packet/header/interpreter - chain. */ + ///< Cast current packet to the given type + /**< This operations returns a handle to the same packet + header/interpreter however cast to the given + ConcretePacket type. + \throws std::bad_cast if the current packet is not of + type \a OtherPacket */ + + Packet append(Packet const & packet) const; ///< Append the given packet to \c this packet + /**< This operation will replace the payload section of \c + this packet with \a packet. This operation will replace + the packet chain after \c this packet with a clone of + \a packet and will replace the raw data of the payload + of \c this with the raw data of \a packet. \c this + packet will not share any date with \a packet. + \returns Packet handle to the cloned \a packet, placed + after \c this in the packet/header/interpreter + chain. */ ///@} @@ -325,9 +325,9 @@ namespace senf { struct. \code - struct MyAnnotation { + struct MyAnnotation { int value; - }; + }; senf::Packet p (...); @@ -346,11 +346,11 @@ namespace senf { lead to a program crash. \code - struct MyStringAnnotation : senf::ComplexAnnotation { + struct MyStringAnnotation : senf::ComplexAnnotation { std::string value; - }; + }; \endcode - (This type is not POD since \c std::string is not POD) + (This type is not POD since \c std::string is not POD) \see \ref packet_usage_annotation @@ -379,9 +379,9 @@ namespace senf { ///\name Other methods ///@{ - bool operator==(Packet other) const; ///< Check for packet identity - /**< Two packet handles compare equal if they really are the - same packet header in the same packet chain. */ + bool operator==(Packet const & other) const; ///< Check for packet identity + /**< Two packet handles compare equal if they really are the + same packet header in the same packet chain. */ bool boolean_test() const; ///< Check, whether the packet is valid() /**< \see valid() */ bool valid() const; ///< Check, whether the packet is valid() @@ -423,20 +423,20 @@ namespace senf { This call is equivalent to \code - p.finalizeTo(p.next()) + p.finalizeTo(p.next()) \endcode */ - void finalizeTo(Packet other); ///< Update calculated fields - /**< The finalize() fammily of members will update - calculated packet fields: checksums, size fields and so - on. This includes any field, which can be set from - other information in the packet. Each concrete packet - type should document, which fields are set by - finalize(). + void finalizeTo(Packet const & other); ///< Update calculated fields + /**< The finalize() fammily of members will update + calculated packet fields: checksums, size fields and so + on. This includes any field, which can be set from + other information in the packet. Each concrete packet + type should document, which fields are set by + finalize(). - finalizeTo(other) will automatically process all - packets/headers/interpreters beginning at \a other - backwards towards outer packets up to \c this. */ + finalizeTo(other) will automatically process all + packets/headers/interpreters beginning at \a other + backwards towards outer packets up to \c this. */ void finalizeAll(); ///< Update calculated fields /**< The finalize() fammily of members will update @@ -449,35 +449,35 @@ namespace senf { finalizeAll() will automatically process all packets/headers/interpreters from the end of the chain (the most inner packet) backwards up to \c this. - + This call is equivalent to \code - p.finalizeTo(p.last()) + p.finalizeTo(p.last()) \endcode - + Beware, that finalizeAll() will \e not finalize any headers before \c this, it will \e only process inner headers. */ void dump(std::ostream & os) const; ///< Write out a printable packet representation - /**< This method is provided mostly to help debugging packet - problems. Each concrete packet should implement a dump - method writing out all fields of the packet in a - readable representation. dump() will call this member - for each packet/header/interpreter in the chain from \c - this packet up to the end of the chain. */ + /**< This method is provided mostly to help debugging packet + problems. Each concrete packet should implement a dump + method writing out all fields of the packet in a + readable representation. dump() will call this member + for each packet/header/interpreter in the chain from \c + this packet up to the end of the chain. */ TypeIdValue typeId() const; ///< Get id of \c this packet - /**< This value is used e.g. in the packet registry to - associate packet types with other information. - \returns A type holding the same information as a - type_info object, albeit assignable */ + /**< This value is used e.g. in the packet registry to + associate packet types with other information. + \returns A type holding the same information as a + type_info object, albeit assignable */ factory_t factory() const; ///< Return factory instance of \c this packet - /**< The returned factory instance can be used to create new - packets of the given type without knowing the concrete - type of the packet. The value may be stored away for - later use if needed. */ - + /**< The returned factory instance can be used to create new + packets of the given type without knowing the concrete + type of the packet. The value may be stored away for + later use if needed. */ + ///@} protected: @@ -488,9 +488,9 @@ namespace senf { private: Packet checkNext() const; Packet checkLast() const; - + PacketInterpreterBase::ptr packet_; - + template friend class ConcretePacket; friend class PacketParserBase; @@ -508,13 +508,13 @@ namespace senf { The new members provided by ConcretePacket over packet are mostly comprised of the packet constructors. These come in three major flavors: - + \li The create() family of constructors will create completely new packets. \li The createAfter() family of constructors will create new packets (with new data for the packet) \e after a given existing packet. \li The createBefore() family of constructors will create new packets (again with new data) \e before a given existing packet. - + Whereas create() will create a completely new packet with it's own chain and data storage, createAfter() and createBefore() extend a packet with additional headers/interpreters. createAfter() will set the payload of the given packet to the new @@ -524,10 +524,10 @@ namespace senf { createAfter() differs from Packet::parseNextAs() in that the former creates a new packet \e replacing any possibly existing data whereas the latter will interpret the already \e existing data as given by the type argument. - + \see \ref PacketTypeBase for a specification of the interface to be provided by the \a PacketType policy class. - */ + */ template class ConcretePacket : public Packet @@ -535,7 +535,7 @@ namespace senf { public: /////////////////////////////////////////////////////////////////////////// // Types - + typedef PacketType type; typedef typename PacketType::parser Parser; @@ -549,40 +549,40 @@ namespace senf { // no conversion constructors ConcretePacket(); ///< Create uninitialized packet handle - /**< An uninitialized handle is not valid(). It does not - allow any operation except assignment and checking for - validity. */ + /**< An uninitialized handle is not valid(). It does not + allow any operation except assignment and checking for + validity. */ static factory_t factory(); ///< Return factory for packets of specific type - /**< This \e static member is like Packet::factory() for a - specific packet of type \a PacketType */ + /**< This \e static member is like Packet::factory() for a + specific packet of type \a PacketType */ // Create completely new packet static ConcretePacket create(); ///< Create default initialized packet - /**< The packet will be initialized to it's default empty - state. */ + /**< The packet will be initialized to it's default empty + state. */ static ConcretePacket create(senf::NoInit_t); ///< Create uninitialized empty packet - /**< This will create a completely empty and uninitialized - packet with size() == 0. - \param[in] senf::noinit This parameter must always have the - value \c senf::noinit. */ + /**< This will create a completely empty and uninitialized + packet with size() == 0. + \param[in] senf::noinit This parameter must always have the + value \c senf::noinit. */ static ConcretePacket create(size_type size); ///< Create default initialized packet - /**< This member will create a default initialized packet - with the given size. If the size parameter is smaller - than the minimum allowed packet size an exception will - be thrown. - \param[in] size Size of the packet to create in bytes. - \throws TruncatedPacketException if \a size is smaller - than the smallest permissible size for this type of - packet. */ + /**< This member will create a default initialized packet + with the given size. If the size parameter is smaller + than the minimum allowed packet size an exception will + be thrown. + \param[in] size Size of the packet to create in bytes. + \throws TruncatedPacketException if \a size is smaller + than the smallest permissible size for this type of + packet. */ static ConcretePacket create(size_type size, senf::NoInit_t); - ///< Create uninitialized packet - /**< Creates an uninitialized (all-zero) packet of the exact - given size. - \param[in] size Size of the packet to create in bytes - \param[in] senf::noinit This parameter must always have the - value \c senf::noinit. */ + ///< Create uninitialized packet + /**< Creates an uninitialized (all-zero) packet of the exact + given size. + \param[in] size Size of the packet to create in bytes + \param[in] senf::noinit This parameter must always have the + value \c senf::noinit. */ #ifndef DOXYGEN template static ConcretePacket create( @@ -591,105 +591,112 @@ namespace senf { #else template static ConcretePacket create(ForwardReadableRange const & range); - ///< Create packet from given data - /**< The packet will be created from a copy of the given - data. The data from the range will be copied directly - into the packet representation. The data will \e not be - validated in any way. - \param[in] range Boost.Range - of data to construct packet from. */ + ///< Create packet from given data + /**< The packet will be created from a copy of the given + data. The data from the range will be copied directly + into the packet representation. The data will \e not be + validated in any way. + \param[in] range Boost.Range + of data to construct packet from. */ #endif // Create packet as new packet after a given packet - static ConcretePacket createAfter(Packet packet); - ///< Create default initialized packet after \a packet - /**< The packet will be initialized to it's default empty - state. It will be appended as next header/interpreter - after \a packet in that packets interpreter chain. - \param[in] packet Packet to append new packet to. */ - static ConcretePacket createAfter(Packet packet, senf::NoInit_t); - ///< Create uninitialized empty packet after\a packet - /**< This will create a completely empty and uninitialized - packet with size() == 0. It will be appended - as next header/interpreter after \a packet in that - packets interpreter chain. - \param[in] packet Packet to append new packet to. - \param[in] senf::noinit This parameter must always have the - value \c senf::noinit. */ - static ConcretePacket createAfter(Packet packet, size_type size); - ///< Create default initialized packet after \a packet - /**< This member will create a default initialized packet - with the given size. If the size parameter is smaller - than the minimum allowed packet size an exception will - be thrown. It will be appended as next - header/interpreter after \a packet in that packets - interpreter chain. - \param[in] packet Packet to append new packet to. - \param[in] size Size of the packet to create in bytes. - \throws TruncatedPacketException if \a size is smaller - than the smallest permissible size for this type of - packet. */ - static ConcretePacket createAfter(Packet packet, size_type size, senf::NoInit_t); - ///< Create uninitialized packet after \a packet - /**< Creates an uninitialized (all-zero) packet of the exact - given size. It will be appended as next - header/interpreter after \a packet in that packets - interpreter chain. - \param[in] packet Packet to append new packet to. - \param[in] size Size of the packet to create in bytes - \param[in] senf::noinit This parameter must always have the - value \c senf::noinit. */ + static ConcretePacket createAfter(Packet const & packet); + ///< Create default initialized packet after \a packet + /**< The packet will be initialized to it's default empty + state. It will be appended as next header/interpreter + after \a packet in that packets interpreter chain. + \param[in] packet Packet to append new packet to. */ + static ConcretePacket createAfter(Packet const & packet, senf::NoInit_t); + ///< Create uninitialized empty packet after\a packet + /**< This will create a completely empty and uninitialized + packet with size() == 0. It will be appended + as next header/interpreter after \a packet in that + packets interpreter chain. + \param[in] packet Packet to append new packet to. + \param[in] senf::noinit This parameter must always have the + value \c senf::noinit. */ + static ConcretePacket createAfter(Packet const & packet, size_type size); + ///< Create default initialized packet after \a packet + /**< This member will create a default initialized packet + with the given size. If the size parameter is smaller + than the minimum allowed packet size an exception will + be thrown. It will be appended as next + header/interpreter after \a packet in that packets + interpreter chain. + \param[in] packet Packet to append new packet to. + \param[in] size Size of the packet to create in bytes. + \throws TruncatedPacketException if \a size is smaller + than the smallest permissible size for this type of + packet. */ + static ConcretePacket createAfter(Packet const & packet, size_type size, senf::NoInit_t); + ///< Create uninitialized packet after \a packet + /**< Creates an uninitialized (all-zero) packet of the exact + given size. It will be appended as next + header/interpreter after \a packet in that packets + interpreter chain. + \param[in] packet Packet to append new packet to. + \param[in] size Size of the packet to create in bytes + \param[in] senf::noinit This parameter must always have the + value \c senf::noinit. */ #ifndef DOXYGEN template static ConcretePacket createAfter( - Packet packet, + Packet const & packet, ForwardReadableRange const & range, typename boost::disable_if< boost::is_integral >::type * = 0); #else template - static ConcretePacket createAfter(Packet packet, + static ConcretePacket createAfter(Packet const & packet, ForwardReadableRange const & range); - ///< Create packet from given data after \a packet - /**< The packet will be created from a copy of the given - data. The data from the range will be copied directly - into the packet representation. The data will \e not be - validated in any way. It will be appended as next - header/interpreter after \a packet in that packets - interpreter chain. - \param[in] packet Packet to append new packet to. - \param[in] range Boost.Range - of data to construct packet from. */ + ///< Create packet from given data after \a packet + /**< The packet will be created from a copy of the given + data. The data from the range will be copied directly + into the packet representation. The data will \e not be + validated in any way. It will be appended as next + header/interpreter after \a packet in that packets + interpreter chain. + \param[in] packet Packet to append new packet to. + \param[in] range Boost.Range + of data to construct packet from. */ #endif // Create packet as new packet (header) before a given packet - static ConcretePacket createBefore(Packet packet); - ///< Create default initialized packet before \a packet - /**< The packet will be initialized to it's default empty - state. It will be prepended as previous - header/interpreter before \a packet in that packets - interpreter chain. - \param[in] packet Packet to prepend new packet to. */ - static ConcretePacket createBefore(Packet packet, senf::NoInit_t); - ///< Create uninitialized empty packet before \a packet - /**< Creates a completely empty and uninitialized packet. It - will be prepended as previous header/interpreter before - \a packet in that packets interpreter chain. - \param[in] packet Packet to prepend new packet to. */ + static ConcretePacket createBefore(Packet const & packet); + ///< Create default initialized packet before \a packet + /**< The packet will be initialized to it's default empty + state. It will be prepended as previous + header/interpreter before \a packet in that packets + interpreter chain. + \param[in] packet Packet to prepend new packet to. */ + static ConcretePacket createBefore(Packet const & packet, senf::NoInit_t); + ///< Create uninitialized empty packet before \a packet + /**< Creates a completely empty and uninitialized packet. It + will be prepended as previous header/interpreter before + \a packet in that packets interpreter chain. + \param[in] packet Packet to prepend new packet to. */ // Create a clone of the current packet ConcretePacket clone() const; - + ///@} /////////////////////////////////////////////////////////////////////////// - + // Field access - - Parser * operator->() const; ///< Access packet fields + + struct ParserProxy + { + ParserProxy(Parser const & p) : p_ (p) {} + Parser * operator->() { return &p_; } + Parser p_; + }; + + ParserProxy operator->() const; ///< Access packet fields /**< This operator allows to access the parsed fields of the packet using the notation packet->field(). The fields of the packet are specified by the PacketType's diff --git a/Packets/PacketInterpreter.cti b/Packets/PacketInterpreter.cti index f542015..8dd19a9 100644 --- a/Packets/PacketInterpreter.cti +++ b/Packets/PacketInterpreter.cti @@ -60,12 +60,6 @@ prefix_ Annotation & senf::PacketInterpreterBase::annotation() // senf::PacketInterpreter template -prefix_ senf::PacketInterpreter::~PacketInterpreter() -{ - parser_p()->~parser(); -} - -template prefix_ typename senf::PacketInterpreter::factory_t senf::PacketInterpreter::factory() { @@ -132,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 @@ -183,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 @@ -218,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_ diff --git a/Packets/PacketInterpreter.hh b/Packets/PacketInterpreter.hh index 66fc03f..ac38e7d 100644 --- a/Packets/PacketInterpreter.hh +++ b/Packets/PacketInterpreter.hh @@ -30,8 +30,6 @@ #include "../boost/intrusive/ilist.hpp" #include #include -#include -#include #include "../Utils/intrusive_refcount.hh" #include "../Utils/pool_alloc_mixin.hh" #include "../Utils/Tags.hh" @@ -258,8 +256,6 @@ namespace senf { // no copy // no conversion constructors - ~PacketInterpreter(); - static factory_t factory(); // Create completely new packet @@ -296,7 +292,6 @@ namespace senf { // Packet field access parser fields(); - parser * fields_p(); // PacketType access @@ -373,11 +368,6 @@ namespace senf { static const FactoryImpl factory_; - parser * parser_p(); - - boost::aligned_storage< sizeof(parser), - boost::alignment_of::value > parserStorage_; - friend class detail::packet::test::TestDriver; friend class PacketInterpreterBase; friend class FactoryImpl; diff --git a/Packets/PacketRegistry.cti b/Packets/PacketRegistry.cti index 5687850..fa4096d 100644 --- a/Packets/PacketRegistry.cti +++ b/Packets/PacketRegistry.cti @@ -66,14 +66,14 @@ prefix_ typename boost::optional senf::PacketRegistry: } template -prefix_ typename Tag::key_t senf::PacketRegistry::key(Packet packet) +prefix_ typename Tag::key_t senf::PacketRegistry::key(Packet const & packet) { return registry().key(packet.typeId()); } template prefix_ typename boost::optional -senf::PacketRegistry::key(Packet packet, NoThrow_t) +senf::PacketRegistry::key(Packet const & packet, NoThrow_t) { return registry().key(packet.typeId(),true); } diff --git a/Packets/PacketRegistry.hh b/Packets/PacketRegistry.hh index 6164133..2311f3e 100644 --- a/Packets/PacketRegistry.hh +++ b/Packets/PacketRegistry.hh @@ -152,7 +152,7 @@ namespace senf { \returns key of the packet \throws PacketTypeNotRegistered if the packet type is not found in the registry. */ - static typename Tag::key_t key(Packet packet); + static typename Tag::key_t key(Packet const & packet); /** \brief Find key of a packet @@ -163,7 +163,7 @@ namespace senf { href="http://www.boost.org/libs/optional/doc/optional.html">boost::optional or an unbound optional, if the key is not found. */ - static typename boost::optional key(Packet packet, NoThrow_t); + static typename boost::optional key(Packet const & packet, NoThrow_t); /** \brief Lookup a packet by it's key diff --git a/Packets/PacketType.ct b/Packets/PacketType.ct index 8e5d4a6..caec158 100644 --- a/Packets/PacketType.ct +++ b/Packets/PacketType.ct @@ -35,7 +35,7 @@ template prefix_ senf::PacketInterpreterBase::optional_range -senf::PacketTypeMixin::nextPacketRange(Packet p) +senf::PacketTypeMixin::nextPacketRange(Packet const & p) { typename Self::size_type sz (Self::initHeadSize()); ///\idea This if condition could be replaced with a compile time switch by checking, wether diff --git a/Packets/PacketType.cti b/Packets/PacketType.cti index 75be1a7..1b7e693 100644 --- a/Packets/PacketType.cti +++ b/Packets/PacketType.cti @@ -46,7 +46,7 @@ prefix_ senf::PacketTypeBase::factory_t senf::PacketTypeBase::factory() template prefix_ senf::PacketInterpreterBase::optional_range -senf::PacketTypeMixin::nextPacketRange(Packet p) +senf::PacketTypeMixin::nextPacketRange(Packet const & p) { // Call the member defined in the specialization below return PacketTypeMixin::nextPacketRange(p); @@ -54,7 +54,7 @@ senf::PacketTypeMixin::nextPacketRange(Packet p) template prefix_ senf::PacketInterpreterBase::factory_t -senf::PacketTypeMixin::nextPacketType(Packet p) +senf::PacketTypeMixin::nextPacketType(Packet const & p) { if (p.data().size() < Self::initSize()) return Self::no_factory(); @@ -68,14 +68,14 @@ prefix_ senf::PacketInterpreterBase::size_type senf::PacketTypeMixin -prefix_ void senf::PacketTypeMixin::init(Packet p) +prefix_ void senf::PacketTypeMixin::init(Packet const & p) { p.as< ConcretePacket >()->init(); } template prefix_ typename senf::PacketTypeMixin::optional_key_t -senf::PacketTypeMixin::key(Packet p) +senf::PacketTypeMixin::key(Packet const & p) { return p ? PacketRegistry::key(p, nothrow) : optional_key_t(); } @@ -97,7 +97,7 @@ prefix_ senf::PacketInterpreterBase::size_type senf::PacketTypeMixin: } template -prefix_ void senf::PacketTypeMixin::init(Packet p) +prefix_ void senf::PacketTypeMixin::init(Packet const & p) { p.as< ConcretePacket >()->init(); } diff --git a/Packets/PacketType.hh b/Packets/PacketType.hh index e97380b..931ef4b 100644 --- a/Packets/PacketType.hh +++ b/Packets/PacketType.hh @@ -312,7 +312,7 @@ namespace senf { typedef typename Registry::key_t key_t; typedef boost::optional optional_key_t; - static optional_key_t key (Packet p); ///< Find key of packet from registry + static optional_key_t key (Packet const & p); ///< Find key of packet from registry /**< key() will query the registry to find the key of the given packet. Whereas \c nextPacketKey() as implemented by the mixin user will provide the registry key of the @@ -333,10 +333,10 @@ namespace senf { ///\name PacketType interface implementation ///@{ - static PacketInterpreterBase::optional_range nextPacketRange (Packet p); - static PacketInterpreterBase::factory_t nextPacketType (Packet p); + static PacketInterpreterBase::optional_range nextPacketRange (Packet const & p); + static PacketInterpreterBase::factory_t nextPacketType (Packet const & p); static PacketInterpreterBase::size_type initSize (); - static void init (Packet p); + static void init (Packet const & p); ///@} }; @@ -347,9 +347,9 @@ namespace senf { class PacketTypeMixin { public: - static PacketInterpreterBase::optional_range nextPacketRange (Packet p); + static PacketInterpreterBase::optional_range nextPacketRange (Packet const & p); static PacketInterpreterBase::size_type initSize (); - static void init (Packet p); + static void init (Packet const & p); }; # endif diff --git a/Scheduler/Console/Variables.cti b/Scheduler/Console/Variables.cti index f6839be..3c7fd8e 100644 --- a/Scheduler/Console/Variables.cti +++ b/Scheduler/Console/Variables.cti @@ -92,6 +92,22 @@ ConstVariableAttributor(QueryOverload & queryOverload) : queryOverload_ (queryOverload) {} +template +prefix_ senf::console::OverloadedCommandNode & +senf::console::ConstVariableAttributor::node() + const +{ + return queryOverload_.node(); +} + +template +prefix_ senf::console::ConstVariableAttributor:: +operator senf::console::OverloadedCommandNode &() + const +{ + return node(); +} + /////////////////////////////////////////////////////////////////////////// // senf::console::VariableAttributor diff --git a/Scheduler/Console/Variables.hh b/Scheduler/Console/Variables.hh index 2ce1dd2..13fb787 100644 --- a/Scheduler/Console/Variables.hh +++ b/Scheduler/Console/Variables.hh @@ -84,6 +84,9 @@ namespace console { ConstVariableAttributor doc(std::string const & doc); ConstVariableAttributor formatter(Formatter formatter); + OverloadedCommandNode & node() const; ///< Return the node object + operator OverloadedCommandNode & () const; ///< Automatically convert to node object + protected: explicit ConstVariableAttributor(QueryOverload & queryOverload); @@ -100,8 +103,8 @@ namespace console { variables type to set the variable and another one taking no arguments and just querying the current variable value. \code - int var; - ScopedDirectory<> dir; + int var; + ScopedDirectory<> dir; dir.add("var", var); \endcode @@ -118,12 +121,12 @@ namespace console { boost::cref(). Such a variable cannot be changed only queried. Therefore, it does not have the parser() and typeName() attributes. \code - dir.add("const_var", boost::cref(var)) + dir.add("const_var", boost::cref(var)) \endcode \ingroup console_commands */ - template + template class VariableAttributor : public ConstVariableAttributor { @@ -139,36 +142,36 @@ namespace console { VariableAttributor doc(std::string const & doc); ///< Set documentation of the variable VariableAttributor formatter(Formatter formatter); ///< Set formatter - /**< The \a formatter must be a callable with a signature - compatible with - \code - void formatter(Variable const & value, std::ostream & os); - \endcode - The \a formatter takes the return value of the call \a - value and writes it properly formated to \a os. */ + /**< The \a formatter must be a callable with a signature + compatible with + \code + void formatter(Variable const & value, std::ostream & os); + \endcode + The \a formatter takes the return value of the call \a + value and writes it properly formated to \a os. */ VariableAttributor parser(Parser parser); ///< Set argument parser - /**< The parser is an arbitrary callable object with - the signature - \code - void parser(senf::console::ParseCommandInfo::TokensRange const & tokens, value_type & out); - \endcode - - where \c value_type is the type of the overload - parameter. The parser must read and parse the complete - \a tokens range and return the parsed value in \a - out. If the parser fails, it must raise a - senf::console::SyntaxErrorException. */ + /**< The parser is an arbitrary callable object with + the signature + \code + void parser(senf::console::ParseCommandInfo::TokensRange const & tokens, value_type & out); + \endcode + + where \c value_type is the type of the overload + parameter. The parser must read and parse the complete + \a tokens range and return the parsed value in \a + out. If the parser fails, it must raise a + senf::console::SyntaxErrorException. */ VariableAttributor typeName(std::string const & name); ///< Set name of the variable type VariableAttributor onChange(OnChangeHandler handler); ///< Set change callback - /**< The \a handler callback is called, whenever the value - of the variable is changed. The new value has already - been set, when the callback is called, the old value is - passed to the callback. The callback must have a - signature compatible to - \code - void handler(Variable const & oldValue); - \endcode */ + /**< The \a handler callback is called, whenever the value + of the variable is changed. The new value has already + been set, when the callback is called, the old value is + passed to the callback. The callback must have a + signature compatible to + \code + void handler(Variable const & oldValue); + \endcode */ protected: diff --git a/Scheduler/Console/Variables.test.cc b/Scheduler/Console/Variables.test.cc index 9bc58cd..bd3954a 100644 --- a/Scheduler/Console/Variables.test.cc +++ b/Scheduler/Console/Variables.test.cc @@ -79,11 +79,11 @@ BOOST_AUTO_UNIT_TEST(variables) "\n" "Current blorg limit\n"); - dir.add("refvar", boost::ref(var)) + senf::console::CommandNode & refvar (dir.add("refvar", boost::ref(var)) .doc("Current blorg limit") .formatter(&testFormatter) .parser(&testParser) - .typeName("number"); + .typeName("number")); dir.add("crefvar", boost::cref(var)) .doc("Current blorg limit")