From 13fcd5f8258bb17fb0f90d512860787220e24e5e Mon Sep 17 00:00:00 2001
From: g0dil <g0dil@wiback.org>
Date: Tue, 3 Feb 2009 10:50:21 +0000
Subject: [PATCH] Utils/Logger: Extend Target routing API

---
 Utils/Logger/Target.cc  | 13 +++++++++++++
 Utils/Logger/Target.cci | 18 ++++++++++++++++++
 Utils/Logger/Target.hh  |  8 ++++++++
 3 files changed, 39 insertions(+)

diff --git a/Utils/Logger/Target.cc b/Utils/Logger/Target.cc
index 2cc923d00..a277dd582 100644
--- a/Utils/Logger/Target.cc
+++ b/Utils/Logger/Target.cc
@@ -85,6 +85,8 @@ prefix_ void senf::log::Target::unroute(std::string const & stream, std::string
 
 prefix_ void senf::log::Target::unroute(int index)
 {
+    if (rib_.empty())
+        return;
     RIB::iterator i;
     if (index < 0) {
         if (RIB::size_type(-index) >= rib_.size())
@@ -110,6 +112,17 @@ prefix_ void senf::log::Target::unroute(int index)
         updateRoutingCache(entry.stream_, entry.area_);
 }
 
+prefix_ void senf::log::Target::clear()
+{
+    RIB old;
+    rib_.swap(old);
+    RIB::const_iterator i (old.begin());
+    RIB::const_iterator const i_end (old.end());
+    for (; i != i_end; ++i)
+        if (i->action_ == ACCEPT)
+            updateRoutingCache(i->stream_, i->area_)
+}
+
 ////////////////////////////////////////
 // private members
 
diff --git a/Utils/Logger/Target.cci b/Utils/Logger/Target.cci
index c7854973d..602793997 100644
--- a/Utils/Logger/Target.cci
+++ b/Utils/Logger/Target.cci
@@ -56,6 +56,24 @@ prefix_ senf::log::Target::iterator senf::log::Target::end()
     return rib_.end();
 }
 
+prefix_ RoutingEntry const & senf::log::Target::operator[](size_type i)
+    size_type size() const
+{
+    return rib_[i];
+}
+
+prefix_ RoutingEntry const & senf::log::Target::operator[](size_type i)
+    size_type size() const
+{
+    return rib_.size();
+}
+
+prefix_ bool senf::log::Target::empty()
+    const
+{
+    return rib_.empty();
+}
+
 ///////////////////////////////////////////////////////////////////////////
 // senf::log::Target::RoutingEntry
 
diff --git a/Utils/Logger/Target.hh b/Utils/Logger/Target.hh
index 622adf1e5..e969f1a8f 100644
--- a/Utils/Logger/Target.hh
+++ b/Utils/Logger/Target.hh
@@ -179,6 +179,7 @@ namespace log {
 
     public:
         typedef RIB::const_iterator iterator; ///< Routing table iterator
+        typedef RIB::size_type size_type;
 
         ///////////////////////////////////////////////////////////////////////////
         ///\name Structors and default members
@@ -332,6 +333,13 @@ namespace log {
         iterator begin() const;         ///< Iterator to beginning of routing table
         iterator end() const;           ///< Iterator past the end of routing table
 
+        RoutingEntry const & operator[](size_type i) ///< Access routing entry
+
+        size_type size() const;         ///< Number of routing table entries
+        bool empty() const;             ///< \c true, if routing table empty, \c false otherwise
+
+        void clear();                   ///< Clear routing table
+
     private:
         void route(detail::StreamBase const * stream, detail::AreaBase const * area,
                    unsigned level, action_t action, int index);
-- 
GitLab