本文整理汇总了C++中ParamXMLFile::store方法的典型用法代码示例。如果您正苦于以下问题:C++ ParamXMLFile::store方法的具体用法?C++ ParamXMLFile::store怎么用?C++ ParamXMLFile::store使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ParamXMLFile
的用法示例。
在下文中一共展示了ParamXMLFile::store方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getSystemParameters
Param File::getSystemParameters()
{
String filename = String(QDir::homePath()) + "/.OpenMS/OpenMS.ini";
Param p;
if (!File::readable(filename)) // create file
{
p = getSystemParameterDefaults_();
String dirname = String(QDir::homePath()) + "/.OpenMS";
QDir dir(dirname.toQString());
if (!dir.exists())
{
if (!File::writable(dirname))
{
LOG_WARN << "Warning: Cannot create folder '.OpenMS' in user home directory. Please check your environment!" << std::endl;
LOG_WARN << " Home directory determined is: " << QDir::homePath().toStdString() << "." << std::endl;
return p;
}
dir.mkpath(".");
}
if (!File::writable(filename))
{
LOG_WARN << "Warning: Cannot create '.OpenMS/OpenMS.ini' in user home directory. Please check your environment!" << std::endl;
LOG_WARN << " Home directory determined is: " << QDir::homePath().toStdString() << "." << std::endl;
return p;
}
ParamXMLFile paramFile;
paramFile.store(filename, p);
}
else
{
ParamXMLFile paramFile;
paramFile.load(filename, p);
// check version
if (!p.exists("version") || (p.getValue("version") != VersionInfo::getVersion()))
{
if (!p.exists("version"))
{
LOG_WARN << "Broken file '" << filename << "' discovered. The 'version' tag is missing." << std::endl;
}
else // old version
{
LOG_WARN << "File '" << filename << "' is deprecated." << std::endl;
}
LOG_WARN << "Updating missing/wrong entries in '" << filename << "' with defaults!" << std::endl;
Param p_new = getSystemParameterDefaults_();
p.setValue("version", VersionInfo::getVersion()); // update old version, such that p_new:version does not get overwritten during update()
p_new.update(p);
paramFile.store(filename, p_new);
}
}
return p;
}
示例2: storeINI_
void ToolsDialog::storeINI_()
{
//nothing to save
if (arg_param_.empty())
return;
filename_ = QFileDialog::getSaveFileName(this, tr("Save ini file"), default_dir_.c_str(), tr("ini files (*.ini)"));
//not file selected
if (filename_.isEmpty())
{
return;
}
if (!filename_.endsWith(".ini"))
filename_.append(".ini");
editor_->store();
arg_param_.insert(getTool() + ":1:", vis_param_);
try
{
ParamXMLFile paramFile;
paramFile.store(filename_.toStdString(), arg_param_);
}
catch (Exception::BaseException& e)
{
QMessageBox::critical(this, "Error", (String("Error storing INI file: ") + e.getMessage()).c_str());
return;
}
}
示例3: saveFile
bool INIFileEditorWindow::saveFile()
{
if (filename_.isEmpty())
{
return false;
}
editor_->store();
ParamXMLFile paramFile;
paramFile.store(filename_.toStdString(), param_);
updateWindowTitle(editor_->isModified());
return true;
}
示例4: saveFileAs
bool INIFileEditorWindow::saveFileAs()
{
filename_ = QFileDialog::getSaveFileName(this, tr("Save ini file"), current_path_.toQString(), tr("ini files (*.ini)"));
if (!filename_.isEmpty())
{
if (!filename_.endsWith(".ini"))
filename_.append(".ini");
editor_->store();
ParamXMLFile paramFile;
paramFile.store(filename_.toStdString(), param_);
updateWindowTitle(editor_->isModified());
return true;
}
return false;
}
示例5: ok_
void ToolsDialog::ok_()
{
if (input_combo_->currentText() == "<select>" || tools_combo_->currentText() == "<select>")
{
QMessageBox::critical(this, "Error", "You have to select a tool and an input argument!");
}
else
{
editor_->store();
arg_param_.insert(getTool() + ":1:", vis_param_);
if (!File::writable(ini_file_))
{
QMessageBox::critical(this, "Error", (String("Could not write to '") + ini_file_ + "'!").c_str());
}
ParamXMLFile paramFile;
paramFile.store(ini_file_, arg_param_);
accept();
}
}
示例6: main
Int main(int argc, const char** argv)
{
if (argc < 2) return 1;
// the path to the data should be given on the command line
String tutorial_data_path(argv[1]);
QApplication app(argc, const_cast<char**>(argv));
Param param;
ParamXMLFile paramFile;
paramFile.load(tutorial_data_path + "/data/Tutorial_ParamEditor.ini", param);
ParamEditor* editor = new ParamEditor(0);
editor->load(param);
editor->show();
app.exec();
editor->store();
paramFile.store("Tutorial_ParamEditor_out.ini", param);
return 0;
} //end of main
示例7: updateINI
//.........这里部分代码省略.........
Param p;
ParamXMLFile paramFile;
paramFile.load(infile, p);
// get sections (usually there is only one - or the user has merged INI files manually)
StringList sections = updater.getToolNamesFromINI(p);
if (sections.empty())
{
writeLog_("Update for file " + infile + " failed because tool section does not exist. Check INI file for corruption!");
failed_.push_back(infile);
return;
}
// get version of first section
String version_old = "Unknown";
if (!p.exists(sections[0] + ":version"))
{
writeLog_("No OpenMS version information found in file " + infile + "! Cannot update!");
failed_.push_back(infile);
return;
}
else
{
version_old = p.getValue(sections[0] + ":version");
// TODO: return on newer version?!
}
// update sections
writeDebug_("Section names: " + ListUtils::concatenate(sections, ", "), 1);
bool update_success = true;
for (Size s = 0; s < sections.size(); ++s)
{
String sec_inst = sections[s] + ":" + String(this_instance) + ":";
// check for default instance
if (!p.exists(sec_inst + "debug"))
{
writeLog_("Update for file '" + infile + "' failed because the instance section '" + sec_inst + "' does not exist. Use -instance or check INI file for corruption!");
update_success = false;
break;
}
String new_tool;
String ttype;
// find mapping to new tool (might be the same name)
if (p.exists(sec_inst + "type")) ttype = p.getValue(sec_inst + "type");
if (!updater.getNewToolName(sections[s], ttype, new_tool))
{
String type_text = ((ttype == "") ? "" : " with type '" + ttype + "' ");
writeLog_("Update for file '" + infile + "' failed because the tool '" + sections[s] + "'" + type_text + "is unknown. TOPPAS file seems to be corrupted!");
update_success = false;
break;
}
// get defaults of new tool by calling it
QProcess pr;
QStringList arguments;
arguments << "-write_ini";
arguments << tmp_ini_file.toQString();
arguments << "-instance";
arguments << String(this_instance).toQString();
pr.start((path + "/" + new_tool).toQString(), arguments);
if (!pr.waitForFinished(-1))
{
writeLog_("Update for file '" + infile + "' failed because the tool '" + new_tool + "' returned with an error! Check if the tool works properly.");
update_success = false;
break;
}
// update defaults with old values
Param new_param;
paramFile.load(tmp_ini_file, new_param);
new_param = new_param.copy(new_tool, true);
Param old_param = p.copy(sections[s], true);
new_param.update(old_param);
// push back changes
p.remove(sections[s] + ":");
p.insert(new_tool, new_param);
}
if (!update_success)
{
failed_.push_back(infile);
return;
}
// STORE
if (outfile.empty()) // create a backup
{
QFileInfo fi(infile.toQString());
String backup_filename = String(fi.path()) + "/" + fi.completeBaseName() + "_v" + version_old + ".ini";
QFile::rename(infile.toQString(), backup_filename.toQString());
std::cout << "Backup of input file created: " << backup_filename << std::endl;
// write updated/new file
paramFile.store(infile, p);
}
else
{
paramFile.store(outfile, p);
}
}
示例8: updateTOPPAS
//.........这里部分代码省略.........
update_success = false;
break;
}
if (p.getValue(sec_inst + "toppas_type") != "tool") // not a tool (but input/output/merge node)
{
continue;
}
if (!p.exists(sec_inst + "tool_name"))
{
writeLog_("Update for file " + infile + " failed because the vertex #" + String(v) + " does not have a 'tool_name' node. Check INI file for corruption!");
update_success = false;
break;
}
String old_name = p.getValue(sec_inst + "tool_name");
String new_tool;
String ttype;
// find mapping to new tool (might be the same name)
if (p.exists(sec_inst + "tool_type")) ttype = p.getValue(sec_inst + "tool_type");
if (!updater.getNewToolName(old_name, ttype, new_tool))
{
String type_text = ((ttype == "") ? "" : " with type '" + ttype + "' ");
writeLog_("Update for file " + infile + " failed because the tool '" + old_name + "'" + type_text + "is unknown. TOPPAS file seems to be corrupted!");
update_success = false;
break;
}
// set new tool name
p.setValue(sec_inst + "tool_name", new_tool);
// delete TOPPAS type
if (new_tool != "GenericWrapper")
{
p.setValue(sec_inst + "tool_type", "");
}
// get defaults of new tool by calling it
QProcess pr;
QStringList arguments;
arguments << "-write_ini";
arguments << tmp_ini_file.toQString();
arguments << "-instance";
arguments << String(this_instance).toQString();
pr.start((path + "/" + new_tool).toQString(), arguments);
if (!pr.waitForFinished(-1))
{
writeLog_("Update for file " + infile + " failed because the tool '" + new_tool + "' returned with an error! Check if the tool works properly.");
update_success = false;
break;
}
// update defaults with old values
Param new_param;
paramFile.load(tmp_ini_file, new_param);
new_param = new_param.copy(new_tool + ":1", true);
Param old_param = p.copy(sec_inst + "parameters", true);
new_param.update(old_param);
// push back changes
p.remove(sec_inst + "parameters:");
p.insert(sec_inst + "parameters", new_param);
}
if (!update_success)
{
failed_.push_back(infile);
return;
}
paramFile.store(tmp_ini_file, p);
// update internal structure (e.g. edges format changed from 1.8 to 1.9)
int argc = 1;
const char* c = "IniUpdater";
const char** argv = &c;
QApplication app(argc, const_cast<char**>(argv), false);
String tmp_dir = File::getTempDirectory() + "/" + File::getUniqueName();
QDir d;
d.mkpath(tmp_dir.toQString());
TOPPASScene ts(nullptr, tmp_dir.toQString(), false);
paramFile.store(tmp_ini_file, p);
ts.load(tmp_ini_file);
ts.store(tmp_ini_file);
paramFile.load(tmp_ini_file, p);
// STORE
if (outfile.empty()) // create a backup
{
QFileInfo fi(infile.toQString());
String new_name = String(fi.path()) + "/" + fi.completeBaseName() + "_v" + version + ".toppas";
QFile::rename(infile.toQString(), new_name.toQString());
// write new file
paramFile.store(infile, p);
}
else
{
paramFile.store(outfile, p);
}
}
示例9: main_
//.........这里部分代码省略.........
maximum_sequence_length);
}
else if (temp_type == SVMWrapper::OLIGO)
{
encoded_training_sample =
encoder.encodeLibSVMProblemWithOligoBorderVectors(training_peptides,
training_labels,
k_mer_length,
allowed_amino_acid_characters,
svm.getIntParameter(SVMWrapper::BORDER_LENGTH));
}
if (!start_values.empty())
{
String digest = "";
bool output_flag = false;
if (debug_level >= 1)
{
output_flag = true;
vector<String> parts;
outputfile_name.split('/', parts);
if (parts.empty())
{
digest = outputfile_name;
}
else
{
digest = parts[parts.size() - 1];
}
}
SVMData dummy;
DoubleReal cv_quality = svm.performCrossValidation(encoded_training_sample,
dummy,
false,
start_values,
step_sizes,
end_values,
number_of_partitions,
number_of_runs,
optimized_parameters,
additive_cv,
output_flag,
"performances_" + digest + ".txt");
String debug_string = "Best parameters found in cross validation:";
for (parameters_iterator = optimized_parameters.begin();
parameters_iterator != optimized_parameters.end();
++parameters_iterator)
{
svm.setParameter(parameters_iterator->first,
parameters_iterator->second);
if (parameters_iterator->first == SVMWrapper::DEGREE)
{
debug_string += " degree: " + String(parameters_iterator->second);
}
else if (parameters_iterator->first == SVMWrapper::C)
{
debug_string += " C: " + String(parameters_iterator->second);
}
else if (parameters_iterator->first == SVMWrapper::NU)
{
debug_string += " nu: " + String(parameters_iterator->second);
}
else if (parameters_iterator->first == SVMWrapper::SIGMA)
{
debug_string += " sigma: " + String(parameters_iterator->second);
}
}
debug_string += " with performance " + String(cv_quality);
writeDebug_(debug_string, 1);
}
svm.train(encoded_training_sample);
//-------------------------------------------------------------
// writing output
//-------------------------------------------------------------
svm.saveModel(outputfile_name);
// If the oligo-border kernel is used some additional information has to be stored
if (temp_type == SVMWrapper::OLIGO)
{
encoder.storeLibSVMProblem(outputfile_name + "_samples", encoded_training_sample);
additional_parameters.setValue("kernel_type", temp_type);
if (temp_type == SVMWrapper::OLIGO)
{
additional_parameters.setValue("border_length", svm.getIntParameter(SVMWrapper::BORDER_LENGTH));
additional_parameters.setValue("k_mer_length", k_mer_length);
additional_parameters.setValue("sigma", svm.getDoubleParameter(SVMWrapper::SIGMA));
}
ParamXMLFile paramFile;
paramFile.store(outputfile_name + "_additional_parameters", additional_parameters);
}
return EXECUTION_OK;
}
示例10: store
p.addTags("test:float", ListUtils::create<String>("a,b,c"));
START_SECTION((void store(const String& filename, const Param& param) const))
ParamXMLFile paramFile;
Param p2(p);
p2.setValue("test:a:a1", 47.1,"a1desc\"<>\nnewline");
p2.setValue("test:b:b1", 47.1);
p2.setSectionDescription("test:b","bdesc\"<>\nnewline");
p2.setValue("test2:a:a1", 47.1);
p2.setValue("test2:b:b1", 47.1,"",ListUtils::create<String>("advanced"));
p2.setSectionDescription("test2:a","adesc");
//exception
Param p300;
TEST_EXCEPTION(Exception::UnableToCreateFile, paramFile.store("/does/not/exist/FileDoesNotExist.xml",p300))
String filename;
NEW_TMP_FILE(filename);
paramFile.store(filename,p2);
Param p3;
paramFile.load(filename,p3);
TEST_REAL_SIMILAR(float(p2.getValue("test:float")), float(p3.getValue("test:float")))
TEST_EQUAL(p2.getValue("test:string"), p3.getValue("test:string"))
TEST_EQUAL(p2.getValue("test:int"), p3.getValue("test:int"))
TEST_REAL_SIMILAR(float(p2.getValue("test2:float")), float(p3.getValue("test2:float")))
TEST_EQUAL(p2.getValue("test2:string"), p3.getValue("test2:string"))
TEST_EQUAL(p2.getValue("test2:int"), p3.getValue("test2:int"))
TEST_STRING_EQUAL(p2.getDescription("test:float"), p3.getDescription("test:float"))
TEST_STRING_EQUAL(p2.getDescription("test:string"), p3.getDescription("test:string"))