当前位置: 首页>>代码示例>>C++>>正文


C++ ParamXMLFile类代码示例

本文整理汇总了C++中ParamXMLFile的典型用法代码示例。如果您正苦于以下问题:C++ ParamXMLFile类的具体用法?C++ ParamXMLFile怎么用?C++ ParamXMLFile使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ParamXMLFile类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main(int argc, const char** argv)
{
#if  defined(__APPLE__)
  // we do not want to load plugins as this leads to serious problems
  // when shipping on mac os x
  QApplication::setLibraryPaths(QStringList());
#endif
  
  // ensure correct encoding of paths
  QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
  
  Map<String, String> option_lists;
  Map<String, String> options;
  options["-print"] = "print";
  Map<String, String> flags;
  flags["--help"] = "help";
  Param param;
  param.parseCommandLine(argc, argv, options, flags, option_lists);

  //catch command line errors
  if (param.exists("help") //help requested
     || argc > 3 //too many arguments
     || (argc == 3 && !param.exists("print")) //three argument but no -print
     || (param.exists("print") && param.getValue("print") == "") //-print but no file given
      )
  {
    cerr << endl
         << "INIFileEditor -- An editor for OpenMS configuration files." << endl
         << endl
         << "Usage:" << endl
         << " INIFileEditor [options] [file]" << endl
         << endl
         << "Options are:" << endl
         << " --help         Shows this help and exits" << endl
         << " -print <file>  Prints the content of the file to the command line and exits" << endl
         << endl;
    return 0;
  }

  //print a ini file as text
  if (param.exists("print"))
  {
    Param data;
    ParamXMLFile paramFile;
    try
    {
      paramFile.load(param.getValue("print"), data);
      for (Param::ParamIterator it = data.begin(); it != data.end(); ++it)
      {
        cout << it.getName() << " = " << it->value << endl;
      }
    }
    catch (Exception::BaseException& e)
    {
      LOG_ERROR << "Error while parsing file '" << param.getValue("print") << "'\n";
      LOG_ERROR << e << "\n";
    }

    return 0;
  }

  //Create window
  QApplicationTOPP app(argc, const_cast<char**>(argv));

  //set plastique style unless windows / mac style is available
  if (QStyleFactory::keys().contains("windowsxp", Qt::CaseInsensitive))
  {
    app.setStyle("windowsxp");
  }
  else if (QStyleFactory::keys().contains("macintosh", Qt::CaseInsensitive))
  {
    app.setStyle("macintosh");
  }
  else if (QStyleFactory::keys().contains("plastique", Qt::CaseInsensitive))
  {
    app.setStyle("plastique");
  }

  INIFileEditorWindow editor_window;

  //Open passed file
  if (argc == 2)
  {
    //cout << "OPEN: "  << argv[1] << endl;
    editor_window.openFile(argv[1]);
  }

#ifdef OPENMS_WINDOWSPLATFORM
  FreeConsole(); // get rid of console window at this point (we will not see any console output from this point on)
  AttachConsole(-1); // if the parent is a console, reattach to it - so we can see debug output - a normal user will usually not use cmd.exe to start a GUI)
#endif

  editor_window.show();
  return app.exec();
}
开发者ID:BioITer,项目名称:OpenMS,代码行数:95,代码来源:INIFileEditor.C

示例2: tr

  void ToolsDialog::loadINI_()
  {
    QString string;
    filename_ = QFileDialog::getOpenFileName(this, tr("Open ini file"), default_dir_.c_str(), tr("ini files (*.ini);; all files (*.*)"));
    //not file selected
    if (filename_.isEmpty())
    {
      return;
    }
    enable_();
    if (!arg_param_.empty())
    {
      arg_param_.clear();
      vis_param_.clear();
      editor_->clear();
      arg_map_.clear();
    }
    try
    {
      ParamXMLFile paramFile;
      paramFile.load(filename_.toStdString(), arg_param_);
    }
    catch (Exception::BaseException& e)
    {
      QMessageBox::critical(this, "Error", (String("Error loading INI file: ") + e.getMessage()).c_str());
      arg_param_.clear();
      return;
    }
    //set tool combo
    Param::ParamIterator iter = arg_param_.begin();
    String str;
    string = iter.getName().substr(0, iter.getName().find(":")).c_str();
    Int pos = tools_combo_->findText(string);
    if (pos == -1)
    {
      QMessageBox::critical(this, "Error", (String("Cannot apply '") + string + "' tool to this layer type. Aborting!").c_str());
      arg_param_.clear();
      return;
    }
    tools_combo_->setCurrentIndex(pos);
    //Extract the required parameters
    vis_param_ = arg_param_.copy(getTool() + ":1:", true);
    vis_param_.remove("log");
    vis_param_.remove("no_progress");
    vis_param_.remove("debug");
    //load data into editor
    editor_->load(vis_param_);

    QStringList arg_list;
    for (Param::ParamIterator iter = arg_param_.begin(); iter != arg_param_.end(); ++iter)
    {
      str = iter.getName().substr(iter.getName().rfind("1:") + 2, iter.getName().size());
      if (!str.empty() && str.find(":") == String::npos)
      {
        arg_map_.insert(make_pair(str, iter.getName()));
        arg_list << QStringList(str.c_str());
      }
    }
    arg_list.push_front("<select>");
    input_combo_->clear();
    output_combo_->clear();
    input_combo_->addItems(arg_list);
    pos = arg_list.indexOf("in");
    if (pos != -1)
    {
      input_combo_->setCurrentIndex(pos);
    }
    output_combo_->addItems(arg_list);
    pos = arg_list.indexOf("out");
    if (pos != -1 && getTool() != "FileInfo")
    {
      output_combo_->setCurrentIndex(pos);
    }
  }
开发者ID:FabianAicheler,项目名称:OpenMS,代码行数:74,代码来源:ToolsDialog.cpp

示例3: START_TEST

START_TEST(ParamXMLFile, "$Id")

ParamXMLFile* ptr = 0;
ParamXMLFile* nullPtr = 0;

START_SECTION((ParamXMLFile()))
{
  ptr = new ParamXMLFile();
  TEST_NOT_EQUAL(ptr, nullPtr)
}
END_SECTION


START_SECTION((void load(const String& filename, Param& param)))
	Param p2;
  ParamXMLFile paramFile;
	TEST_EXCEPTION(Exception::FileNotFound, paramFile.load("FileDoesNotExist.xml",p2))
END_SECTION

Param p;
p.setValue("test:float",17.4f,"floatdesc");
p.setValue("test:string","test,test,test","stringdesc");
p.setValue("test:int",17,"intdesc");
p.setValue("test2:float",17.5f);
p.setValue("test2:string","test2");
p.setValue("test2:int",18);
p.setSectionDescription("test","sectiondesc");
p.addTags("test:float", ListUtils::create<String>("a,b,c"));

START_SECTION((void store(const String& filename, const Param& param) const))
  ParamXMLFile paramFile;
开发者ID:chahuistle,项目名称:OpenMS,代码行数:31,代码来源:ParamXMLFile_test.cpp

示例4: String

  void ToolsDialog::createINI_()
  {
    String call = String("\"") + File::findExecutable(getTool()) + "\"" + " -write_ini " + ini_file_ + " -log " + ini_file_ + ".log";

    if (system(call.c_str()) != 0)
    {
      QMessageBox::critical(this, "Error", (String("Could not execute '") + call + "'!\n\nMake sure the TOPP tools are present in '" + File::getExecutablePath() + "',  that you have permission to write to the temporary file path, and that there is space left in the temporary file path.").c_str());
    }
    else if (!File::exists(ini_file_))
    {
      QMessageBox::critical(this, "Error", (String("Could not open '") + ini_file_ + "'!").c_str());
    }
    else
    {
      enable_();
      if (!arg_param_.empty())
      {
        tool_desc_->clear();
        arg_param_.clear();
        vis_param_.clear();
        editor_->clear();
        arg_map_.clear();
      }

      ParamXMLFile paramFile;
      paramFile.load((ini_file_).c_str(), arg_param_);

      tool_desc_->setText(arg_param_.getSectionDescription(getTool()).toQString());
      vis_param_ = arg_param_.copy(getTool() + ":1:", true);
      vis_param_.remove("log");
      vis_param_.remove("no_progress");
      vis_param_.remove("debug");

      editor_->load(vis_param_);

      String str;
      QStringList arg_list;
      for (Param::ParamIterator iter = arg_param_.begin(); iter != arg_param_.end(); ++iter)
      {
        str = iter.getName().substr(iter.getName().rfind("1:") + 2, iter.getName().size());
        if (str.size() != 0 && str.find(":") == String::npos)
        {
          arg_map_.insert(make_pair(str, iter.getName()));
          arg_list << QStringList(str.c_str());
        }
      }

      arg_list.push_front("<select>");
      input_combo_->clear();
      output_combo_->clear();
      input_combo_->addItems(arg_list);
      Int pos = arg_list.indexOf("in");
      if (pos != -1)
      {
        input_combo_->setCurrentIndex(pos);
      }
      output_combo_->addItems(arg_list);
      pos = arg_list.indexOf("out");
      if (pos != -1 && getTool() != "FileInfo")
      {
        output_combo_->setCurrentIndex(pos);
      }
      editor_->setFocus(Qt::MouseFocusReason);
    }
  }
开发者ID:FabianAicheler,项目名称:OpenMS,代码行数:65,代码来源:ToolsDialog.cpp


注:本文中的ParamXMLFile类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。