Separate imp+rep from public interfaces for some clases, Routers,
authorAdam Dickmeiss <adam@indexdata.dk>
Thu, 10 Nov 2005 23:10:42 +0000 (23:10 +0000)
committerAdam Dickmeiss <adam@indexdata.dk>
Thu, 10 Nov 2005 23:10:42 +0000 (23:10 +0000)
Filters, .. Still need to do session+package properly.

14 files changed:
src/Makefile.am
src/filter_backend_test.cpp
src/filter_backend_test.hpp
src/filter_factory.cpp [new file with mode: 0644]
src/filter_factory.hpp
src/filter_z3950_client.cpp
src/filter_z3950_client.hpp
src/pipe.cpp
src/router.hpp
src/router_chain.cpp
src/router_chain.hpp
src/router_flexml.cpp
src/router_flexml.hpp
src/test_filter_factory.cpp

index 65192b0..ed5a00d 100644 (file)
@@ -1,4 +1,4 @@
-## $Id: Makefile.am,v 1.33 2005-11-07 12:32:01 adam Exp $
+## $Id: Makefile.am,v 1.34 2005-11-10 23:10:42 adam Exp $
 
 MAINTAINERCLEANFILES = Makefile.in config.in config.hpp
 
@@ -16,7 +16,7 @@ libyp2_la_SOURCES = \
        router.hpp router_chain.hpp router_chain.cpp \
         router_flexml.hpp router_flexml.cpp \
        thread_pool_observer.cpp thread_pool_observer.hpp \
-       filter.hpp filter.cpp filter_factory.hpp \
+       filter.hpp filter.cpp filter_factory.cpp filter_factory.hpp \
        filter_frontend_net.cpp filter_frontend_net.hpp \
        filter_log.cpp filter_log.hpp \
        filter_virt_db.cpp filter_virt_db.hpp \
index 737ffd2..577e2b1 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: filter_backend_test.cpp,v 1.9 2005-11-03 14:45:16 adam Exp $
+/* $Id: filter_backend_test.cpp,v 1.10 2005-11-10 23:10:42 adam Exp $
    Copyright (c) 2005, Index Data.
 
 %LICENSE%
@@ -9,21 +9,21 @@
 #include "filter.hpp"
 #include "router.hpp"
 #include "package.hpp"
-
-#include <boost/thread/mutex.hpp>
-
 #include "util.hpp"
 #include "filter_backend_test.hpp"
 
+#include <stdexcept>
+#include <list>
+#include <map>
+#include <iostream>
+
+#include <boost/thread/mutex.hpp>
+
 #include <yaz/zgdu.h>
 #include <yaz/log.h>
 #include <yaz/otherinfo.h>
 #include <yaz/diagbib1.h>
 
-#include <list>
-#include <map>
-#include <iostream>
-
 namespace yf = yp2::filter;
 
 namespace yp2 {
index 66afcee..6842af8 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: filter_backend_test.hpp,v 1.4 2005-10-31 09:40:18 marc Exp $
+/* $Id: filter_backend_test.hpp,v 1.5 2005-11-10 23:10:42 adam Exp $
    Copyright (c) 2005, Index Data.
 
 %LICENSE%
@@ -7,8 +7,6 @@
 #ifndef FILTER_BACKEND_TEST_HPP
 #define FILTER_BACKEND_TEST_HPP
 
-#include <stdexcept>
-#include <list>
 #include <boost/scoped_ptr.hpp>
 
 #include "filter.hpp"
diff --git a/src/filter_factory.cpp b/src/filter_factory.cpp
new file mode 100644 (file)
index 0000000..6cbca63
--- /dev/null
@@ -0,0 +1,78 @@
+/* $Id: filter_factory.cpp,v 1.1 2005-11-10 23:10:42 adam Exp $
+   Copyright (c) 2005, Index Data.
+
+%LICENSE%
+ */
+
+#include "filter_factory.hpp"
+
+#include <stdexcept>
+#include <iostream>
+#include <string>
+#include <map>
+
+namespace yp2 {
+    class FilterFactory::Rep {
+    public:
+        friend class FilterFactory;
+        CallbackMap m_fcm;
+        Rep();
+        ~Rep();
+    };
+}
+
+yp2::FilterFactoryException::FilterFactoryException(const std::string message)
+    : std::runtime_error("FilterException: " + message)
+{
+}
+
+yp2::FilterFactory::Rep::Rep()
+{
+}
+
+yp2::FilterFactory::Rep::~Rep()
+{
+}
+
+yp2::FilterFactory::FilterFactory() : m_p(new yp2::FilterFactory::Rep)
+{
+
+}
+
+yp2::FilterFactory::~FilterFactory()
+{
+
+}
+
+bool yp2::FilterFactory::add_creator(std::string fi,
+                                     CreateFilterCallback cfc)
+{
+    return m_p->m_fcm.insert(CallbackMap::value_type(fi, cfc)).second;
+}
+
+
+bool yp2::FilterFactory::drop_creator(std::string fi)
+{
+    return m_p->m_fcm.erase(fi) == 1;
+}
+
+yp2::filter::Base* yp2::FilterFactory::create(std::string fi)
+{
+    CallbackMap::const_iterator it = m_p->m_fcm.find(fi);
+    
+    if (it == m_p->m_fcm.end()){
+        std::string msg = "filter type '" + fi + "' not found";
+            throw yp2::FilterFactoryException(msg);
+    }
+    // call create function
+    return (it->second());
+}
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * c-file-style: "stroustrup"
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
index 29630a6..320f86f 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: filter_factory.hpp,v 1.5 2005-11-07 21:57:10 adam Exp $
+/* $Id: filter_factory.hpp,v 1.6 2005-11-10 23:10:42 adam Exp $
    Copyright (c) 2005, Index Data.
 
 %LICENSE%
 #include <string>
 #include <map>
 
+#include <boost/noncopyable.hpp>
+#include <boost/scoped_ptr.hpp>
+
 #include "filter.hpp"
 
 
 namespace yp2 {
 
-    namespace filter {
-    
     class FilterFactoryException : public std::runtime_error {
     public:
-        FilterFactoryException(const std::string message)
-            : std::runtime_error("FilterException: " + message){
-        };
+        FilterFactoryException(const std::string message);
     };
-
-        class FilterFactory {
-
-        public:
-            typedef yp2::filter::Base* (*CreateFilterCallback)();
-            /// true if registration ok
-
-            FilterFactory(){};
-
-            bool add_creator(std::string fi, CreateFilterCallback cfc);
-            /// true if unregistration ok
-
-            bool drop_creator(std::string fi);
-            
-            /// factory create method
-
-            yp2::filter::Base* create(std::string fi);
-            
-        private:
-            typedef std::map<std::string, CreateFilterCallback> CallbackMap;
-            CallbackMap m_fcm;
-
-        private:
-            /// disabled because class is singleton
-            FilterFactory(const FilterFactory &);
-            
-            /// disabled because class is singleton
-            FilterFactory& operator=(const FilterFactory &);
-        };
-        
-    }
     
-    bool yp2::filter::FilterFactory::add_creator(std::string fi,
-                                    CreateFilterCallback cfc)
+    class FilterFactory : public boost::noncopyable
     {
-        return m_fcm.insert(CallbackMap::value_type(fi, cfc)).second;
-    }
-    
-    
-    bool yp2::filter::FilterFactory::drop_creator(std::string fi)
-    {
-        return m_fcm.erase(fi) == 1;
-    }
-    
-    yp2::filter::Base* yp2::filter::FilterFactory::create(std::string fi)
-    {
-        CallbackMap::const_iterator i = m_fcm.find(fi);
+        typedef yp2::filter::Base* (*CreateFilterCallback)();
+        typedef std::map<std::string, CreateFilterCallback> CallbackMap;
+
+        class Rep;
+    public:
+        /// true if registration ok
         
-        if (i == m_fcm.end()){
-            std::string msg = "filter type '" + fi + "' not found";
-            throw yp2::filter::FilterFactoryException(msg);
-        }
-        // call create function
-        return (i->second());
-    }
-    
+        FilterFactory();
+        ~FilterFactory();
 
-  
+        bool add_creator(std::string fi, CreateFilterCallback cfc);
+        /// true if unregistration ok
+        
+        bool drop_creator(std::string fi);
+        
+        /// factory create method
+        
+        yp2::filter::Base* create(std::string fi);
+        
+    private:
+        boost::scoped_ptr<Rep> m_p;
+    };
 }
 
 #endif
index 190275b..6d51c9e 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: filter_z3950_client.cpp,v 1.10 2005-11-03 14:45:16 adam Exp $
+/* $Id: filter_z3950_client.cpp,v 1.11 2005-11-10 23:10:42 adam Exp $
    Copyright (c) 2005, Index Data.
 
 %LICENSE%
@@ -6,17 +6,20 @@
 
 #include "config.hpp"
 
-#include <map>
 #include "filter.hpp"
 #include "router.hpp"
 #include "package.hpp"
+#include "util.hpp"
+#include "filter_z3950_client.hpp"
+
+#include <map>
+#include <stdexcept>
+#include <list>
+#include <iostream>
 
 #include <boost/thread/mutex.hpp>
 #include <boost/thread/condition.hpp>
 
-#include "util.hpp"
-#include "filter_z3950_client.hpp"
-
 #include <yaz/zgdu.h>
 #include <yaz/log.h>
 #include <yaz/otherinfo.h>
 #include <yaz++/pdu-assoc.h>
 #include <yaz++/z-assoc.h>
 
-#include <iostream>
-
 namespace yf = yp2::filter;
 
 namespace yp2 {
     namespace filter {
         class Z3950Client::Assoc : public yazpp_1::Z_Assoc{
             friend class Rep;
-        public:
             Assoc(yazpp_1::SocketManager *socket_manager,
                   yazpp_1::IPDU_Observable *PDU_Observable,
                   std::string host);
@@ -46,8 +46,7 @@ namespace yp2 {
             yazpp_1::IPDU_Observer* sessionNotify(
                 yazpp_1::IPDU_Observable *the_PDU_Observable,
                 int fd);
-        private:
-            // yp2::Session m_session_id;
+
             yazpp_1::SocketManager *m_socket_manager;
             yazpp_1::IPDU_Observable *m_PDU_Observable;
             Package *m_package;
index 81633ad..a65b021 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: filter_z3950_client.hpp,v 1.4 2005-10-31 09:40:18 marc Exp $
+/* $Id: filter_z3950_client.hpp,v 1.5 2005-11-10 23:10:42 adam Exp $
    Copyright (c) 2005, Index Data.
 
 %LICENSE%
@@ -7,8 +7,6 @@
 #ifndef FILTER_Z3950_CLIENT_HPP
 #define FILTER_Z3950_CLIENT_HPP
 
-#include <stdexcept>
-#include <list>
 #include <boost/scoped_ptr.hpp>
 
 #include "filter.hpp"
index e5ad991..42f009b 100644 (file)
@@ -1,5 +1,4 @@
-
-/* $Id: pipe.cpp,v 1.4 2005-11-08 08:55:41 adam Exp $
+/* $Id: pipe.cpp,v 1.5 2005-11-10 23:10:42 adam Exp $
    Copyright (c) 2005, Index Data.
 
 %LICENSE%
index 38f1ae8..28279de 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: router.hpp,v 1.5 2005-11-03 14:45:16 adam Exp $
+/* $Id: router.hpp,v 1.6 2005-11-10 23:10:42 adam Exp $
    Copyright (c) 2005, Index Data.
 
 %LICENSE%
@@ -7,11 +7,12 @@
 #ifndef ROUTER_HPP
 #define ROUTER_HPP
 
+#include <boost/noncopyable.hpp>
 #include <string>
 #include <stdexcept>
-#include <list>
 
-namespace yp2 {
+namespace yp2 
+{
     namespace filter {
         class Base;
     }
@@ -24,17 +25,15 @@ namespace yp2 {
     };
   
     
-    class Router {
+    class Router : boost::noncopyable {
     public:
         Router(){};
         virtual ~Router(){};
 
         /// determines next Filter to use from current Filter and Package
         virtual const filter::Base *move(const filter::Base *filter,
-                                   const Package *package) const {
-            return 0;
-        };
-
+                                         const Package *package) const = 0;
+        
         /// re-read configuration of routing tables
         //virtual void configure(){};
 
@@ -42,18 +41,8 @@ namespace yp2 {
         //virtual Router & rule(const filter::Base &filter){
         //    return *this;
         //}
-    private:
-        /// disabled because class is singleton
-        Router(const Router &);
-
-        /// disabled because class is singleton
-        Router& operator=(const Router &);
     };
-  
-  
 }
-
 #endif
 /*
  * Local variables:
index 346028c..c9a85fd 100644 (file)
@@ -1,39 +1,54 @@
-/* $Id: router_chain.cpp,v 1.1 2005-10-26 10:55:26 marc Exp $
+/* $Id: router_chain.cpp,v 1.2 2005-11-10 23:10:42 adam Exp $
    Copyright (c) 2005, Index Data.
-
-%LICENSE%
- */
-
+   
+   %LICENSE%
+*/
 
 #include "router_chain.hpp"
 
+#include <list>
 
-const yp2::filter::Base * yp2::RouterChain::move(const filter::Base *filter,                                   const Package *package) const {
-            std::list<const filter::Base *>::const_iterator it;
-            it = m_filter_list.begin();
-            if (filter)
-                {
-                    for (; it != m_filter_list.end(); it++)
-                        if (*it == filter)
-                            {
-                                it++;
-                                break;
-                            }
-                }
-            if (it == m_filter_list.end())
-                {
-                    //throw RouterException("no routing rules known");
-                    return 0;
-                }
-            return *it;
-        };
-
-        yp2::RouterChain & yp2::RouterChain::append(const filter::Base &filter){
-            m_filter_list.push_back(&filter);
-            return *this;
-        };
+namespace yp2 
+{
+    class RouterChain::Rep {
+        friend class RouterChain;
+        std::list<const filter::Base *> m_filter_list;
+    };
+};
+
+yp2::RouterChain::RouterChain() : m_p(new yp2::RouterChain::Rep)
+{
+}
 
+yp2::RouterChain::~RouterChain()
+{
+}
 
+const yp2::filter::Base * yp2::RouterChain::move(const filter::Base *filter,                                   const Package *package) const {
+    std::list<const filter::Base *>::const_iterator it;
+    it = m_p->m_filter_list.begin();
+    if (filter)
+    {
+        for (; it != m_p->m_filter_list.end(); it++)
+            if (*it == filter)
+            {
+                it++;
+                break;
+            }
+    }
+    if (it == m_p->m_filter_list.end())
+    {
+        //throw RouterException("no routing rules known");
+        return 0;
+    }
+    return *it;
+}
+
+yp2::RouterChain & yp2::RouterChain::append(const filter::Base &filter)
+{
+    m_p->m_filter_list.push_back(&filter);
+    return *this;
+}
 
 
 /*
index 294222e..033b277 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: router_chain.hpp,v 1.2 2005-10-26 10:55:26 marc Exp $
+/* $Id: router_chain.hpp,v 1.3 2005-11-10 23:10:42 adam Exp $
    Copyright (c) 2005, Index Data.
 
 %LICENSE%
@@ -7,40 +7,30 @@
 #ifndef ROUTER_CHAIN_HPP
 #define ROUTER_CHAIN_HPP
 
-#include <stdexcept>
-#include <list>
 
 #include "router.hpp"
 
+#include <boost/scoped_ptr.hpp>
+#include <stdexcept>
 
 namespace yp2 {
-    //namespace filter {
-    //    class Base;
-    //}
-    //class Package;
-    
-    
     class RouterChain : public Router {
+        class Rep;
     public:
-        RouterChain(){};
-        virtual ~RouterChain(){};
+        RouterChain();
+        virtual ~RouterChain();
         virtual const filter::Base *move(const filter::Base *filter,
-                                   const Package *package) const;
-
+                                         const Package *package) const;
+        
         RouterChain & append(const filter::Base &filter);
-
-    protected:
-        std::list<const filter::Base *> m_filter_list;
     private:
+        boost::scoped_ptr<Rep> m_p;
         /// disabled because class is singleton
         RouterChain(const RouterChain &);
 
         /// disabled because class is singleton
         RouterChain& operator=(const RouterChain &);
     };
-  
-
-  
 }
 
 #endif
index 914868e..aa4257a 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: router_flexml.cpp,v 1.1 2005-10-26 14:12:00 marc Exp $
+/* $Id: router_flexml.cpp,v 1.2 2005-11-10 23:10:42 adam Exp $
    Copyright (c) 2005, Index Data.
 
 %LICENSE%
@@ -7,6 +7,198 @@
 
 #include "router_flexml.hpp"
 
+#include <iostream>
+#include <map>
+#include <list>
+
+#include <boost/shared_ptr.hpp>
+
+#include <libxml/xmlversion.h>
+#include <libxml/parser.h>
+#include <libxml/tree.h>
+
+namespace yp2 {
+    class RouterFleXML::Rep {
+        friend class RouterFleXML;
+        Rep();
+
+
+        typedef std::map<std::string, boost::shared_ptr<const yp2::filter::Base> >
+                IdFilterMap ;
+        typedef std::list<std::string> FilterIdList;
+        typedef std::map<std::string, FilterIdList > IdRouteMap ;
+
+
+        std::string m_xmlconf;
+        bool m_xinclude;
+        xmlDoc * m_xmlconf_doc;
+        IdFilterMap m_id_filter_map;
+        FilterIdList m_filter_id_list;
+        IdRouteMap m_id_route_map;
+        void xml_dom_error (const xmlNode* node, std::string msg)
+            {
+                std::cerr << "ERROR: " << msg << " <"
+                          << node->name << ">"
+                          << std::endl;
+            }
+
+        void create_filter(std::string type, 
+                           const xmlDoc * xmldoc,
+                           std::string id = "")
+            {
+                std::cout << "Created Filter type='" << type 
+                          << "' id='" << id << "'" << std::endl;
+            }
+
+        void parse_xml_config_dom() {
+   
+            if (!m_xmlconf_doc){    
+                std::cerr << "XML configuration DOM pointer empty" << std::endl;
+            }
+            
+            const xmlNode* root = xmlDocGetRootElement(m_xmlconf_doc);
+            
+            if ((std::string((const char *) root->name) != "yp2")
+                || (std::string((const char *)(root->ns->href)) 
+                    != "http://indexdata.dk/yp2/config/1")
+                )
+                xml_dom_error(root, 
+                              "expected <yp2 xmlns=\"http://indexdata.dk/yp2/config/1\">, got ");
+            
+            
+            for (const struct _xmlAttr *attr = root->properties; attr; attr = attr->next)
+            {
+                if (std::string((const char *)attr->name) == "xmlns")
+                {
+                    const xmlNode *val = attr->children;
+                    if (std::string((const char *)val->content) 
+                        !=  "http://indexdata.dk/yp2/config/1")
+                        xml_dom_error(root, 
+                                      "expected  xmlns=\"http://indexdata.dk/yp2/config/1\", got ");
+                }  
+            }
+            std::cout << "processing /yp2" << std::endl;
+            
+            // process <start> node which is expected first element node
+            const xmlNode* node = jump_to_children(root, XML_ELEMENT_NODE);
+            //for (; node && node->type != XML_ELEMENT_NODE; node = node->next)
+            //    ;
+            
+            check_node_name(node, "start");
+            std::cout << "processing /yp2/start" << std::endl;
+            
+            // process <filters> node which is expected second element node
+            node = jump_to_next(node, XML_ELEMENT_NODE);
+            check_node_name(node, "filters");
+            std::cout << "processing /yp2/filters" << std::endl;
+            
+            // process <filter> nodes  in next level
+            const xmlNode* node2 = jump_to_children(node, XML_ELEMENT_NODE);
+            check_node_name(node2, "filter");
+            
+            unsigned int filter_nr = 0;
+            while(node2 && std::string((const char *)node2->name) ==  "filter"){
+                filter_nr++;
+                std::cout << "processing /yp2/filters/filter[" 
+                          << filter_nr << "]" << std::endl;
+                node2 = jump_to_next(node2, XML_ELEMENT_NODE);
+            }
+            
+            // process <routes> node which is expected third element node
+            node = jump_to_next(node, XML_ELEMENT_NODE);
+            check_node_name(node, "routes");
+            std::cout << "processing /yp2/routes" << std::endl;
+            
+            // process <route> nodes  in next level
+            node2 = jump_to_children(node, XML_ELEMENT_NODE);
+            check_node_name(node2, "route");
+            
+            unsigned int route_nr = 0;
+            while(node2 && std::string((const char *)node2->name) ==  "route"){
+                route_nr++;
+                std::cout << "processing /yp2/routes/route[" 
+                          << route_nr << "]" << std::endl;
+                
+                // process <filter> nodes in third level
+                const xmlNode* node3 
+                    = jump_to_children(node2, XML_ELEMENT_NODE);
+                check_node_name(node3, "filter");
+                
+                unsigned int filter3_nr = 0;
+                while(node3 && std::string((const char *)node3->name) ==  "filter"){
+                    filter3_nr++;
+                    
+                    std::cout << "processing /yp2/routes/route[" 
+                              << route_nr << "]/filter[" 
+                              << filter3_nr << "]" << std::endl;
+                    
+                    node3 = jump_to_next(node3, XML_ELEMENT_NODE);
+                    
+                }
+                node2 = jump_to_next(node2, XML_ELEMENT_NODE);
+            }
+            
+            
+        }
+        
+        
+        const xmlNode* jump_to(const xmlNode* node, int xml_node_type){
+            for (; node && node->type != xml_node_type; node = node->next)
+                ;
+            return node;
+        }
+
+        const xmlNode* jump_to_next(const xmlNode* node, int xml_node_type){
+            node = node->next;
+            for (; node && node->type != xml_node_type; node = node->next)
+                ;
+            return node;
+        }
+        
+        const xmlNode* jump_to_children(const xmlNode* node, int xml_node_type){
+            node = node->children;
+            for (; node && node->type != xml_node_type; node = node->next)
+                ;
+            return node;
+        }
+        
+        void check_node_name(const xmlNode* node, std::string name){
+            if (std::string((const char *)node->name) 
+                !=  name)
+                xml_dom_error(node, "expected  <" + name + ">, got ");
+        }
+    };
+}
+
+
+yp2::RouterFleXML::Rep::Rep() : m_xmlconf(""), m_xinclude(false), m_xmlconf_doc(0)
+{
+}
+
+yp2::RouterFleXML::RouterFleXML(std::string xmlconf) 
+    : m_p(new Rep)
+{            
+    LIBXML_TEST_VERSION;
+    
+    m_p->m_xmlconf = xmlconf;
+    
+    m_p->m_xmlconf_doc = xmlParseMemory(m_p->m_xmlconf.c_str(), m_p->m_xmlconf.size());
+    
+    m_p->parse_xml_config_dom();
+}
+
+yp2::RouterFleXML::~RouterFleXML()
+{
+    xmlFreeDoc(m_p->m_xmlconf_doc);
+}
+
+const yp2::filter::Base *
+yp2::RouterFleXML::move(const yp2::filter::Base *filter,
+                        const yp2::Package *package) const 
+{
+    return 0;
+}
+        
 
 
 /*
index 08744e3..1eae3e8 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: router_flexml.hpp,v 1.5 2005-10-31 11:59:08 marc Exp $
+/* $Id: router_flexml.hpp,v 1.6 2005-11-10 23:10:42 adam Exp $
    Copyright (c) 2005, Index Data.
 
    %LICENSE%
 
 #include "router.hpp"
 
-#include <iostream>
 #include <stdexcept>
-#include <map>
-#include <list>
-
-#include <libxml/xmlversion.h>
-#include <libxml/parser.h>
-#include <libxml/tree.h>
-
-#include <boost/shared_ptr.hpp>
 
+#include <boost/scoped_ptr.hpp>
 
 namespace yp2 
 {
-    
-
     class RouterFleXML : public yp2::Router 
     {
+        class Rep;
     public:
-        RouterFleXML(std::string xmlconf) 
-            :  m_xmlconf(""), m_xinclude(false), m_xmlconf_doc(0)
-            {            
-                LIBXML_TEST_VERSION;
+        RouterFleXML(std::string xmlconf);
         
-                m_xmlconf = xmlconf;
-                m_xinclude = false;
-
-                m_xmlconf_doc 
-                    = xmlParseMemory(m_xmlconf.c_str(), m_xmlconf.size());
-
-                parse_xml_config_dom();
-            }
-
-        ~RouterFleXML()
-            {
-                xmlFreeDoc(m_xmlconf_doc);
-            }
-    
-    
-    private:
-        typedef std::map<std::string, boost::shared_ptr<const yp2::filter::Base> >
-                IdFilterMap ;
-        typedef std::list<std::string> FilterIdList;
-        typedef std::map<std::string, FilterIdList > IdRouteMap ;
-
-    private:
-
-        std::string m_xmlconf;
-        bool m_xinclude;
-        xmlDoc * m_xmlconf_doc;
-        IdFilterMap m_id_filter_map;
-        FilterIdList m_filter_id_list;
-        IdRouteMap m_id_route_map;
-
-        //boost::shared_ptr<T> s_ptr(new T(t));
-
-
-        void xml_dom_error (const xmlNode* node, std::string msg)
-            {
-                std::cerr << "ERROR: " << msg << " <"
-                          << node->name << ">"
-                          << std::endl;
-            }
-    
-        void create_filter(std::string type, 
-                           const xmlDoc * xmldoc,
-                           std::string id = "")
-            {
-                std::cout << "Created Filter type='" << type 
-                          << "' id='" << id << "'" << std::endl;
-            }
+        ~RouterFleXML();
         
-
-        void parse_xml_config_dom() {
-   
-            if (!m_xmlconf_doc){    
-                std::cerr << "XML configuration DOM pointer empty" << std::endl;
-            }
-            
-            const xmlNode* root = xmlDocGetRootElement(m_xmlconf_doc);
-            
-            if ((std::string((const char *) root->name) != "yp2")
-                || (std::string((const char *)(root->ns->href)) 
-                    != "http://indexdata.dk/yp2/config/1")
-                )
-                xml_dom_error(root, 
-                              "expected <yp2 xmlns=\"http://indexdata.dk/yp2/config/1\">, got ");
-            
-            
-            for (const struct _xmlAttr *attr = root->properties; attr; attr = attr->next)
-            {
-                if (std::string((const char *)attr->name) == "xmlns")
-                {
-                    const xmlNode *val = attr->children;
-                    if (std::string((const char *)val->content) 
-                        !=  "http://indexdata.dk/yp2/config/1")
-                        xml_dom_error(root, 
-                                      "expected  xmlns=\"http://indexdata.dk/yp2/config/1\", got ");
-                }  
-            }
-            std::cout << "processing /yp2" << std::endl;
-            
-            // process <start> node which is expected first element node
-            const xmlNode* node = jump_to_children(root, XML_ELEMENT_NODE);
-            //for (; node && node->type != XML_ELEMENT_NODE; node = node->next)
-            //    ;
-            
-            check_node_name(node, "start");
-            std::cout << "processing /yp2/start" << std::endl;
-            
-            // process <filters> node which is expected second element node
-            node = jump_to_next(node, XML_ELEMENT_NODE);
-            check_node_name(node, "filters");
-            std::cout << "processing /yp2/filters" << std::endl;
-            
-            // process <filter> nodes  in next level
-            const xmlNode* node2 = jump_to_children(node, XML_ELEMENT_NODE);
-            check_node_name(node2, "filter");
-            
-            unsigned int filter_nr = 0;
-            while(node2 && std::string((const char *)node2->name) ==  "filter"){
-                filter_nr++;
-                std::cout << "processing /yp2/filters/filter[" 
-                          << filter_nr << "]" << std::endl;
-                node2 = jump_to_next(node2, XML_ELEMENT_NODE);
-            }
-            
-            // process <routes> node which is expected third element node
-            node = jump_to_next(node, XML_ELEMENT_NODE);
-            check_node_name(node, "routes");
-            std::cout << "processing /yp2/routes" << std::endl;
-            
-            // process <route> nodes  in next level
-            node2 = jump_to_children(node, XML_ELEMENT_NODE);
-            check_node_name(node2, "route");
-            
-            unsigned int route_nr = 0;
-            while(node2 && std::string((const char *)node2->name) ==  "route"){
-                route_nr++;
-                std::cout << "processing /yp2/routes/route[" 
-                          << route_nr << "]" << std::endl;
-                
-                // process <filter> nodes in third level
-                const xmlNode* node3 
-                    = jump_to_children(node2, XML_ELEMENT_NODE);
-                check_node_name(node3, "filter");
-                
-                unsigned int filter3_nr = 0;
-                while(node3 && std::string((const char *)node3->name) ==  "filter"){
-                    filter3_nr++;
-                    
-                    std::cout << "processing /yp2/routes/route[" 
-                              << route_nr << "]/filter[" 
-                              << filter3_nr << "]" << std::endl;
-                    
-                    node3 = jump_to_next(node3, XML_ELEMENT_NODE);
-                    
-                }
-                node2 = jump_to_next(node2, XML_ELEMENT_NODE);
-            }
-            
-            
-        }
-        
-        
-        const xmlNode* jump_to(const xmlNode* node, int xml_node_type){
-            for (; node && node->type != xml_node_type; node = node->next)
-                ;
-            return node;
-        }
-
-        const xmlNode* jump_to_next(const xmlNode* node, int xml_node_type){
-            node = node->next;
-            for (; node && node->type != xml_node_type; node = node->next)
-                ;
-            return node;
-        }
-        
-        const xmlNode* jump_to_children(const xmlNode* node, int xml_node_type){
-            node = node->children;
-            for (; node && node->type != xml_node_type; node = node->next)
-                ;
-            return node;
-        }
-        
-        void check_node_name(const xmlNode* node, std::string name){
-            if (std::string((const char *)node->name) 
-                !=  name)
-                xml_dom_error(node, "expected  <" + name + ">, got ");
-        }
-    
-    
-#if 0
-
-        void parse_xml_config_xmlreader() {   
-
-            xmlTextReader* reader;
-            //reader->SetParserProp(libxml2.PARSER_SUBST_ENTITIES,1);
-            int ret;
-            //reader = xmlReaderForFile(m_xmlconf.c_str(), NULL, 0);
-            reader = xmlReaderWalker(m_xmlconf_doc);
-            if (reader == NULL) {
-                std::cerr << "failed to read XML config file "
-                          << std::endl
-                          << m_xmlconf << std::endl;
-                std::exit(1);
-            }
-
-
-            // root element processing
-            xml_progress_deep_to_element(reader);
-            if (std::string("yp2") != (const char*)xmlTextReaderConstName(reader))
-                xml_error(reader, "root element must be named <yp2>");
-
-            std::cout << "<" << xmlTextReaderConstName(reader);
-
-            //if (xmlTextReaderHasAttributes(reader))
-            //if ((!xmlTextReaderMoveToAttributeNs(reader, NULL,
-            //                         (const xmlChar*)"http://indexdata.dk/yp2/config/1" )))
-            if ((!xmlTextReaderMoveToFirstAttribute(reader))
-                || (! xmlTextReaderIsNamespaceDecl(reader))
-                || (std::string("http://indexdata.dk/yp2/config/1") 
-                    != (const char*)xmlTextReaderConstValue(reader)))
-                xml_error(reader, "expected root element <yp2> in namespace "
-                          "'http://indexdata.dk/yp2/config/1'");
-
-            std::cout << " " << xmlTextReaderConstName(reader) << "=\""  
-                      << xmlTextReaderConstValue(reader) << "\">"  
-                //<< xmlTextReaderIsNamespaceDecl(reader)
-                      << std::endl;
-
-
-            // start element processing
-            xml_progress_deep_to_element(reader);
-            if (std::string("start") != (const char*)xmlTextReaderConstName(reader)
-                || !xmlTextReaderMoveToFirstAttribute(reader)
-                || std::string("route") != (const char*)xmlTextReaderConstName(reader)
-                )
-                xml_error(reader, "start element <start route=\"route_id\"/> expected");
-            std::cout << "<start " << xmlTextReaderConstName(reader) <<  "=\"" 
-                      <<  xmlTextReaderConstValue(reader) << "\"/>" << std::endl;
-            //<< xmlTextReaderGetAttribute(reader, (const xmlChar *)"route") 
-
-
-            // filters element processing
-            xml_progress_flat_to_element(reader);
-        
-            if (std::string("filters") != (const char*)xmlTextReaderConstName(reader)
-                )
-                xml_error(reader, "filters element <filters> expected");
-
-            std::cout << "<filters>" << std::endl;
-                  
-
-            // filter element processing
-            xml_progress_deep_to_element(reader);
-            if (std::string("filter") != (const char*)xmlTextReaderConstName(reader)
-                )
-                xml_error(reader, "filter element <filter id=\"some_id\" "
-                          "type=\"some_type\"/> expected");
-
-            while (std::string("filter") == (const char*)xmlTextReaderConstName(reader)){
-                std::string filter_id;
-                std::string filter_type;
-                if (!xmlTextReaderMoveToFirstAttribute(reader)
-                    || std::string("id") != (const char*)xmlTextReaderConstName(reader))
-                    xml_error(reader, "filter element <filter id=\"some_id\" "
-                              "type=\"some_type\"/> expected");
-                filter_id = (const char*)xmlTextReaderConstValue(reader);
-                if (!xmlTextReaderMoveToNextAttribute(reader)
-                    || std::string("type") != (const char*)xmlTextReaderConstName(reader))
-                    xml_error(reader, "filter element <filter id=\"some_id\" "
-                              "type=\"some_type\"/> expected");
-                filter_type = (const char*)xmlTextReaderConstValue(reader);
-                std::cout << "<filter id=\"" << filter_id 
-                          << "\" type=\"" << filter_type << "\"/>" 
-                          << std::endl;
-                xml_progress_flat_to_element(reader);
-            }
-
-            std::cout << "</filters>" << std::endl;
-
-
-            // routes element processing
-            // xml_progress_flat_to_element(reader);
-            if (std::string("routes") != (const char*)xmlTextReaderConstName(reader)
-                )
-                xml_error(reader, "routes element <routes> expected");
-
-            std::cout << "<routes>" << std::endl;
-            // route element processing
-            xml_progress_deep_to_element(reader);
-            if (std::string("route") != (const char*)xmlTextReaderConstName(reader)
-                )
-                xml_error(reader, "route element <route id=\"some_id\" "
-                          "type=\"some_type\"/> expected");
-            while (std::string("route") == (const char*)xmlTextReaderConstName(reader)){
-                std::string route_id;
-                if (!xmlTextReaderMoveToFirstAttribute(reader)
-                    || std::string("id") != (const char*)xmlTextReaderConstName(reader))
-                    xml_error(reader, "route element <route id=\"some_id\"/> expected");
-                route_id = (const char*)xmlTextReaderConstValue(reader);
-
-
-                std::cout << "<route id=\"" << route_id << "\">" << std::endl;
-                std::cout << "</route>" << std::endl;
-                xml_progress_flat_to_element(reader);
-            }
-
-            std::cout << "</routes>" << std::endl;
-
-            std::cout << "</yp2>" << std::endl;
-
-            xml_debug_print(reader);
-
-
-            // freeing C xml reader libs
-            xmlFreeTextReader(reader);
-            if (ret != 0) {
-                std::cerr << "Parsing failed of XML configuration" 
-                          << std::endl 
-                          << m_xmlconf << std::endl;
-                std::exit(1);
-            }
-        }
-
-        void xml_error ( xmlTextReader* reader, std::string msg)
-            {
-                std::cerr << "ERROR: " << msg << " "
-                          << xmlTextReaderGetParserLineNumber(reader) << ":" 
-                          << xmlTextReaderGetParserColumnNumber(reader) << " " 
-                          << xmlTextReaderConstName(reader) << " "  
-                          << xmlTextReaderDepth(reader) << " " 
-                          << xmlTextReaderNodeType(reader) << std::endl;
-            }
-    
-        void xml_debug_print ( xmlTextReader* reader)
-            {
-                // processing all other elements
-                //while (xmlTextReaderMoveToElement(reader)) // reads next element ??
-                //while (xmlTextReaderNext(reader)) //does not descend, keeps level 
-                while (xmlTextReaderRead(reader)) // descends into all subtree nodes
-                    std::cout << xmlTextReaderGetParserLineNumber(reader) << ":" 
-                              << xmlTextReaderGetParserColumnNumber(reader) << " " 
-                              << xmlTextReaderDepth(reader) << " " 
-                              << xmlTextReaderNodeType(reader) << " "
-                              << "ConstName " << xmlTextReaderConstName(reader) << " "
-                              << std::endl;
-            }
-    
-        bool xml_progress_deep_to_element(xmlTextReader* reader)
-            {
-                bool ret = false;
-                while(xmlTextReaderRead(reader) 
-                      && xmlTextReaderNodeType(reader) !=  XML_ELEMENT_NODE
-                      && !( xmlTextReaderNodeType(reader) 
-                            == XML_READER_TYPE_END_ELEMENT
-                            && 0 == xmlTextReaderDepth(reader))
-                    ) 
-                    ret = true;
-                return ret;
-            }
-    
-        bool xml_progress_flat_to_element(xmlTextReader* reader)
-            {
-                bool ret = false;
-            
-                while(xmlTextReaderNext(reader) 
-                      && xmlTextReaderNodeType(reader) != XML_ELEMENT_NODE
-                      && !( xmlTextReaderNodeType(reader) 
-                            == XML_READER_TYPE_END_ELEMENT
-                            && 0 == xmlTextReaderDepth(reader))
-                    ) {    
-                    ret = true;
-                }
-                return ret;
-            }
-    
-#endif
-
+        virtual const filter::Base *move(const filter::Base *filter,
+                                         const Package *package) const;
+    private:
+        boost::scoped_ptr<Rep> m_p;
     };
  
 };
index a426867..4445a01 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: test_filter_factory.cpp,v 1.4 2005-10-31 09:40:18 marc Exp $
+/* $Id: test_filter_factory.cpp,v 1.5 2005-11-10 23:10:42 adam Exp $
    Copyright (c) 2005, Index Data.
 
 %LICENSE%
@@ -39,13 +39,11 @@ yp2::filter::Base* yfilter_creator(){
 }
 
 
-
-//int main(int argc, char **argv)
 BOOST_AUTO_TEST_CASE( test_filter_factory_1 )
 {
     try {
         
-        yp2::filter::FilterFactory  ffactory;
+        yp2::FilterFactory  ffactory;
         
         XFilter xf;
         YFilter yf;
@@ -75,8 +73,7 @@ BOOST_AUTO_TEST_CASE( test_filter_factory_1 )
 
         BOOST_CHECK(0 != xfilter);
         BOOST_CHECK(0 != yfilter);
-
-        }
+    }
     catch ( ... ) {
         throw;
         BOOST_CHECK (false);
@@ -85,28 +82,24 @@ BOOST_AUTO_TEST_CASE( test_filter_factory_1 )
     std::exit(0);
 }
 
+// get function - right val in assignment
+//std::string name() const {
+//return m_name;
+//  return "Base";
+//}
 
+// set function - left val in assignment
+//std::string & name() {
+//    return m_name;
+//}
 
+// set function - can be chained
+//Base & name(const std::string & name){
+//  m_name = name;
+//  return *this;
+//}
 
 
-            // get function - right val in assignment
-            //std::string name() const {
-                //return m_name;
-            //  return "Base";
-            //}
-            
-            // set function - left val in assignment
-            //std::string & name() {
-            //    return m_name;
-            //}
-            
-            // set function - can be chained
-            //Base & name(const std::string & name){
-            //  m_name = name;
-            //  return *this;
-            //}
-            
-
 /*
  * Local variables:
  * c-basic-offset: 4