1 /* $Id: filter_factory.hpp,v 1.4 2005-10-31 09:40:18 marc Exp $
2 Copyright (c) 2005, Index Data.
7 #ifndef FILTER_FACTORY_HPP
8 #define FILTER_FACTORY_HPP
23 class FilterFactoryException : public std::runtime_error {
25 FilterFactoryException(const std::string message)
26 : std::runtime_error("FilterException: " + message){
33 typedef yp2::filter::Base* (*CreateFilterCallback)();
34 /// true if registration ok
38 bool add_creator(std::string fi, CreateFilterCallback cfc);
39 /// true if unregistration ok
41 bool drop_creator(std::string fi);
43 /// factory create method
45 yp2::filter::Base* create(std::string fi);
48 typedef std::map<std::string, CreateFilterCallback> CallbackMap;
52 /// disabled because class is singleton
53 FilterFactory(const FilterFactory &);
55 /// disabled because class is singleton
56 FilterFactory& operator=(const FilterFactory &);
61 bool yp2::filter::FilterFactory::add_creator(std::string fi,
62 CreateFilterCallback cfc)
64 return m_fcm.insert(CallbackMap::value_type(fi, cfc)).second;
68 bool yp2::filter::FilterFactory::drop_creator(std::string fi)
70 return m_fcm.erase(fi) == 1;
73 yp2::filter::Base* yp2::filter::FilterFactory::create(std::string fi)
75 CallbackMap::const_iterator i = m_fcm.find(fi);
77 if (i == m_fcm.end()){
78 std::string msg = "filter type '" + fi + "' not found";
79 throw yp2::filter::FilterFactoryException(msg);
81 // call create function
93 * indent-tabs-mode: nil
94 * c-file-style: "stroustrup"
96 * vim: shiftwidth=4 tabstop=8 expandtab