void do_file_set_block(FileSetBlock *fsb) { String output_file_name = _output_file_name_argument->get_string()->get_string(); c_file = open_c_file(output_file_name); SuifEnv *s = get_suif_env(); MacroObjectBuilder builder; MacroObjectPtr root = builder.build_macro_object((Address)fsb,fsb->get_meta_class()); char *text = get_file_text(_macro_file_name.c_str()); if (text == NULL) { suif_error(s, "could not open macro file %s\n",_macro_file_name.c_str()); // fprintf(stderr,"could not open macro file %s\n",macro_filename); return; // return -1; } size_t i; for (i = 0;i < _d_opts.size(); i++) AddDefine(root,_d_opts[i]); int len = strlen(text); S2CMacroExpansion expand(s,len); for (i = 0;i < _i_opts.size(); i++) { String value = _i_opts[i]; expand.add_include(value); } // root->Print(0); expand.set_debug(debug_it); expand.Expand(_macro_file_name,text,root); for (int j=1;j<expand.file_count();j++) { const String x = expand.get_file_text(j); write_text(expand.get_file_name(j),x); } const String def = expand.get_file_text(0); if (def.length() > 0) fprintf(c_file,"%s",def.c_str()); root->perform_final_cleanup(); if (c_file && c_file != stdout) fclose(c_file); delete [] text; }
void BoundTextEdit::populateFromOption(Option *option) { OptionString *text = dynamic_cast<OptionString *>(option); this->setPlainText(QString::fromStdString(text->value())); }
void BoundTableWidget::populateTableFromOption() { // For each QTableWidgetItem updation, a 'cellChanged' signal is triggered. // Block all such signals until Table updation this->blockSignals(true); _boundTo->blockSignals(true); // Initialize this->clearContents(); this->setRowCount(0); this->setColumnCount(0); std::vector<std::vector<std::string> > verticalHeaders; std::vector<double> values; QStringList horizontalLabels = QStringList(); QStringList verticalLabels = QStringList(); int column = 0; bool setRowCount = false; for (std::vector<Options *>::iterator it = _groups.begin(); it != _groups.end(); ++it) { Options *newRow = static_cast<Options *>(*it); OptionString *factorName = static_cast<OptionString *>(newRow->get("name")); OptionVariables *headers = static_cast<OptionVariables *>(newRow->get("levels")); OptionDoubleArray *option = static_cast<OptionDoubleArray *>(newRow->get("values")); horizontalLabels << QString::fromStdString(factorName->value()); values = option->value(); verticalHeaders = headers->value(); if (!setRowCount) { this->setRowCount(values.size()); setRowCount = true; } this->insertColumn(column); int row = 0; for (std::vector<double>::iterator i = values.begin(); i != values.end(); ++i, ++row) { QTableWidgetItem *newItem = new QTableWidgetItem(QString::number(*i)); this->setItem(row, column, newItem); } column++; } for (std::vector<std::vector<std::string> >::iterator it = verticalHeaders.begin(); it != verticalHeaders.end(); it++) { for(std::vector<std::string>::iterator col = it->begin(); col != it->end(); col++) { verticalLabels << QString::fromStdString(*col); } } this->setHorizontalHeaderLabels(horizontalLabels); this->setVerticalHeaderLabels(verticalLabels); updateTableValues(); _boundTo->blockSignals(false, false); this->blockSignals(false); }
Option *OptionString::clone() const { OptionString *c = new OptionString(); c->setValue(_value); return c; }
void BoundTableWidget::updateTableValues(bool noSignal) { if (_boundTo == NULL) { return; } int columnCount = this->columnCount(); int rowCount = this->rowCount(); _groups.clear(); std::vector<std::string> verticalHeaders; // Get verticalHeaders for (int i = 0; i < rowCount; ++i) { QTableWidgetItem *verticalHeaderItem = this->verticalHeaderItem(i); QString header = ""; if (verticalHeaderItem != NULL) { header = verticalHeaderItem->toolTip(); // Tooltip will have the entire text } verticalHeaders.push_back(fq(header)); } for (int i = 0; i < columnCount; ++i) { Options *newRow = static_cast<Options *>(_boundTo->rowTemplate()->clone()); OptionString *factorName = static_cast<OptionString *>(newRow->get("name")); QString header = ""; QTableWidgetItem *horizontalHeaderItem = this->horizontalHeaderItem(i); if (horizontalHeaderItem != NULL) { header = horizontalHeaderItem->text(); } else { // TODO: Revisit this part continue; } factorName->setValue(fq(header)); OptionDoubleArray *option = static_cast<OptionDoubleArray *>(newRow->get("values")); OptionVariables *headers = static_cast<OptionVariables *>(newRow->get("levels")); headers->setValue(verticalHeaders); std::vector<double> values; std::vector<std::string> levels; for (int j = 0; j < rowCount; ++j) { QTableWidgetItem *rowItem = this->item(j, i); QString content = ""; if (rowItem != NULL) { content = rowItem->text(); } values.push_back(content.toDouble()); } option->setValue(values); _groups.push_back(newRow); } if (noSignal) _boundTo->blockSignals(true); _boundTo->setValue(_groups); if (noSignal) _boundTo->blockSignals(false, false); }