X-Git-Url: http://sru.miketaylor.org.uk/?a=blobdiff_plain;f=src%2Ffilter_factory.hpp;h=c8b22513edc82f447314c65a99392fa26867b288;hb=cae80f85741d2564d918a0e3285c62e51491a7fc;hp=29630a62ef23d62b348e720310cfe56bec5cc8cc;hpb=d8ae25e485e2b560d7990fadbd061c45e70b69a6;p=metaproxy-moved-to-github.git diff --git a/src/filter_factory.hpp b/src/filter_factory.hpp index 29630a6..c8b2251 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.7 2005-12-10 09:59:10 adam Exp $ Copyright (c) 2005, Index Data. %LICENSE% @@ -12,77 +12,40 @@ #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 boost::noncopyable + { + typedef yp2::filter::Base* (*CreateFilterCallback)(); - 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; + class Rep; + public: + /// true if registration ok + + FilterFactory(); + ~FilterFactory(); - private: - /// disabled because class is singleton - FilterFactory(const FilterFactory &); - - /// disabled because class is singleton - FilterFactory& operator=(const FilterFactory &); - }; + bool add_creator(std::string fi, CreateFilterCallback cfc); - } - - 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); + bool drop_creator(std::string 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()); - } - + yp2::filter::Base* create(std::string fi); - + bool add_creator_dyn(const std::string &fi, const std::string &path); + private: + boost::scoped_ptr m_p; + }; } #endif