Started work on shared session filter.
[metaproxy-moved-to-github.git] / src / filter_factory.cpp
1 /* $Id: filter_factory.cpp,v 1.1 2005-11-10 23:10:42 adam Exp $
2    Copyright (c) 2005, Index Data.
3
4 %LICENSE%
5  */
6
7 #include "filter_factory.hpp"
8
9 #include <stdexcept>
10 #include <iostream>
11 #include <string>
12 #include <map>
13
14 namespace yp2 {
15     class FilterFactory::Rep {
16     public:
17         friend class FilterFactory;
18         CallbackMap m_fcm;
19         Rep();
20         ~Rep();
21     };
22 }
23
24 yp2::FilterFactoryException::FilterFactoryException(const std::string message)
25     : std::runtime_error("FilterException: " + message)
26 {
27 }
28
29 yp2::FilterFactory::Rep::Rep()
30 {
31 }
32
33 yp2::FilterFactory::Rep::~Rep()
34 {
35 }
36
37 yp2::FilterFactory::FilterFactory() : m_p(new yp2::FilterFactory::Rep)
38 {
39
40 }
41
42 yp2::FilterFactory::~FilterFactory()
43 {
44
45 }
46
47 bool yp2::FilterFactory::add_creator(std::string fi,
48                                      CreateFilterCallback cfc)
49 {
50     return m_p->m_fcm.insert(CallbackMap::value_type(fi, cfc)).second;
51 }
52
53
54 bool yp2::FilterFactory::drop_creator(std::string fi)
55 {
56     return m_p->m_fcm.erase(fi) == 1;
57 }
58
59 yp2::filter::Base* yp2::FilterFactory::create(std::string fi)
60 {
61     CallbackMap::const_iterator it = m_p->m_fcm.find(fi);
62     
63     if (it == m_p->m_fcm.end()){
64         std::string msg = "filter type '" + fi + "' not found";
65             throw yp2::FilterFactoryException(msg);
66     }
67     // call create function
68     return (it->second());
69 }
70
71 /*
72  * Local variables:
73  * c-basic-offset: 4
74  * indent-tabs-mode: nil
75  * c-file-style: "stroustrup"
76  * End:
77  * vim: shiftwidth=4 tabstop=8 expandtab
78  */