namespace {
struct CompareNumber {
- CompareNumber(boost::unordered_map<std::string, ModelColumns>& cols) :
- cols_(cols) {}
-
- bool operator()(const std::string& lhs, const std::string& rhs) const {
- boost::unordered_map<std::string, ModelColumns>::const_iterator it = cols_.find(lhs);
- assert(it != cols_.end());
- const ModelColumns& left_cols = it->second;
-
- it = cols_.find(rhs);
- assert(it != cols_.end());
- const ModelColumns& right_cols = it->second;
-
- int left_num = model_column::field<model_column::Number>(left_cols);
- int right_num = model_column::field<model_column::Number>(right_cols);
+ bool operator()(const ModelColumns& lhs, const ModelColumns& rhs) const {
+ int left_num = model_column::field<model_column::Number>(lhs);
+ int right_num = model_column::field<model_column::Number>(rhs);
if (left_num == 0) left_num = boost::integer_traits<int>::const_max;
if (right_num == 0) right_num = boost::integer_traits<int>::const_max;
return left_num < right_num;
}
- boost::unordered_map<std::string, ModelColumns>& cols_;
};
}
void ThreadListModel::append(const ModelColumns& record) {
const model_column::ID::type& id = model_column::field<model_column::ID>(record);
- StoreType::iterator it = list_.find(id);
- if (it != list_.end()) {
- list_[id] = record;
+ OrderType::iterator it = order_.find(id);
+ if (it != order_.end()) {
+ list_[it->second] = record;
} else {
- list_[id] = record;
- order_.push_back(model_column::field<model_column::ID>(record));
+ list_.push_back(record);
+ order_[id] = list_.size()-1;
const size_t index = list_.size() -1;
iterator iter;
append(cols);
}
- boost::unordered_map<std::string, int> old_order;
- for (size_t i = 0; i != order_.size(); ++i) old_order[order_[i]] = i;
+ OrderType old_order = order_;
- std::sort(order_.begin(), order_.end(), CompareNumber(list_));
+ std::sort(list_.begin(), list_.end(), CompareNumber());
+
+ for (size_t i = 0; i != list_.size(); i++) {
+ const model_column::ID::type& id =
+ model_column::field<model_column::ID>(list_[i]);
+ order_[id] = i;
+ }
std::vector<int> new_order;
new_order.reserve(order_.size());
- BOOST_FOREACH(const std::string& id, order_) {
+ BOOST_FOREACH(const ModelColumns& record, list_) {
+ const model_column::ID::type& id =
+ model_column::field<model_column::ID>(record);
new_order.push_back(old_order[id]);
}
void ThreadListModel::get_buffer(
boost::unordered_map<model_column::ID::type, ModelColumns>& buffer) const {
- buffer = list_;
+ buffer.clear();
+ BOOST_FOREACH(const ModelColumns& record, list_) {
+ const model_column::ID::type& id =
+ model_column::field<model_column::ID>(record);
+ buffer[id] = record;
+ }
}
const ModelColumns& ThreadListModel::get_model_columns(const size_t row_index) const {
assert(row_index < list_.size());
-
- const std::string& id = order_[row_index];
- StoreType::const_iterator it = list_.find(id);
-
- assert(it != list_.end());
-
- return it->second;
+ return list_[row_index];
}
void ThreadListModel::update_row(const ModelColumns& record) {
const model_column::ID::type& id = model_column::field<model_column::ID>(record);
- StoreType::iterator it = list_.find(id);
- if (it != list_.end()) {
- model_column::field<model_column::Title>(it->second) =
+ OrderType::iterator it = order_.find(id);
+ if (it != order_.end()) {
+ const size_t row_index = it->second;
+
+ model_column::field<model_column::Title>(list_[row_index]) =
model_column::field<model_column::Title>(record);
- model_column::field<model_column::LineCount>(it->second) =
+ model_column::field<model_column::LineCount>(list_[row_index]) =
model_column::field<model_column::LineCount>(record);
- OrderType::iterator jt = std::find(order_.begin(), order_.end(), id);
- if (jt != order_.end()) {
- const size_t row_index = std::distance(order_.begin(), jt);
- Gtk::TreePath path;
- path.append_index(row_index);
- iterator iter;
- iter.set_stamp(1);
- iter.gobj()->user_data = GINT_TO_POINTER(row_index);
- row_changed(path, iter);
- }
+
+ Gtk::TreePath path;
+ path.append_index(row_index);
+ iterator iter;
+ iter.set_stamp(1);
+ iter.gobj()->user_data = GINT_TO_POINTER(row_index);
+ row_changed(path, iter);
} else {
append(record);
}
const size_t index = GPOINTER_TO_INT(iter.gobj()->user_data);
if (index >= order_.size()) return;
- const std::string& id = order_[index];
-
- StoreType::const_iterator it = list_.find(id);
- assert(it != list_.end());
+ const ModelColumns& record = list_[index];
- const ModelColumns& record = it->second;
model_column::GetColumnData functor(record, column, value);
boost::mpl::for_each<model_column::List>(functor);
}