Same header and footer for all files. Header includes copyright +
[metaproxy-moved-to-github.git] / src / router.hpp
1 /* $Id: router.hpp,v 1.3 2005-10-15 14:09:09 adam Exp $
2    Copyright (c) 2005, Index Data.
3
4 %LICENSE%
5  */
6
7 #ifndef ROUTER_HPP
8 #define ROUTER_HPP
9
10 #include <stdexcept>
11 #include <list>
12
13 namespace yp2 {
14     namespace filter {
15         class Base;
16     }
17     class Package;
18     
19     class RouterException : public std::runtime_error {
20     public:
21         RouterException(const std::string message)
22             : std::runtime_error("RouterException: " + message){};
23     };
24   
25     
26     class Router {
27     public:
28         Router(){};
29         virtual ~Router(){};
30
31         /// determines next Filter to use from current Filter and Package
32         virtual const filter::Base *move(const filter::Base *filter,
33                                    const Package *package) const {
34             return 0;
35         };
36
37         /// re-read configuration of routing tables
38         virtual void configure(){};
39
40         /// add routing rule expressed as Filter to Router
41         virtual Router & rule(const filter::Base &filter){
42             return *this;
43         }
44     private:
45         /// disabled because class is singleton
46         Router(const Router &);
47
48         /// disabled because class is singleton
49         Router& operator=(const Router &);
50     };
51   
52     
53     class RouterChain : public Router {
54     public:
55         RouterChain(){};
56         virtual ~RouterChain(){};
57         virtual const filter::Base *move(const filter::Base *filter,
58                                    const Package *package) const {
59             std::list<const filter::Base *>::const_iterator it;
60             it = m_filter_list.begin();
61             if (filter)
62                 {
63                     for (; it != m_filter_list.end(); it++)
64                         if (*it == filter)
65                             {
66                                 it++;
67                                 break;
68                             }
69                 }
70             if (it == m_filter_list.end())
71                 {
72                     //throw RouterException("no routing rules known");
73                     return 0;
74                 }
75             return *it;
76         };
77         virtual void configure(){};
78         RouterChain & rule(const filter::Base &filter){
79             m_filter_list.push_back(&filter);
80             return *this;
81         }
82     protected:
83         std::list<const filter::Base *> m_filter_list;
84     private:
85         /// disabled because class is singleton
86         RouterChain(const RouterChain &);
87
88         /// disabled because class is singleton
89         RouterChain& operator=(const RouterChain &);
90     };
91   
92
93   
94 }
95
96 #endif
97 /*
98  * Local variables:
99  * c-basic-offset: 4
100  * indent-tabs-mode: nil
101  * c-file-style: "stroustrup"
102  * End:
103  * vim: shiftwidth=4 tabstop=8 expandtab
104  */