From: tho Date: Thu, 24 Nov 2011 13:37:31 +0000 (+0000) Subject: Packets: another not smart but efficient 'shortcut' for ConcretePacket::next() (like... X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=ecbf10f737b7f1305670600ac0f1134625f14f05;hp=d5b4cca5714c2b44bbc476636a0774b4fcbd9151;p=senf.git Packets: another not smart but efficient 'shortcut' for ConcretePacket::next() (like Rev. #1818) (we have to think about the internal packet refcounting pointer handling) Utils: added const members to Statistic class git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1829 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/senf/Packets/80221Bundle/TLVParser.cc b/senf/Packets/80221Bundle/TLVParser.cc index 10f5381..ce24b1b 100644 --- a/senf/Packets/80221Bundle/TLVParser.cc +++ b/senf/Packets/80221Bundle/TLVParser.cc @@ -332,7 +332,7 @@ prefix_ senf::MIHLengthParser::value_type senf::MIHLengthParser::value() const }; } -prefix_ void senf::MIHLengthParser::value(value_type const & v) +prefix_ void senf::MIHLengthParser::value(value_type v) { switch (bytes() ) { case 1: diff --git a/senf/Packets/80221Bundle/TLVParser.hh b/senf/Packets/80221Bundle/TLVParser.hh index 830494c..2362a10 100644 --- a/senf/Packets/80221Bundle/TLVParser.hh +++ b/senf/Packets/80221Bundle/TLVParser.hh @@ -53,7 +53,7 @@ namespace senf { static value_type const max_value = 4294967295u; value_type value() const; - void value(value_type const & v); + void value(value_type v); MIHLengthParser const & operator= (value_type other); size_type bytes() const; diff --git a/senf/Packets/Packet.cc b/senf/Packets/Packet.cc index 2738b6e..fc828c5 100644 --- a/senf/Packets/Packet.cc +++ b/senf/Packets/Packet.cc @@ -37,14 +37,11 @@ #define prefix_ //-///////////////////////////////////////////////////////////////////////////////////////////////// -prefix_ senf::Packet senf::Packet::getNext(PacketInterpreterBase::optional_range const & range) +prefix_ senf::PacketInterpreterBase::ptr senf::Packet::getNext(PacketInterpreterBase::optional_range const & range) const { factory_t factory (ptr()->nextPacketType()); - if (factory) - return parseNextAs(factory, range); - else - return parseNextAs(); + return parseNextAs(factory ? factory : DataPacket::factory(), range); } prefix_ senf::Packet senf::Packet::getLast() diff --git a/senf/Packets/Packet.cci b/senf/Packets/Packet.cci index c988387..4ec1289 100644 --- a/senf/Packets/Packet.cci +++ b/senf/Packets/Packet.cci @@ -71,7 +71,7 @@ prefix_ senf::Packet senf::Packet::next(NoThrow_t) PacketInterpreterBase::ptr p (ptr()->next()); if (p) return Packet(p); PacketInterpreterBase::optional_range r (ptr()->nextPacketRange()); - return (r && ! r->empty()) ? getNext(r) : Packet(); + return (r && ! r->empty()) ? Packet(getNext(r)) : Packet(); } prefix_ senf::Packet senf::Packet::next() @@ -115,10 +115,11 @@ prefix_ senf::Packet senf::Packet::parseNextAs(factory_t factory) return Packet(ptr()->parseNextAs(factory, ptr()->nextPacketRange())); } -prefix_ senf::Packet senf::Packet::parseNextAs(factory_t factory, PacketInterpreterBase::optional_range const & range) +prefix_ senf::PacketInterpreterBase::ptr +senf::Packet::parseNextAs(factory_t factory, PacketInterpreterBase::optional_range const & range) const { - return Packet(ptr()->parseNextAs(factory, range)); + return ptr()->parseNextAs(factory, range); } prefix_ senf::Packet senf::Packet::append(Packet const & packet) diff --git a/senf/Packets/Packet.ct b/senf/Packets/Packet.ct index d7d58a7..7a40320 100644 --- a/senf/Packets/Packet.ct +++ b/senf/Packets/Packet.ct @@ -65,6 +65,27 @@ prefix_ OtherPacket senf::Packet::rfind(NoThrow_t) } //-///////////////////////////////////////////////////////////////////////////////////////////////// +// senf::ConcretePacket + +template +template +prefix_ OtherPacket senf::ConcretePacket::next(NoThrow_t) + const +{ + PacketInterpreterBase::ptr p (Packet::ptr()->next()); + if (p) + return (p->typeId() == typeIdValue()) ? + OtherPacket(p->as()) : OtherPacket(); + PacketInterpreterBase::optional_range r (type::nextPacketRange(*this)); + if (r && ! r->empty()) { + PacketInterpreterBase::ptr nxt (getNext(r)); + if (nxt && nxt->typeId() == typeIdValue()) + return OtherPacket(nxt->as()); + } + return OtherPacket(); +} + +//-///////////////////////////////////////////////////////////////////////////////////////////////// #undef prefix_ diff --git a/senf/Packets/Packet.cti b/senf/Packets/Packet.cti index 80bb93a..0b70b19 100644 --- a/senf/Packets/Packet.cti +++ b/senf/Packets/Packet.cti @@ -337,7 +337,7 @@ prefix_ senf::Packet senf::ConcretePacket::next(NoThrow_t) PacketInterpreterBase::ptr p (Packet::ptr()->next()); if (p) return Packet(p); PacketInterpreterBase::optional_range r (type::nextPacketRange(*this)); - return (r && ! r->empty()) ? getNext(r) : Packet(); + return (r && ! r->empty()) ? Packet(getNext(r)) : Packet(); } // private members diff --git a/senf/Packets/Packet.hh b/senf/Packets/Packet.hh index af001a5..ab61419 100644 --- a/senf/Packets/Packet.hh +++ b/senf/Packets/Packet.hh @@ -518,8 +518,8 @@ namespace senf { PacketInterpreterBase::ptr const & ptr() const; - Packet parseNextAs(factory_t factory, PacketInterpreterBase::optional_range const & range) const; - Packet getNext(PacketInterpreterBase::optional_range const & range) const; + PacketInterpreterBase::ptr parseNextAs(factory_t factory, PacketInterpreterBase::optional_range const & range) const; + PacketInterpreterBase::ptr getNext(PacketInterpreterBase::optional_range const & range) const; Packet getLast() const; private: @@ -754,7 +754,7 @@ namespace senf { Parser p_; }; - ParserProxy operator->() const; ///< Access packet fields + 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 @@ -777,6 +777,8 @@ namespace senf { using Packet::next; Packet next(NoThrow_t) const; + template + OtherPacket next(NoThrow_t) const; #endif private: @@ -788,6 +790,7 @@ namespace senf { friend class Packet; friend class PacketInterpreter; + template friend class ConcretePacket; }; /** \brief Generic parser copying diff --git a/senf/Utils/Statistics.cci b/senf/Utils/Statistics.cci index 8e7b093..8842ac5 100644 --- a/senf/Utils/Statistics.cci +++ b/senf/Utils/Statistics.cci @@ -39,16 +39,6 @@ //-///////////////////////////////////////////////////////////////////////////////////////////////// //-///////////////////////////////////////////////////////////////////////////////////////////////// -// senf::StatisticsBase::Transform - -prefix_ senf::StatisticsBase::Transform::result_type -senf::StatisticsBase::Transform::operator()(first_argument_type i) - const -{ - return i.second; -} - -//-///////////////////////////////////////////////////////////////////////////////////////////////// // senf::StatisticsBase::OutputEntry prefix_ senf::StatisticsBase::OutputEntry::OutputEntry() @@ -98,7 +88,13 @@ prefix_ senf::StatisticsBase::~StatisticsBase() prefix_ senf::StatisticsBase::CollectorRange senf::StatisticsBase::collectors() { - return senf::make_transform_range(children_, Transform()); + return senf::make_transform_range(children_,__gnu_cxx::select2nd()); +} + +prefix_ senf::StatisticsBase::const_CollectorRange senf::StatisticsBase::collectors() + const +{ + return senf::make_transform_range(children_,__gnu_cxx::select2nd()); } prefix_ float senf::StatisticsBase::min() @@ -136,6 +132,12 @@ prefix_ senf::Statistics & senf::StatisticsBase::base() return v_base(); } +prefix_ senf::Statistics const & senf::StatisticsBase::base() + const +{ + return const_cast(this)->v_base(); +} + prefix_ std::string senf::StatisticsBase::path() const { @@ -143,6 +145,7 @@ prefix_ std::string senf::StatisticsBase::path() } prefix_ senf::StatisticsData senf::StatisticsBase::data() + const { return StatisticsData(min_, avg_, max_, dev_, 0); } diff --git a/senf/Utils/Statistics.hh b/senf/Utils/Statistics.hh index cdea0da..0e79361 100644 --- a/senf/Utils/Statistics.hh +++ b/senf/Utils/Statistics.hh @@ -74,13 +74,10 @@ namespace senf { { typedef std::map Children; - struct Transform { - typedef Children::value_type & first_argument_type; - typedef Collector & result_type; - result_type operator()(first_argument_type i) const; - }; - - typedef boost::transform_iterator ValueIterator; + typedef boost::transform_iterator< ::__gnu_cxx::select2nd, + Children::iterator > collector_iterator; + typedef boost::transform_iterator< ::__gnu_cxx::select2nd, + Children::const_iterator > collector_const_iterator; struct OutputEntry; @@ -88,7 +85,8 @@ namespace senf { //-//////////////////////////////////////////////////////////////////////// // Types - typedef boost::iterator_range CollectorRange; + typedef boost::iterator_range CollectorRange; + typedef boost::iterator_range const_CollectorRange; /** \brief Output connection interface @@ -190,6 +188,10 @@ namespace senf { CollectorRange collectors(); ///< List all child collectors /**< \returns iterator range of child collector references */ + const_CollectorRange collectors() const; + ///< List all child collectors + /**< \returns const iterator range of child collector + references */ Collector & collect(unsigned rank); ///< Register a new collector /**< Adds a collector collecting \a rank values into each @@ -199,6 +201,11 @@ namespace senf { \throws DuplicateRankException if a collector collecting \a rank values already exists. */ + Statistics const & base() const; ///< Get const base statistics object + /**< Returns the base statistics object as const reference. + If this is a child collector, this will return the outermost + statistics object, otherwise it will return + \c *this. */ Statistics & base(); ///< Get base statistics object /**< Returns the base statistics object. If this is a child collector, this will return the outermost @@ -229,10 +236,9 @@ namespace senf { \param[in] n size of sliding average window */ //\} - StatisticsData data(); ///< Get the Statistics data as senf::StatisticsData - /**< Return a Statistic Data object containing values - from this instance. - */ + StatisticsData data() const; ///< Get the Statistics data as senf::StatisticsData + /**< Return a Statistic Data object containing values + from this instance. */ //-////////////////////////////////////////////////////////////////////////