root/tlate/data_model.hh

Revision 43f521291669f483d361949fa6c886c0fbd94daf, 2.5 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_DATA_MODEL_HH
21#define GUARD_TLATE_DATA_MODEL_HH
22
23#include "empty_value.hh"
24#include "string_value.hh"
25#include "structured_value.hh"
26
27#include "../myassert.hh"
28
29#include <map>
30
31namespace tlate
32{
33        class data_model : public structured_value
34        {
35                std::map<std::string,value::const_ptr> m;
36        public:
37                typedef boost::shared_ptr<data_model> ptr;
38                typedef boost::shared_ptr<const data_model> const_ptr;
39
40                void insert(std::string var) {
41                        insert(var, new empty_value);
42                }
43                void insert(std::string var, std::string val) {
44                        insert(var, new string_value(val));
45                }
46                void insert(std::string var, int val, unsigned md = 1) {
47                        insert(var, new string_value(val, md));
48                }
49                void insert(std::string var, value::const_ptr val) {
50                        myassert(var.find('.') == std::string::npos);
51                        m[var] = val;
52                }
53                // ONLY for use with explicit new-expressions
54                void insert(std::string var, value *val) {
55                        value::ptr vp(val);
56                        insert(var, vp);
57                }
58                value::const_ptr get(std::string var) const {
59                        std::map<std::string,value::const_ptr>::const_iterator
60                                it = m.find(var);
61                        if (it != m.end())
62                                return it->second;
63                        else
64                                return value::ptr();
65                }
66        };
67}
68
69#endif /* GUARD_TLATE_DATA_MODEL_HH */
Note: See TracBrowser for help on using the browser.