From 5cc9145ea95e0a778bef7ad2a0ea9c1a4824bcc4 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Thu, 10 Nov 2005 23:10:42 +0000 Subject: [PATCH] Separate imp+rep from public interfaces for some clases, Routers, Filters, .. Still need to do session+package properly. --- src/Makefile.am | 4 +- src/filter_backend_test.cpp | 16 +- src/filter_backend_test.hpp | 4 +- src/filter_factory.cpp | 78 +++++++++ src/filter_factory.hpp | 86 +++------- src/filter_z3950_client.cpp | 19 +-- src/filter_z3950_client.hpp | 4 +- src/pipe.cpp | 3 +- src/router.hpp | 25 +-- src/router_chain.cpp | 73 +++++---- src/router_chain.hpp | 28 +--- src/router_flexml.cpp | 194 +++++++++++++++++++++- src/router_flexml.hpp | 381 +------------------------------------------ src/test_filter_factory.cpp | 41 ++--- 14 files changed, 405 insertions(+), 551 deletions(-) create mode 100644 src/filter_factory.cpp diff --git a/src/Makefile.am b/src/Makefile.am index 65192b0..ed5a00d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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 \ diff --git a/src/filter_backend_test.cpp b/src/filter_backend_test.cpp index 737ffd2..577e2b1 100644 --- a/src/filter_backend_test.cpp +++ b/src/filter_backend_test.cpp @@ -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 - #include "util.hpp" #include "filter_backend_test.hpp" +#include +#include +#include +#include + +#include + #include #include #include #include -#include -#include -#include - namespace yf = yp2::filter; namespace yp2 { diff --git a/src/filter_backend_test.hpp b/src/filter_backend_test.hpp index 66afcee..6842af8 100644 --- a/src/filter_backend_test.hpp +++ b/src/filter_backend_test.hpp @@ -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 -#include #include #include "filter.hpp" diff --git a/src/filter_factory.cpp b/src/filter_factory.cpp new file mode 100644 index 0000000..6cbca63 --- /dev/null +++ b/src/filter_factory.cpp @@ -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 +#include +#include +#include + +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 + */ diff --git a/src/filter_factory.hpp b/src/filter_factory.hpp index 29630a6..320f86f 100644 --- a/src/filter_factory.hpp +++ b/src/filter_factory.hpp @@ -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% @@ -12,77 +12,43 @@ #include #include +#include +#include + #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 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 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 m_p; + }; } #endif diff --git a/src/filter_z3950_client.cpp b/src/filter_z3950_client.cpp index 190275b..6d51c9e 100644 --- a/src/filter_z3950_client.cpp +++ b/src/filter_z3950_client.cpp @@ -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 #include "filter.hpp" #include "router.hpp" #include "package.hpp" +#include "util.hpp" +#include "filter_z3950_client.hpp" + +#include +#include +#include +#include #include #include -#include "util.hpp" -#include "filter_z3950_client.hpp" - #include #include #include @@ -26,15 +29,12 @@ #include #include -#include - 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; diff --git a/src/filter_z3950_client.hpp b/src/filter_z3950_client.hpp index 81633ad..a65b021 100644 --- a/src/filter_z3950_client.hpp +++ b/src/filter_z3950_client.hpp @@ -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 -#include #include #include "filter.hpp" diff --git a/src/pipe.cpp b/src/pipe.cpp index e5ad991..42f009b 100644 --- a/src/pipe.cpp +++ b/src/pipe.cpp @@ -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% diff --git a/src/router.hpp b/src/router.hpp index 38f1ae8..28279de 100644 --- a/src/router.hpp +++ b/src/router.hpp @@ -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 #include #include -#include -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: diff --git a/src/router_chain.cpp b/src/router_chain.cpp index 346028c..c9a85fd 100644 --- a/src/router_chain.cpp +++ b/src/router_chain.cpp @@ -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 -const yp2::filter::Base * yp2::RouterChain::move(const filter::Base *filter, const Package *package) const { - std::list::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 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_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; +} /* diff --git a/src/router_chain.hpp b/src/router_chain.hpp index 294222e..033b277 100644 --- a/src/router_chain.hpp +++ b/src/router_chain.hpp @@ -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 -#include #include "router.hpp" +#include +#include 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 m_filter_list; private: + boost::scoped_ptr m_p; /// disabled because class is singleton RouterChain(const RouterChain &); /// disabled because class is singleton RouterChain& operator=(const RouterChain &); }; - - - } #endif diff --git a/src/router_flexml.cpp b/src/router_flexml.cpp index 914868e..aa4257a 100644 --- a/src/router_flexml.cpp +++ b/src/router_flexml.cpp @@ -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 +#include +#include + +#include + +#include +#include +#include + +namespace yp2 { + class RouterFleXML::Rep { + friend class RouterFleXML; + Rep(); + + + typedef std::map > + IdFilterMap ; + typedef std::list FilterIdList; + typedef std::map 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 , 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 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 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 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 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 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 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; +} + /* diff --git a/src/router_flexml.hpp b/src/router_flexml.hpp index 08744e3..1eae3e8 100644 --- a/src/router_flexml.hpp +++ b/src/router_flexml.hpp @@ -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% @@ -6,387 +6,24 @@ #include "router.hpp" -#include #include -#include -#include - -#include -#include -#include - -#include +#include 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 > - IdFilterMap ; - typedef std::list FilterIdList; - typedef std::map 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 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 , 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 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 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 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 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 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 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 "); - - 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 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 expected"); - std::cout << "" << 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 expected"); - - std::cout << "" << std::endl; - - - // filter element processing - xml_progress_deep_to_element(reader); - if (std::string("filter") != (const char*)xmlTextReaderConstName(reader) - ) - xml_error(reader, "filter element 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 expected"); - filter_id = (const char*)xmlTextReaderConstValue(reader); - if (!xmlTextReaderMoveToNextAttribute(reader) - || std::string("type") != (const char*)xmlTextReaderConstName(reader)) - xml_error(reader, "filter element expected"); - filter_type = (const char*)xmlTextReaderConstValue(reader); - std::cout << "" - << std::endl; - xml_progress_flat_to_element(reader); - } - - std::cout << "" << std::endl; - - - // routes element processing - // xml_progress_flat_to_element(reader); - if (std::string("routes") != (const char*)xmlTextReaderConstName(reader) - ) - xml_error(reader, "routes element expected"); - - std::cout << "" << std::endl; - // route element processing - xml_progress_deep_to_element(reader); - if (std::string("route") != (const char*)xmlTextReaderConstName(reader) - ) - xml_error(reader, "route element 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 expected"); - route_id = (const char*)xmlTextReaderConstValue(reader); - - - std::cout << "" << std::endl; - std::cout << "" << std::endl; - xml_progress_flat_to_element(reader); - } - - std::cout << "" << std::endl; - - std::cout << "" << 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 m_p; }; }; diff --git a/src/test_filter_factory.cpp b/src/test_filter_factory.cpp index a426867..4445a01 100644 --- a/src/test_filter_factory.cpp +++ b/src/test_filter_factory.cpp @@ -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 -- 1.7.10.4