a965dd087247b404c432b6d64c47a88c762e7816
[metaproxy-moved-to-github.git] / src / router_chain.hpp
1 /* $Id: router_chain.hpp,v 1.1 2005-10-26 10:21:03 marc Exp $
2    Copyright (c) 2005, Index Data.
3
4 %LICENSE%
5  */
6
7 #ifndef ROUTER_CHAIN_HPP
8 #define ROUTER_CHAIN_HPP
9
10 #include <stdexcept>
11 #include <list>
12
13 #include "router.hpp"
14
15
16 namespace yp2 {
17     namespace filter {
18         class Base;
19     }
20     class Package;
21     
22     
23     class RouterChain : public Router {
24     public:
25         RouterChain(){};
26         virtual ~RouterChain(){};
27         virtual const filter::Base *move(const filter::Base *filter,
28                                    const Package *package) const {
29             std::list<const filter::Base *>::const_iterator it;
30             it = m_filter_list.begin();
31             if (filter)
32                 {
33                     for (; it != m_filter_list.end(); it++)
34                         if (*it == filter)
35                             {
36                                 it++;
37                                 break;
38                             }
39                 }
40             if (it == m_filter_list.end())
41                 {
42                     //throw RouterException("no routing rules known");
43                     return 0;
44                 }
45             return *it;
46         };
47         virtual void configure(){};
48         RouterChain & rule(const filter::Base &filter){
49             m_filter_list.push_back(&filter);
50             return *this;
51         }
52     protected:
53         std::list<const filter::Base *> m_filter_list;
54     private:
55         /// disabled because class is singleton
56         RouterChain(const RouterChain &);
57
58         /// disabled because class is singleton
59         RouterChain& operator=(const RouterChain &);
60     };
61   
62
63   
64 }
65
66 #endif
67 /*
68  * Local variables:
69  * c-basic-offset: 4
70  * indent-tabs-mode: nil
71  * c-file-style: "stroustrup"
72  * End:
73  * vim: shiftwidth=4 tabstop=8 expandtab
74  */