2 * Copyright (C) 2009 by Aiwota Programmer
3 * aiwotaprog@tetteke.tk
5 * This file is part of Dialektos.
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.
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.
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/>.
21 #ifndef THREAD_LIST_MODEL_HXX
22 #define THREAD_LIST_MODEL_HXX
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>
39 namespace model_column {
41 template <typename T, int ID = 0>
44 enum { Identifyer = ID };
47 template <typename TypeHolderT>
49 FieldHolder() : data_() {}
50 typedef typename TypeHolderT::type ValueType;
54 template <typename TypeHolderT>
55 inline typename TypeHolderT::type& field(FieldHolder<TypeHolderT>& t) {
58 template <typename TypeHolderT>
59 inline const typename TypeHolderT::type& field(const FieldHolder<TypeHolderT>& t) {
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;
71 } // namespace model_column
74 struct ModelColumns : public boost::mpl::inherit_linearly<
76 boost::mpl::inherit<boost::mpl::_1, model_column::FieldHolder<boost::mpl::_2> >
78 typedef model_column::List type;
82 class ThreadListModel : public Glib::Object, public Gtk::TreeModel {
84 typedef Gtk::TreeModel::iterator iterator;
86 static Glib::RefPtr<ThreadListModel> create();
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;
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;
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;
117 typedef boost::unordered_map<model_column::ID::type, ModelColumns> StoreType;
118 typedef std::vector<model_column::ID::type> OrderType;
125 } // namespace dialektos