1 /* $Id: filter_factory.hpp,v 1.3 2005-10-29 22:51:11 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
41 bool add_creator(std::string fi, CreateFilterCallback cfc);
42 /// true if unregistration ok
44 bool drop_creator(std::string fi);
46 /// factory create method
48 yp2::filter::Base* create(std::string fi);
51 typedef std::map<std::string, CreateFilterCallback> CallbackMap;
55 /// disabled because class is singleton
56 FilterFactory(const FilterFactory &);
58 /// disabled because class is singleton
59 FilterFactory& operator=(const FilterFactory &);
64 bool yp2::filter::FilterFactory::add_creator(std::string fi,
65 CreateFilterCallback cfc)
67 return m_fcm.insert(CallbackMap::value_type(fi, cfc)).second;
71 bool yp2::filter::FilterFactory::drop_creator(std::string fi)
73 return m_fcm.erase(fi) == 1;
76 yp2::filter::Base* yp2::filter::FilterFactory::create(std::string fi)
78 CallbackMap::const_iterator i = m_fcm.find(fi);
80 if (i == m_fcm.end()){
81 std::string msg = "filter type '" + fi + "' not found";
82 throw yp2::filter::FilterFactoryException(msg);
84 // call create function
96 * indent-tabs-mode: nil
97 * c-file-style: "stroustrup"
99 * vim: shiftwidth=4 tabstop=8 expandtab