RouterFleXML now reads XML simple config and make proper runtime
[metaproxy-moved-to-github.git] / src / router_chain.cpp
1 /* $Id: router_chain.cpp,v 1.3 2006-01-09 13:43:59 adam Exp $
2    Copyright (c) 2005, Index Data.
3    
4    %LICENSE%
5 */
6
7 #include "router_chain.hpp"
8
9 #include <list>
10
11 namespace yp2 
12 {
13     class ChainPos;
14
15     class RouterChain::Rep {
16         friend class RouterChain;
17         friend class RouterChain::Pos;
18         std::list<const filter::Base *> m_filter_list;
19     };
20
21 #if ROUTE_POS
22     class RouterChain::Pos : public RoutePos {
23     public:
24         virtual const filter::Base *move();
25         virtual RoutePos *clone();
26         virtual ~Pos();
27         std::list<const filter::Base *>::const_iterator it;
28         yp2::RouterChain::Rep *m_p;
29     };
30 #endif
31 };
32
33 yp2::RouterChain::RouterChain() : m_p(new yp2::RouterChain::Rep)
34 {
35 }
36
37 yp2::RouterChain::~RouterChain()
38 {
39 }
40
41 #if ROUTE_POS
42 const yp2::filter::Base *yp2::RouterChain::Pos::move()
43 {
44     if (it == m_p->m_filter_list.end())
45         return 0;
46     const yp2::filter::Base *f = *it;
47     it++;
48     return f;
49 }
50
51 yp2::RoutePos *yp2::RouterChain::createpos() const
52 {
53     yp2::RouterChain::Pos *p = new yp2::RouterChain::Pos;
54     p->it = m_p->m_filter_list.begin();
55     p->m_p = m_p.get();
56     return p;
57 }
58
59 yp2::RoutePos *yp2::RouterChain::Pos::clone()
60 {
61     yp2::RouterChain::Pos *p = new yp2::RouterChain::Pos;
62     p->it = it;
63     p->m_p = m_p;
64     return p;
65 }
66
67
68 yp2::RouterChain::Pos::~Pos()
69 {
70 }
71 #else
72 const yp2::filter::Base *yp2::RouterChain::move(const filter::Base *filter,
73                                                 const Package *package) const {
74     std::list<const filter::Base *>::const_iterator it;
75     it = m_p->m_filter_list.begin();
76     if (filter)
77     {
78         for (; it != m_p->m_filter_list.end(); it++)
79             if (*it == filter)
80             {
81                 it++;
82                 break;
83             }
84     }
85     if (it == m_p->m_filter_list.end())
86     {
87         //throw RouterException("no routing rules known");
88         return 0;
89     }
90     return *it;
91 }
92 #endif
93
94 yp2::RouterChain & yp2::RouterChain::append(const filter::Base &filter)
95 {
96     m_p->m_filter_list.push_back(&filter);
97     return *this;
98 }
99
100
101 /*
102  * Local variables:
103  * c-basic-offset: 4
104  * indent-tabs-mode: nil
105  * c-file-style: "stroustrup"
106  * End:
107  * vim: shiftwidth=4 tabstop=8 expandtab
108  */