root/tlate/header_value.hh

Revision e7bbf3c6b857df8ad33c4d39396d693b48a48461, 3.1 KB (checked in by Antti-Juhani Kaijanaho <antti-juhani@…>, 21 months ago)

Add support for message/rfc822

Signed-off-by: Antti-Juhani Kaijanaho <antti-juhani@…>

  • Property mode set to 100644
Line 
1/*  This file is part of Alue, the multiprotocol Internet discussion daemon
2
3    Copyright © 2010 Antti-Juhani Kaijanaho
4
5    Alue is free software: you can redistribute it and/or modify it
6    under the terms of the GNU General Public License as published by
7    the Free Software Foundation, either version 3 of the License, or
8    (at your option) any later version.
9
10    Alue is distributed in the hope that it will be useful, but
11    WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    General Public License for more details.
14
15    You should have received a copy of the GNU General Public License
16    along with Alue.  If not, see <http://www.gnu.org/licenses/>.
17
18 */
19
20#ifndef GUARD_TLATE_HEADER_VALUE_HH
21#define GUARD_TLATE_HEADER_VALUE_HH
22
23#include "field_value.hh"
24#include "sequential_value.hh"
25#include "../msg/entity.hh"
26
27namespace tlate
28{
29        class header_value : public sequential_value
30        {
31                msg::entity::const_ptr m;
32                bool munge;
33
34                class vit : public virtual_iterator
35                {
36                        msg::entity::field_iterator it;
37                        mutable value::const_ptr cur;
38                        bool munge;
39 
40                        vit(msg::entity::field_iterator it,
41                            value::const_ptr cur,
42                            bool munge)
43                                : it(it)
44                                , cur(cur)
45                                , munge(munge)
46                                {}
47               public:
48                        vit(msg::entity::field_iterator it, bool munge)
49                                : it(it)
50                                , munge(munge)
51                                {}
52                        virtual_iterator *clone() const {
53                                return new vit(it, cur, munge);
54                        }
55                        value::const_ptr get() const {
56                                if (!cur)
57                                        cur.reset(new field_value(*it, munge));
58                                return cur;
59                        }
60                        void next() {
61                                it++;
62                                cur.reset();
63                        }
64                        bool eq(const virtual_iterator &o_) const {
65                                const vit *o = dynamic_cast<const vit *>(&o_);
66                                return o ? it == o->it : false;
67                        }
68                };
69
70        public:
71                header_value(msg::entity::const_ptr m, bool munge)
72                        : m(m)
73                        , munge(munge)
74                        {}
75                const_iterator begin() const {
76                        return const_iterator
77                                (new vit(m->fields_begin(), munge));
78                }
79                const_iterator end() const {
80                        return const_iterator
81                                (new vit(m->fields_end(), munge));
82                }
83        };
84
85}
86
87#endif /* GUARD_TLATE_HEADER_VALUE_HH */
Note: See TracBrowser for help on using the browser.