From b9b7602d95d03cd65f717dfc6a933fdb6111dd81 Mon Sep 17 00:00:00 2001 From: Roker Date: Mon, 22 Oct 2018 22:56:53 +0200 Subject: [PATCH] remove "consumer API", remove changed queue. it is not necessary! --- pc_container.hh | 46 +++------------------------------------------- 1 file changed, 3 insertions(+), 43 deletions(-) diff --git a/pc_container.hh b/pc_container.hh index 9a83fe8..474d871 100644 --- a/pc_container.hh +++ b/pc_container.hh @@ -38,33 +38,24 @@ public: typename Container::const_iterator begin() const noexcept { return c.cbegin(); } typename Container::const_iterator end() const noexcept { return c.cend(); } + typename Container::iterator begin() noexcept { return c.begin(); } + typename Container::iterator end() noexcept { return c.end(); } + std::size_t size() const noexcept { return c.size(); } bool empty() const noexcept { return c.empty(); } - ////////////////////////////////// - // Producer's API: - ////////////////////////////////// - void insert(Pdata* pd) { c.push_back({ pd, nullptr }); - changed.push_back( c.back() ); } // Beware: does not delete *pdata nor *cdata! That's producer's and consumer's task! void erase(typename Container::const_iterator pos) { - changed.push_back( *pos ); c.erase(pos); } - // notify Consumer about the changed element - void change(typename Container::const_iterator pos) - { - changed.push_back( *pos ); - } - // clear the container. Delete all *pdata via custom deleter functor. void clear(std::function deleter = [](Pdata *e) { delete e; }) { @@ -75,40 +66,9 @@ public: erase(q); } } - - ////////////////////////////////// - // Consumer's API: - ////////////////////////////////// - - std::size_t changed_elements() const { return changed.size(); } - bool has_changed() const { return !changed.empty(); } - - // got oldest element in change queue. - // - // pc.pdata != nullptr && pc.cdata == nullptr : freshly inserted element - // pc.pdata != nullptr && pc.cdata != nullptr : changed element - // pc.pdata == nullptr && pc.cdata != nullptr : erased element - // - // Beware: this blocks if changed queue is empty! - PC get_changed() - { - PC pc = changed.pop_front(); - - // does the element still exists? - if( pc.pdata && - std::find_if( c.cbegin(), c.cend(), [&pc](const PC& element) { return pc.pdata == element.pdata; } ) == c.cend() - ) - { - // No, not anymore. So mark it as erased element for the consumer: - pc.pdata = nullptr; - } - - return pc; - } private: Container c; - ::utility::locked_queue< PC > changed; }; } // end of namespace pEp