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