ccd04863436e5cccb8cf58dd84cbd80b7cda7250
[metaproxy-moved-to-github.git] / src / router_chain.cpp
1 /* This file is part of Metaproxy.
2    Copyright (C) 2005-2012 Index Data
3
4 Metaproxy is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
7 version.
8
9 Metaproxy is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17 */
18
19 #include "router_chain.hpp"
20 #include <metaproxy/filter.hpp>
21
22 #include <list>
23
24 namespace mp = metaproxy_1;
25
26 namespace metaproxy_1
27 {
28     class ChainPos;
29
30     class RouterChain::Rep {
31         friend class RouterChain;
32         friend class RouterChain::Pos;
33         std::list<const filter::Base *> m_filter_list;
34     };
35     class RouterChain::Pos : public RoutePos {
36     public:
37         virtual const filter::Base *move(const char *route);
38         virtual RoutePos *clone();
39         virtual ~Pos();
40         std::list<const filter::Base *>::const_iterator it;
41         mp::RouterChain::Rep *m_p;
42     };
43 }
44
45 mp::RouterChain::RouterChain() : m_p(new mp::RouterChain::Rep)
46 {
47 }
48
49 mp::RouterChain::~RouterChain()
50 {
51 }
52
53 void mp::RouterChain::start()
54 {
55     std::list<const filter::Base *>::const_iterator it;
56
57     for (it = m_p->m_filter_list.begin(); it != m_p->m_filter_list.end(); it++)
58         (*it)->start();
59 }
60
61 const mp::filter::Base *mp::RouterChain::Pos::move(const char *route)
62 {
63     if (it == m_p->m_filter_list.end())
64         return 0;
65     const mp::filter::Base *f = *it;
66     it++;
67     return f;
68 }
69
70 mp::RoutePos *mp::RouterChain::createpos() const
71 {
72     mp::RouterChain::Pos *p = new mp::RouterChain::Pos;
73     p->it = m_p->m_filter_list.begin();
74     p->m_p = m_p.get();
75     return p;
76 }
77
78 mp::RoutePos *mp::RouterChain::Pos::clone()
79 {
80     mp::RouterChain::Pos *p = new mp::RouterChain::Pos;
81     p->it = it;
82     p->m_p = m_p;
83     return p;
84 }
85
86
87 mp::RouterChain::Pos::~Pos()
88 {
89 }
90
91 mp::RouterChain & mp::RouterChain::append(const filter::Base &filter)
92 {
93     m_p->m_filter_list.push_back(&filter);
94     return *this;
95 }
96
97
98 /*
99  * Local variables:
100  * c-basic-offset: 4
101  * c-file-style: "Stroustrup"
102  * indent-tabs-mode: nil
103  * End:
104  * vim: shiftwidth=4 tabstop=8 expandtab
105  */
106