py::list std_vector_to_py_list(const std::vector<T>& v) { py::object get_iter = py::iterator<std::vector<T> >(); py::object iter = get_iter(v); py::list l(iter); return l; }
//------------------------------------------------------------------------------ void ListModelWrapper::note_row_added() { if (*_tm) { (*_tm)->refresh(); Gtk::TreePath path((*_tm)->count() - 1); row_inserted(path, get_iter(path)); } }
void commsys_hist_symerr::updateresults(libbase::vector<double>& result, const int i, const libbase::vector<int>& source, const libbase::vector< int>& decoded) const { const int skip = count() / get_iter(); int symerrors = libbase::hamming(source, decoded); // Update the count for that number of symbol errors (may be zero) result(skip * i + symerrors)++; }
/*! * \brief Update result set * \param[out] result Vector containing the set of results to be updated * \param[in] i Iteration just performed * \param[in] source Source data sequence * \param[in] decoded Decoded data sequence * * Results are organized as (symbol,frame) error count, repeated for * every iteration that needs to be performed. Eventually these will be * divided by the respective multiplicity to get the average error rates. */ void commsys_errorrates::updateresults(libbase::vector<double>& result, const int i, const libbase::vector<int>& source, const libbase::vector< int>& decoded) const { assert(i >= 0 && i < get_iter()); // Count errors int symerrors = libbase::hamming(source, decoded); // Estimate the BER, SER, FER result(2 * i + 0) += symerrors; result(2 * i + 1) += symerrors ? 1 : 0; }
void LevelParser::load(const std::string& filepath) { try { m_level.m_filename = filepath; register_translation_directory(filepath); auto doc = ReaderDocument::from_file(filepath); auto root = doc.get_root(); if(root.get_name() != "supertux-level") throw std::runtime_error("file is not a supertux-level file."); auto level = root.get_mapping(); int version = 1; level.get("version", version); if(version == 1) { log_info << "[" << filepath << "] level uses old format: version 1" << std::endl; load_old_format(level); } else if (version == 2) { level.get("tileset", m_level.m_tileset); level.get("name", m_level.m_name); level.get("author", m_level.m_author); level.get("contact", m_level.m_contact); level.get("license", m_level.m_license); level.get("target-time", m_level.m_target_time); auto iter = level.get_iter(); while(iter.next()) { if (iter.get_key() == "sector") { auto sector = SectorParser::from_reader(m_level, iter.as_mapping()); m_level.add_sector(std::move(sector)); } } if (m_level.m_license.empty()) { log_warning << "[" << filepath << "] The level author \"" << m_level.m_author << "\" did not specify a license for this level \"" << m_level.m_name << "\". You might not be allowed to share it." << std::endl; } } else { log_warning << "[" << filepath << "] level format version " << version << " is not supported" << std::endl; } } catch(std::exception& e) { std::stringstream msg; msg << "Problem when reading level '" << filepath << "': " << e.what(); throw std::runtime_error(msg.str()); } m_level.m_stats.init(m_level); }
/*! * \brief Update result set * \param[out] result Vector containing the set of results to be updated * \param[in] i Iteration just performed * \param[in] source Source data sequence * \param[in] decoded Decoded data sequence * * Results are organized as (symbol_hamming, symbol_levenshtein,frame) * error count, repeated for every iteration that needs to be performed. * Eventually these will be divided by the respective multiplicity to get the * average error rates. */ void commsys_errors_levenshtein::updateresults(libbase::vector<double>& result, const int i, const libbase::vector<int>& source, const libbase::vector< int>& decoded) const { assert(i >= 0 && i < get_iter()); // Count errors const int hd = libbase::hamming(source, decoded); const int ld = libbase::levenshtein(source, decoded); // Estimate the SER, LD, FER result(3 * i + 0) += hd; result(3 * i + 1) += ld; result(3 * i + 2) += hd ? 1 : 0; }
bool TreeModel_Dnd::row_drop_possible_vfunc(const Gtk::TreeModel::Path& dest, const Gtk::SelectionData& selection_data) const { //Make the value of the "receives drags" column determine whether a row can be //dragged into it: //dest is the path that the row would have after it has been dropped: //But in this case we are more interested in the parent row: Gtk::TreeModel::Path dest_parent = dest; bool dest_is_not_top_level = dest_parent.up(); if(!dest_is_not_top_level || dest_parent.empty()) { //The user wants to move something to the top-level. //Let's always allow that. } else { //Get an iterator for the row at this path: //We must unconst this. This should not be necessary with a future version //of gtkmm. //TODO: Add a const version of get_iter to TreeModel: auto unconstThis = const_cast<TreeModel_Dnd*>(this); const_iterator iter_dest_parent = unconstThis->get_iter(dest_parent); //const_iterator iter_dest_parent = get_iter(dest); if(iter_dest_parent) { Row row = *iter_dest_parent; bool receives_drags = row[m_Columns.m_col_receivesdrags]; return receives_drags; } } //You could also examine the row being dragged (via selection_data) //if you must look at both rows to see whether a drop should be allowed. //You could use //TODO: Add const version of get_from_selection_data(): Glib::RefPtr<const //Gtk::TreeModel> refThis = Glib::RefPtr<const Gtk::TreeModel>(this); // //auto refThis = //Glib::RefPtr<Gtk::TreeModel>(const_cast<TreeModel_Dnd*>(this)); //refThis->reference(); //, true /* take_copy */) //Gtk::TreeModel::Path path_dragged_row; //Gtk::TreeModel::Path::get_from_selection_data(selection_data, refThis, //path_dragged_row); // return Gtk::TreeStore::row_drop_possible_vfunc(dest, selection_data); return Gtk::ListStore::row_drop_possible_vfunc(dest, selection_data); }
bool TreeModel_Dnd::row_draggable_vfunc(const Gtk::TreeModel::Path& path) const { // Make the value of the "draggable" column determine whether this row can // be dragged: //TODO: Add a const version of get_iter to TreeModel: auto unconstThis = const_cast<TreeModel_Dnd*>(this); const_iterator iter = unconstThis->get_iter(path); //const_iterator iter = get_iter(path); if(iter) { Row row = *iter; bool is_draggable = row[m_Columns.m_col_draggable]; return is_draggable; } // return Gtk::TreeStore::row_draggable_vfunc(path); return Gtk::ListStore::row_draggable_vfunc(path); }
int main(void) { const int iter = get_iter(0, 1); const bool oth_first = CHECK_FLAG(iter, 1); diag("oth_first=%s", btos(oth_first)); plan_tests(1); sem_t *sems[] = { &goahead_sem, &done_sem }; for(int i=0; i < NUM_ELEMENTS(sems); i++) { int n = sem_init(sems[i], 0, 0); if(n != 0) { perror("sem_init"); abort(); } } int *data = malloc(sizeof(*data) * 2); data[0] = 100; data[1] = 100; pthread_t other; int n = pthread_create(&other, NULL, &other_fn, data); if(n != 0) { perror("pthread_create"); abort(); } int status; bool posted = false; do { status = xn_begin(); diag("main txn started"); int v0 = xn_read_int(&data[0]), v1 = xn_read_int(&data[1]); if(oth_first && !posted) { sem_post(&goahead_sem); sem_wait(&done_sem); posted = true; } v1 -= 200; if(v0 + v1 < 0) { diag("invariant broken in main"); break; } xn_put(&data[1], v1); } while(status = xn_commit(), XN_RESTART(status)); xn_abort(status); diag("main txn done"); if(!posted) { assert(!oth_first); sem_post(&goahead_sem); sem_wait(&done_sem); } void *retval = NULL; n = pthread_join(other, &retval); if(n != 0) { perror("pthread_join"); abort(); } if(!ok1(data[0] + data[1] >= 0)) { diag("data[0]=%d, data[1]=%d", data[0], data[1]); } free(data); for(int i=0; i < NUM_ELEMENTS(sems); i++) sem_destroy(sems[i]); return exit_status(); }