OSDN Git Service

HTTP GET method is implemented. It is used in board window.
[fukui-no-namari/dialektos.git] / src / thread_list_model.hxx
1 /*
2  * Copyright (C) 2009 by Aiwota Programmer
3  * aiwotaprog@tetteke.tk
4  *
5  * This file is part of Dialektos.
6  *
7  * Dialektos is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * Dialektos is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with Dialektos.  If not, see <http://www.gnu.org/licenses/>.
19  */
20
21 #ifndef THREAD_LIST_MODEL_HXX
22 #define THREAD_LIST_MODEL_HXX
23
24 #include <glibmm/object.h>
25 #include <gtkmm/treemodel.h>
26 #include <boost/unordered_map.hpp>
27 #include <boost/mpl/vector.hpp>
28 #include <boost/mpl/find.hpp>
29 #include <boost/mpl/size.hpp>
30 #include <boost/mpl/inherit.hpp>
31 #include <boost/mpl/inherit_linearly.hpp>
32 #include <boost/array.hpp>
33 #include <string>
34 #include <vector>
35
36
37 namespace dialektos {
38
39 namespace model_column {
40
41 template <typename T, int ID = 0>
42 struct TypeHolder {
43   typedef T type;
44   enum { Identifyer = ID };
45 };
46
47 template <typename TypeHolderT>
48 struct FieldHolder {
49   FieldHolder() : data_() {}
50   typedef typename TypeHolderT::type ValueType;
51   ValueType data_;
52 };
53
54 template <typename TypeHolderT>
55 inline typename TypeHolderT::type& field(FieldHolder<TypeHolderT>& t) {
56   return t.data_;
57 }
58 template <typename TypeHolderT>
59 inline const typename TypeHolderT::type& field(const FieldHolder<TypeHolderT>& t) {
60   return t.data_;
61 }
62
63 typedef TypeHolder<int> Number;
64 typedef TypeHolder<int, 1> ResNum;
65 typedef TypeHolder<int, 2> LineCount;
66 typedef TypeHolder<double> Average;
67 typedef TypeHolder<std::string> Title;
68 typedef TypeHolder<std::string, 1> ID;
69 typedef boost::mpl::vector<ID, Number, Title, ResNum, LineCount, Average> List;
70
71 } // namespace model_column
72
73
74 struct ModelColumns : public boost::mpl::inherit_linearly<
75   model_column::List,
76   boost::mpl::inherit<boost::mpl::_1, model_column::FieldHolder<boost::mpl::_2> >
77   >::type {
78   typedef model_column::List type;
79 };
80
81
82 class ThreadListModel : public Glib::Object, public Gtk::TreeModel {
83 public:
84   typedef Gtk::TreeModel::iterator iterator;
85
86   static Glib::RefPtr<ThreadListModel> create();
87
88   virtual ~ThreadListModel();
89   void append(const ModelColumns& record);
90   void set_buffer(const boost::unordered_map<model_column::ID::type, ModelColumns>& buffer);
91   void get_buffer(boost::unordered_map<model_column::ID::type, ModelColumns>& buffer) const;
92   const ModelColumns& get_model_columns(size_t row_index) const;
93 protected:
94   ThreadListModel();
95
96   virtual GType get_column_type_vfunc(int index) const;
97   virtual Gtk::TreeModelFlags get_flags_vfunc() const;
98   virtual int get_n_columns_vfunc() const;
99   virtual bool get_iter_vfunc(const Gtk::TreeModel::Path& path, iterator& iter) const;
100   virtual Gtk::TreeModel::Path get_path_vfunc(const iterator& iter) const;
101   virtual void get_value_vfunc(const iterator& iter, int column,
102       Glib::ValueBase& value) const;
103
104   virtual bool iter_children_vfunc(const iterator& parent, iterator& iter) const;
105   virtual bool iter_has_child_vfunc(const iterator& iter) const;
106   virtual bool iter_is_valid(const iterator& iter) const;
107   virtual int iter_n_children_vfunc(const iterator& iter) const;
108   virtual int iter_n_root_children_vfunc() const;
109   virtual bool iter_next_vfunc(const iterator& iter, iterator& iter_next) const;
110   virtual bool iter_nth_child_vfunc(const iterator& parent, int n,
111       iterator& iter) const;
112   virtual bool iter_nth_root_child_vfunc(int n, iterator& iter) const;
113   virtual bool iter_parent_vfunc(const iterator& child, iterator& iter) const;
114
115 private:
116
117   typedef boost::unordered_map<model_column::ID::type, ModelColumns> StoreType;
118   typedef std::vector<model_column::ID::type> OrderType;
119
120   StoreType list_;
121   OrderType order_;
122 };
123
124
125 } // namespace dialektos
126
127 #endif