From: Marc Cromme Date: Thu, 6 Oct 2005 11:15:23 +0000 (+0000) Subject: name function added to filters X-Git-Tag: YP2.0.0.2~258 X-Git-Url: http://lists.indexdata.com/cgi-bin?a=commitdiff_plain;h=ace216a7a0ef96f3af0bbddd5ba454ef4efa5be2;p=metaproxy-moved-to-github.git name function added to filters --- diff --git a/src/design.h b/src/design.h index bb6f5b1..481b705 100644 --- a/src/design.h +++ b/src/design.h @@ -1,16 +1,14 @@ -#ifndef P3_FILTER_H -#define P3_FILTER_H +#ifndef DESIGN_H +#define DESIGN_H #include -namespace p3 { +namespace yp2 { class Package; - - class Filter { public: virtual ~Filter(){}; @@ -23,24 +21,24 @@ namespace p3 { // get function - returns copy and keeps object const, // thus is right val in assignment - unsigned int max_front_workers() const { - return m_max_front; + std::string name() const { + return m_name; } // set function - returns reference and changes object, // thus is left val in assignment - unsigned int & max_front_workers() { - return m_max_front; + std::string & name() { + return m_name; } // more traditional set function, taking const reference // or copy (here const ref for demo), returning ref to object // can be chained with other similar functions! - Filter & max_front_workers(const unsigned int & max_front){ - m_max_front = max_front; + Filter & name(const std::string & name){ + m_name = name; return *this; } private: - unsigned int m_max_front; + std::string m_name; }; @@ -54,20 +52,23 @@ namespace p3 { class Router { public: + Router(){}; virtual ~Router(){}; - virtual const Filter & - route(const Filter & filter, Package & package) const { + virtual const Filter * + route(const Filter *filter, const Package *package) const { //if (!m_sillyrule) //throw Router_Exception("no routing rules known"); - return m_sillyrule; + return m_filter; }; virtual void configure(){}; - Router & rule(Filter filter){ - m_sillyrule = filter; + Router & rule(const Filter &filter){ + m_filter = &filter; return *this; } private: - Filter m_sillyrule; + Router(const Router &); + Router& operator=(const Router &); + const Filter *m_filter; }; @@ -82,11 +83,12 @@ namespace p3 { public: // send package to it's next filter defined in chain - void move() { - Filter oldfilter; - Filter nextfilter = m_router.route(oldfilter, *this); - nextfilter.process(*this); - } + void move() + { + m_filter = m_router->route(m_filter, this); + if (m_filter) + m_filter->process(*this); + } // get function - returns copy and keeps object const, @@ -110,25 +112,26 @@ namespace p3 { // get function - returns copy and keeps object const, // thus is right val in assignment - Router router() const { - return m_router; - } + //Router router() const { + // return m_router; + //} // set function - returns reference and changes object, // thus is left val in assignment - Router & router() { - return m_router; - } + //Router & router() { + // return m_router; + //} // more traditional set function, taking const reference // or copy (here const ref for demo), returning ref to object // can be chained with other similar functions! - Package & router(const Router & router){ - m_router = router; + Package & router(const Router &router){ + m_router = &router; return *this; } private: unsigned int m_data; - Router m_router; + const Filter *m_filter; + const Router *m_router; }; diff --git a/src/design_main.cpp b/src/design_main.cpp index f5c2820..6f2d2c6 100644 --- a/src/design_main.cpp +++ b/src/design_main.cpp @@ -9,18 +9,15 @@ int main(int argc, char **argv) { // test filter set/get/exception try { std::cout << "\nTRY" << "\n"; - p3::Filter filter; - unsigned int tmp; + yp2::Filter filter; - filter.max_front_workers(1).max_front_workers(2); - tmp = filter.max_front_workers(); - std::cout << "workers: " << tmp << "\n"; + filter.name("filter1"); + std::cout << "filter: " << filter.name() << "\n"; - filter.max_front_workers() = 3; - tmp = filter.max_front_workers(); - std::cout << "workers: " << tmp << "\n"; + filter.name() = "filter1 rename"; + std::cout << "filter: " << filter.name() << "\n"; - throw p3::Filter_Exception("finished"); + throw yp2::Filter_Exception("finished"); } catch (std::exception &e) { std::cout << e.what() << "\n"; @@ -30,20 +27,23 @@ int main(int argc, char **argv) { try { std::cout << "\nTRY" << "\n"; - p3::Filter filter1; - p3::Filter filter2; + yp2::Filter filter1; + filter1.name("filter1"); + + yp2::Filter filter2; + filter2.name() = "filter2"; std::cout << "filter1 filter2" << "\n"; - p3::Router router1; + yp2::Router router1; router1.rule(filter1); std::cout << "router1.rule(filter1)" << "\n"; - p3::Router router2; + yp2::Router router2; router2.rule(filter2); std::cout << "router2.rule(filter2)" << "\n"; - p3::Package pack_in; + yp2::Package pack_in; pack_in.data(7).router(router1); std::cout << "pack_in.data(7).router(router1)" << "\n"; @@ -56,7 +56,7 @@ int main(int argc, char **argv) { pack_in.move(); std::cout << "pack_in.move()" << "\n"; - throw p3::Router_Exception("finished"); + throw yp2::Router_Exception("finished"); } catch (std::exception &e) {