X-Git-Url: http://sru.miketaylor.org.uk/?a=blobdiff_plain;f=src%2Ffilter_factory.hpp;h=320f86fe42836b0cde828cc70107e1c088768a7d;hb=77dee8966dd1304a0fb8540c3fc68d02dc6ce84a;hp=902c84d6dee1cb41022c86f42efee65b9d122418;hpb=8a595f41f5eaaa7ef846a697cfe4466ea57d224a;p=metaproxy-moved-to-github.git diff --git a/src/filter_factory.hpp b/src/filter_factory.hpp index 902c84d..320f86f 100644 --- a/src/filter_factory.hpp +++ b/src/filter_factory.hpp @@ -1,4 +1,4 @@ -/* $Id: filter_factory.hpp,v 1.2 2005-10-29 17:58:14 marc Exp $ +/* $Id: filter_factory.hpp,v 1.6 2005-11-10 23:10:42 adam Exp $ Copyright (c) 2005, Index Data. %LICENSE% @@ -12,73 +12,43 @@ #include #include -#include "config.hpp" +#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 - - 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; - - }; - - } - 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