X-Git-Url: http://lists.indexdata.com/cgi-bin?a=blobdiff_plain;f=src%2Ffilter_factory.hpp;h=7ad4e191523f7fbe94ee99385dfc57c0afc87338;hb=35f51b468b01c18772b50d15a4586a15fe4f6b50;hp=0ac8b6700e7ff2fed7029e530712a7a0bf7ac0d1;hpb=349c7da1d51fc13c35a03c0be3fd6b2b63af8875;p=metaproxy-moved-to-github.git diff --git a/src/filter_factory.hpp b/src/filter_factory.hpp index 0ac8b67..7ad4e19 100644 --- a/src/filter_factory.hpp +++ b/src/filter_factory.hpp @@ -1,4 +1,4 @@ -/* $Id: filter_factory.hpp,v 1.1 2005-10-28 10:35:30 marc Exp $ +/* $Id: filter_factory.hpp,v 1.4 2005-10-31 09:40:18 marc Exp $ Copyright (c) 2005, Index Data. %LICENSE% @@ -19,32 +19,69 @@ namespace yp2 { namespace filter { + + class FilterFactoryException : public std::runtime_error { + public: + FilterFactoryException(const std::string message) + : std::runtime_error("FilterException: " + message){ + }; + }; + class FilterFactory { -#if 0 public: typedef yp2::filter::Base* (*CreateFilterCallback)(); /// true if registration ok - bool register_filter(std::string fi, CreateFilterCallback cfc); + + FilterFactory(){}; + + bool add_creator(std::string fi, CreateFilterCallback cfc); /// true if unregistration ok - bool unregister_filter(std::string fi); + + bool drop_creator(std::string fi); + /// factory create method + yp2::filter::Base* create(std::string fi); private: typedef std::map CallbackMap; + CallbackMap m_fcm; -#endif - + 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) + { + 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); + + if (i == m_fcm.end()){ + std::string msg = "filter type '" + fi + "' not found"; + throw yp2::filter::FilterFactoryException(msg); + } + // call create function + return (i->second()); } - class FilterFactoryException : public std::runtime_error { - public: - FilterFactoryException(const std::string message) - : std::runtime_error("FilterException: " + message){ - }; - }; }