1 /* $Id: filter_factory.hpp,v 1.2 2005-10-29 17:58:14 marc Exp $
2 Copyright (c) 2005, Index Data.
7 #ifndef FILTER_FACTORY_HPP
8 #define FILTER_FACTORY_HPP
26 class FilterFactoryException : public std::runtime_error {
28 FilterFactoryException(const std::string message)
29 : std::runtime_error("FilterException: " + message){
36 typedef yp2::filter::Base* (*CreateFilterCallback)();
37 /// true if registration ok
39 bool add_creator(std::string fi, CreateFilterCallback cfc);
40 /// true if unregistration ok
42 bool drop_creator(std::string fi);
44 /// factory create method
46 yp2::filter::Base* create(std::string fi);
49 typedef std::map<std::string, CreateFilterCallback> CallbackMap;
56 bool yp2::filter::FilterFactory::add_creator(std::string fi,
57 CreateFilterCallback cfc)
59 return m_fcm.insert(CallbackMap::value_type(fi, cfc)).second;
63 bool yp2::filter::FilterFactory::drop_creator(std::string fi)
65 return m_fcm.erase(fi) == 1;
68 yp2::filter::Base* yp2::filter::FilterFactory::create(std::string fi)
70 CallbackMap::const_iterator i = m_fcm.find(fi);
72 if (i == m_fcm.end()){
73 std::string msg = "filter type '" + fi + "' not found";
74 throw yp2::filter::FilterFactoryException(msg);
76 // call create function
88 * indent-tabs-mode: nil
89 * c-file-style: "stroustrup"
91 * vim: shiftwidth=4 tabstop=8 expandtab