1 /* $Id: filter_factory.hpp,v 1.5 2005-11-07 21:57:10 adam Exp $
2 Copyright (c) 2005, Index Data.
7 #ifndef FILTER_FACTORY_HPP
8 #define FILTER_FACTORY_HPP
22 class FilterFactoryException : public std::runtime_error {
24 FilterFactoryException(const std::string message)
25 : std::runtime_error("FilterException: " + message){
32 typedef yp2::filter::Base* (*CreateFilterCallback)();
33 /// true if registration ok
37 bool add_creator(std::string fi, CreateFilterCallback cfc);
38 /// true if unregistration ok
40 bool drop_creator(std::string fi);
42 /// factory create method
44 yp2::filter::Base* create(std::string fi);
47 typedef std::map<std::string, CreateFilterCallback> CallbackMap;
51 /// disabled because class is singleton
52 FilterFactory(const FilterFactory &);
54 /// disabled because class is singleton
55 FilterFactory& operator=(const FilterFactory &);
60 bool yp2::filter::FilterFactory::add_creator(std::string fi,
61 CreateFilterCallback cfc)
63 return m_fcm.insert(CallbackMap::value_type(fi, cfc)).second;
67 bool yp2::filter::FilterFactory::drop_creator(std::string fi)
69 return m_fcm.erase(fi) == 1;
72 yp2::filter::Base* yp2::filter::FilterFactory::create(std::string fi)
74 CallbackMap::const_iterator i = m_fcm.find(fi);
76 if (i == m_fcm.end()){
77 std::string msg = "filter type '" + fi + "' not found";
78 throw yp2::filter::FilterFactoryException(msg);
80 // call create function
92 * indent-tabs-mode: nil
93 * c-file-style: "stroustrup"
95 * vim: shiftwidth=4 tabstop=8 expandtab