root/tlate/thread_value.hh

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

Add support for paginating thread and article lists.

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 © 2009, 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_THREAD_VALUE_HH
21#define GUARD_TLATE_THREAD_VALUE_HH
22
23#include "msg_value.hh"
24#include "sequential_value.hh"
25
26#include "../db/threaded.hh"
27
28#include <vector>
29
30namespace db { class user; }
31
32namespace tlate
33{
34        class thread_value : public sequential_value
35        {
36                typedef std::vector<db::thread_node::const_ptr> tl;
37                tl tnl;
38                boost::shared_ptr<const db::user> u;
39        private:
40                class vit : public virtual_iterator
41                {
42                        tl::const_iterator it;
43                        mutable value::ptr cur;
44                        boost::shared_ptr<const db::user> u;
45
46                public:
47                        vit(tl::const_iterator it,
48                            boost::shared_ptr<const db::user> u)
49                                : it(it), u(u)
50                                {}
51
52                        virtual_iterator *clone() const {
53                                return new vit(*this);
54                        }
55                        value::const_ptr get() const {
56                                if (!cur) cur = msg_value::mk(*it, u);
57                                return cur;
58                        }
59                        void next() {
60                                cur.reset();
61                                it++;
62                        }
63                        bool eq(const virtual_iterator &o_) const {
64                                const vit *o = dynamic_cast<const vit *>(&o_);
65                                return o ? it == o->it : false;
66                        }
67                };
68
69        public:
70                typedef boost::shared_ptr<thread_value> ptr;
71                typedef boost::shared_ptr<const thread_value> const_ptr;
72
73                const_iterator begin() const { return new vit(tnl.begin(), u); }
74                const_iterator end() const   { return new vit(tnl.end(),   u); }
75
76                thread_value(db::thread_node::const_ptr tn,
77                             boost::shared_ptr<const db::user> u);
78                void slice_window(size_t start, size_t length);
79                size_t size() const { return tnl.size(); }
80        };
81}
82
83#endif /* GUARD_TLATE_THREAD_VALUE_HH */
Note: See TracBrowser for help on using the browser.