示例#1
0
std::string cfg::node::to_string() const
{
	YAML::Emitter out;
	cfg::encode(out, *this);

	return {out.c_str(), out.size()};
}
示例#2
0
bool ParamManager::save_to_file(std::string filename)
{
  // build YAML document
  YAML::Emitter yaml;
  yaml << YAML::BeginSeq;
  std::map<std::string, Param>::iterator it;
  for (it = params_.begin(); it != params_.end(); it++)
  {
    yaml << YAML::Flow;
    yaml << YAML::BeginMap;
    yaml << YAML::Key << "name" << YAML::Value << it->second.getName();
    yaml << YAML::Key << "type" << YAML::Value << (int) it->second.getType();
    yaml << YAML::Key << "value" << YAML::Value << it->second.getValue();
    yaml << YAML::EndMap;
  }
  yaml << YAML::EndSeq;

  // write to file
  try
  {
    std::ofstream fout;
    fout.open(filename.c_str());
    fout << yaml.c_str();
    fout.close();
  }
  catch (...)
  {
    return false;
  }

  return true;
}
void GenericVectorMessage::InstancedImplementation::decode(const YAML::Node& node)
{
    YAML::Emitter emitter;
    emitter << node;
    std::cout << "vector instance: decode " << emitter.c_str() << std::endl;
    value = node["values"].as<std::vector<TokenData::Ptr> >();
}
示例#4
0
/**
 * Saves new battle data to a YAML file.
 * @param filename YAML filename.
 */
void NewBattleState::save(const std::string &filename)
{
	std::string s = Options::getMasterUserFolder() + filename + ".cfg";
	std::ofstream sav(s.c_str());
	if (!sav)
	{
		Log(LOG_WARNING) << "Failed to save " << filename << ".cfg";
		return;
	}
	YAML::Emitter out;

	YAML::Node node;
	node["mission"] = _cbxMission->getSelected();
	node["craft"] = _cbxCraft->getSelected();
	node["darkness"] = _slrDarkness->getValue();
	node["terrain"] = _cbxTerrain->getSelected();
	node["alienRace"] = _cbxAlienRace->getSelected();
	node["difficulty"] = _cbxDifficulty->getSelected();
	node["alienTech"] = _slrAlienTech->getValue();
	node["base"] = _game->getSavedGame()->getBases()->front()->save();
	out << node;

	sav << out.c_str();
	sav.close();
	if (!sav)
	{
		Log(LOG_WARNING) << "Failed to save " << filename << ".cfg";
	}
}
示例#5
0
//--------------------------------------------------------------
void testApp::keyPressed(int key){
    if(key == 'r'){
        parseYAML();
    }
    if(key == 's'){
        ofColor color = ofColor(ofRandom(255),ofRandom(255),ofRandom(255));
        ofPoint p1 = ofPoint(ofRandom(3,10), ofRandom(3,10));
        ofPoint p2 = ofPoint(ofRandom(20,50), ofRandom(20,50));
        int s1 = ofRandom(10);
        int s2 = ofRandom(20);
        
        YAML::Emitter out;
        out << YAML::BeginMap;     
        out << YAML::Key << "name";
        out << YAML::Value << "Greg Borenstein";
        out << YAML::Key << "color";
        out << YAML::Value << color;
        out << YAML::Key << "point1";
        out << YAML::Value << p1;
        out << YAML::Key << "point2";
        out << YAML::Value << p2;
        out << YAML::Key << "size1";
        out << YAML::Value << s1;
        out << YAML::Key << "size2";
        out << YAML::Value << s2;
        
        out << YAML::EndMap;
        
        int l = strlen(out.c_str());
        
        ofBuffer yamlData;
        yamlData.set((const char *)out.c_str(), l);
        bool fileWritten = ofBufferToFile(ofToDataPath("my_points.yml"), yamlData); 
    }
}
示例#6
0
		/**
		 * @return A string representation of the full YAML output
		 */
		std::string &string () {
			TRACE ("Emitting parameters");
			YAML::Emitter out;
			out << *this;
			yaml_data = out.c_str ();
			return yaml_data;
		}
TrackExtractor *defaultTE(void) {
    MaggotTrackExtractor *te = new MaggotTrackExtractor();
    te->background_blur_sigma = 0;
    te->background_resampleInterval = 200;
    te->blurThresholdIm_sigma = 0;
    te->endFrame = -1;
    te->startFrame = 0;
    te->analysisRectangle = cvRect (0,0,-1,-1);
    te->extension = string(".mmf");
    te->fnm = _frame_none;
    te->imstacklength = 0;
    te->logVerbosity = verb_debug;
    te->maxArea = 2000;
    te->minArea = 5;
    te->maxExtractDist = 15;
    te->nBackgroundFrames = 5;
    te->overallThreshold = 30;
    te->padding = 0;
    te->showExtraction = true;
    te->startFrame = 0;
    te->winSize = 50;
    te->setMaxAngle(1.57);
    YAML::Emitter out;
    ofstream os(default_tename);
    te->toYAML(out);
    cout << out.c_str();
    os << out.c_str();

    return te;
}
示例#8
0
void Settings::UpdateInitConfig() {
    YAML::Emitter emitter;
    emitter << YAML::BeginMap;
    //emitter << YAML::Key << CONFIG_UPDATE_INTERVAL;
    //emitter << YAML::Value << m_nUpdateTimer;

//    emitter << YAML::Key << LAUNCHER;
//    std::map<std::string, std::string> launcher;
//    launcher[QString(LAUNCHER_VER).toStdString()] = m_Config.m_Launcher.m_Version.toStdString();
//    launcher[QString(LAUNCHER_UPDATE_URL).toStdString()] = m_Config.m_Launcher.m_Url.toString().toStdString();
//    emitter << YAML::Value << launcher;

    EmitAppConfig(emitter, STABLE, m_Config.m_Stable);
    EmitAppConfig(emitter, QA, m_Config.m_Test);
    EmitAppConfig(emitter, DEVELOPMENT, m_Config.m_Development);
    EmitAppConfig(emitter, DEPENDENCIES, m_Config.m_Dependencies);

    emitter << YAML::EndMap;

    QString path = DirectoryManager::GetInstance()->GetDocumentsDirectory() + InitFile;
    QFile file(path);
    if (!file.open(QFile::WriteOnly | QFile::Truncate)) {
        Logger::GetInstance()->AddLog(tr("Error save config"));
        return;
    }

    file.write(emitter.c_str());

    file.close();
}
示例#9
0
文件: Run.hpp 项目: yliu120/K3
  void runProgram(Options opt) {

    std::vector<string> peer_strs = opt.peer_strings;
    bool simulation = opt.simulation;
    std::string log_level = opt.log_level;
    std::string log_path = opt.json_path;
    std::string result_var = opt.result_var;
    std::string result_path = opt.result_path;

    std::vector<std::string> configurations;

    for (auto p: peer_strs) {
      if (p.size() > 0 && p[0] != '{') {
        for (auto d: YAML::LoadAllFromFile(p)) {
          YAML::Emitter out;
          out << d;
          configurations.push_back(std::string {out.c_str()});
        }
      } else {
        configurations.push_back(p);
      }
    }

    typedef std::map<Address, shared_ptr<__k3_context>> ctxt_map;
    typedef shared_ptr<Engine> e_ptr;
    std::list<tuple<e_ptr, ctxt_map>> engines;

    shared_ptr<MessageQueues> queues = make_shared<MessageQueues>();
    list<Address> peers;
    for (auto& s: configurations) {
      ctxt_map contexts;
      e_ptr engine = make_shared<Engine>();
      auto gc = make_shared<context>(*engine);
      gc->__patch(s);
      gc->initDecls(unit_t {});
      contexts[gc->me] = gc;
      queues->addQueue(gc->me);
      peers.push_back(gc->me);
      SystemEnvironment se = defaultEnvironment(getAddrs(contexts));
      engine->configure(simulation, se, make_shared<DefaultMessageCodec>(), log_level, log_path, result_var, result_path, queues);
      processRoles(contexts);
      auto t = tuple<e_ptr, ctxt_map>(engine, contexts);
      engines.push_back(t);
    }

     using boost::thread;
     using boost::thread_group;
     auto l = std::list<shared_ptr<thread>>();
     for (auto& t : engines) {
       auto engine = get<0>(t);
       auto contexts = get<1>(t);
       shared_ptr<thread> thread = engine->forkEngine(make_shared<virtualizing_message_processor>(contexts));
       l.push_back(thread);
     }
     // Block until completion
     for (auto th : l) {
       th->join();
     }

  }
示例#10
0
		// update_info writes m_next_id and m_free_ids to "info.yaml"
		void update_info()
		{
			YAML::Emitter out;
			out << YAML::BeginMap
			    << YAML::Key << "next"
			    << YAML::Value << m_next_id;
			if(!m_free_ids.empty())
			{
				out << YAML::Key << "free"
				    << YAML::Value << YAML::BeginSeq;
				for(auto it = m_free_ids.begin(); it != m_free_ids.end(); ++it)
				{
					out << *it;
				}
				out << YAML::EndSeq;
			}
			out << YAML::EndMap;

			fstream file;
			file.open(m_foldername + "/info.yaml", ios_base::out);
			if(file.is_open())
			{
				file << out.c_str();
				file.close();
			}
		}
示例#11
0
    const std::string CFGManager::writeConfigToString(const char *group,
                                                      const unsigned char saveOption) const {
      YAML::Emitter out;
      mapStringToParam::const_iterator iter;
      string lastGroup = "";
      CFGParam *param = NULL;
      out << YAML::BeginMap;
      mutexCFGParams.lock();

      for(iter = cfgParamsByString.begin(); iter != cfgParamsByString.end(); ++iter) {
        param = iter->second;
        if(!group || param->getGroup() == string(group)) {
          if( (param->getOption() & saveOption)  || group) {
            if(lastGroup != param->getGroup()) {
              if(lastGroup != "") {
                out << YAML::EndSeq;
              }
              lastGroup = param->getGroup();
              out << YAML::Key << lastGroup;
              out << YAML::Value << YAML::BeginSeq;
            }
            param->writeToYAML(out);
          }
        }

      } //for
      out << YAML::EndSeq;
      out << YAML::EndMap;

      mutexCFGParams.unlock();

      return out.c_str();
    }
示例#12
0
		bool write_yaml_object(doid_t do_id, const Class* dcc, const ObjectData &dbo)
		{
			// Build object as YAMl output
			YAML::Emitter out;
			out << YAML::BeginMap
			    << YAML::Key << "id"
			    << YAML::Value << do_id
			    << YAML::Key << "class"
			    << YAML::Value << dcc->get_name()
			    << YAML::Key << "fields"
			    << YAML::Value << YAML::BeginMap;
			for(auto it = dbo.fields.begin(); it != dbo.fields.end(); ++it)
			{
				write_yaml_field(out, it->first, it->second);
			}
			out << YAML::EndMap
			    << YAML::EndMap;

			// Print YAML to file
			fstream file;
			file.open(filename(do_id), ios_base::out);
			if(file.is_open())
			{
				file << out.c_str();
				file.close();
				return true;
			}
			return false;
		}
void DepthObstacleGrid::saveYML(const std::string &filename){
  
  YAML::Emitter out;
  std::ofstream ofstr(filename.c_str());  
  out << YAML::BeginSeq;
  
  for(std::vector<GridElement>::iterator it = grid.begin(); it != grid.end(); it++){
    
    if( (!std::isnan(it->depth_variance)) && (!std::isnan(it->depth) ) ){
      out << YAML::BeginMap;
      out << YAML::Key << "position";
      std::vector<double> vals;
      vals.push_back(it->pos.x());
      vals.push_back(it->pos.y());
      vals.push_back(it->depth);

      out << YAML::Value << YAML::Flow << vals;
      out << YAML::EndMap;
    }
    
    
  }
  
  out << YAML::EndSeq;
  ofstr << out.c_str();
}
示例#14
0
int main(int argc, char **argv)
{
  if (argc != 4 && argc != 5)
  {
    std::cout << "Usage: rosrun giskard extract_expression <start_link> <end_link> <urdf> (optional <output_file>)" << std::endl;
    return 0;
  }
  std::string start_link = argv[1];
  std::string end_link = argv[2];
  std::string urdf_path = argv[3];
  YAML::Node yaml = giskard::ExpressionExtractor::extract(start_link, end_link, urdf_path);
  YAML::Emitter out;
  out << yaml;
  if (argc == 5)
  {
    std::ofstream output_file;
    output_file.open(argv[4]);
    if (!output_file.is_open())
      throw giskard::WriteError(argv[4]);
    output_file << out.c_str();
    output_file.close();
  }
  else
  {
    std::cout << out.c_str() << std::endl;
  }


  return 0;
}
示例#15
0
// Writes a minimal masterlist that only contains mods that have Bash Tag suggestions,
// and/or dirty messages, plus the Tag suggestions and/or messages themselves and their
// conditions, in order to create the Wrye Bash taglist. outputFile is the path to use
// for output. If outputFile already exists, it will only be overwritten if overwrite is true.
void ApiDatabase::WriteMinimalList(const std::string& outputFile, const bool overwrite) {
  if (!boost::filesystem::exists(boost::filesystem::path(outputFile).parent_path()))
    throw std::invalid_argument("Output directory does not exist.");

  if (boost::filesystem::exists(outputFile) && !overwrite)
    throw FileAccessError("Output file exists but overwrite is not set to true.");

  Masterlist temp = game_.GetMasterlist();
  std::unordered_set<PluginMetadata> minimalPlugins;
  for (const auto &plugin : temp.Plugins()) {
    PluginMetadata p(plugin.Name());
    p.Tags(plugin.Tags());
    p.DirtyInfo(plugin.DirtyInfo());
    minimalPlugins.insert(p);
  }

  YAML::Emitter yout;
  yout.SetIndent(2);
  yout << YAML::BeginMap
    << YAML::Key << "plugins" << YAML::Value << minimalPlugins
    << YAML::EndMap;

  boost::filesystem::path p(outputFile);
  boost::filesystem::ofstream out(p);
  if (out.fail())
    throw FileAccessError("Couldn't open output file.");
  out << yout.c_str();
  out.close();
}
示例#16
0
文件: generators.cpp 项目: dbb/loot
    //Default settings file generation.
    void GenerateDefaultSettingsFile(const std::string& file) {

        BOOST_LOG_TRIVIAL(info) << "Generating default settings file.";

        YAML::Node root;
        std::vector<Game> games;

        root["Language"] = "eng";
        root["Game"] = "auto";
        root["Last Game"] = "auto";
        root["Debug Verbosity"] = 0;
        root["Update Masterlist"] = true;

        games.push_back(Game(Game::tes4));
        games.push_back(Game(Game::tes5));
        games.push_back(Game(Game::fo3));
        games.push_back(Game(Game::fonv));
        games.push_back(Game(Game::tes4, "Nehrim").SetDetails("Nehrim - At Fate's Edge", "Nehrim.esm", "https://github.com/loot-developers/loot-oblivion.git", "gh-pages", "", "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Nehrim - At Fate's Edge_is1"));

        root["Games"] = games;

        //Save settings.
        YAML::Emitter yout;
        yout.SetIndent(2);
        yout << root;

        boost::filesystem::path p(file);
        loot::ofstream out(p);
        out << yout.c_str();
        out.close();
    }
示例#17
0
文件: api.cpp 项目: Eclipse06/loot
// Writes a minimal masterlist that only contains mods that have Bash Tag suggestions,
// and/or dirty messages, plus the Tag suggestions and/or messages themselves and their
// conditions, in order to create the Wrye Bash taglist. outputFile is the path to use
// for output. If outputFile already exists, it will only be overwritten if overwrite is true.
LOOT_API unsigned int loot_write_minimal_list (loot_db db, const char * const outputFile, const bool overwrite) {
    if (db == NULL || outputFile == NULL)
        return c_error(loot_error_invalid_args, "Null pointer passed.");

    if (boost::filesystem::exists(outputFile) && !overwrite)
        return c_error(loot_error_invalid_args, "Output file exists but overwrite is not set to true.");

    std::list<loot::Plugin> temp = db->metadata;
    for (std::list<loot::Plugin>::iterator it=temp.begin(), endIt=temp.end(); it != endIt; ++it) {
        loot::Plugin p(it->Name());
        p.Tags(it->Tags());
        p.DirtyInfo(it->DirtyInfo());

        *it = p;
    }

    YAML::Emitter yout;
    yout.SetIndent(2);
    yout << YAML::BeginMap
         << YAML::Key << "plugins" << YAML::Value << temp
         << YAML::EndMap;

    boost::filesystem::path p(outputFile);
    loot::ofstream out(p);
    if (out.fail())
        return c_error(loot_error_invalid_args, "Couldn't open output file");
    out << yout.c_str();
    out.close();

    return loot_ok;
}
示例#18
0
	const string Desc() {
		YAML::Emitter emitter;
		emitter << _yaml_root;
		if (! emitter.good())
			THROW("Unexpected");
		return emitter.c_str();
	}
示例#19
0
 TEST EmitEmptyNode()
 {
     YAML::Node node;
     YAML::Emitter emitter;
     emitter << node;
     YAML_ASSERT(std::string(emitter.c_str()) == "");
     return true;
 }
示例#20
0
 void ConfigMap::toYamlStream(std::ostream &out) const {
   YAML::Emitter emitter;
   dumpConfigMapToYaml(emitter, *this);
   if(!emitter.good()) {
     fprintf(stderr, "ERROR: ConfigMap::toYamlStream failed!\n");
     return;
   }
   out << emitter.c_str() << endl;
 }
示例#21
0
void Document::write_to_file(const std::string& filename)
{
    YAML::Emitter emitter;
    emitter << *this;

    std::ofstream fout(filename.c_str());
    assert(fout.is_open());
    if(fout.is_open())
        fout << emitter.c_str();
}
示例#22
0
void LootSettings::save(const boost::filesystem::path& file) {
  lock_guard<recursive_mutex> guard(mutex_);

  YAML::Emitter yout;
  yout.SetIndent(2);
  yout << toYaml();

  boost::filesystem::ofstream out(file);
  out << yout.c_str();
}
示例#23
0
int main(int argc, char **argv) {

  if (argc != 2) {
    printf("usage: generate_map <output path>\n");
    return -1;
  }

  double x = 0, y = 0;
  int tag_id = 0;

  Tag tag;

  //  encode into map
  YAML::Emitter emitter;
  emitter << YAML::Comment("MRSL Floor Map, 9x12 tags");
  emitter << YAML::BeginSeq;
  emitter << YAML::Block;

  for (int i = 0; i < 9; i++) {
    x = 0.0;

    for (int j = 0; j < 12; j++) {
      tag.id = tag_id++;
      tag.p[0] = cv::Point3d(x + 0.152, y, 0);
      tag.p[1] = cv::Point3d(x + 0.152, y + 0.152, 0);
      tag.p[2] = cv::Point3d(x, y + 0.152, 0);
      tag.p[3] = cv::Point3d(x, y, 0);

      emitter << tag;

      x += 0.152 * 2;
    }

    if (i == 2 || i == 5) {
      y += 0.178 + 0.152;
    } else {
      y += 0.152 * 2;
    }
  }
  emitter << YAML::EndSeq;
  emitter << YAML::Comment("End of map");

  //  save to disk
  FILE *output = fopen(argv[1], "w");
  if (!output) {
    printf("Failed to open %s for writing\n", argv[1]);
    return -1;
  }

  fprintf(output, "%s", emitter.c_str());
  fclose(output);

  printf("Wrote to %s\n", argv[1]);
  return 0;
}
void AddWayPoint::saveWayPointsToFile()
{
  /*! Function for saving all the Way-Points into yaml file.
      This function opens a Qt Dialog where the user can set the name of the Way-Points file and the location.
      Furthermore, it parses the way-points into a format that could be also loaded into the Plugin.
  */
  QString fileName =
      QFileDialog::getSaveFileName(this, tr("Save Way Points"), ".yaml", tr("Way Points (*.yaml);;All Files (*)"));

  if (fileName.isEmpty())
    return;
  else
  {
    QFile file(fileName);
    if (!file.open(QIODevice::WriteOnly))
    {
      QMessageBox::information(this, tr("Unable to open file"), file.errorString());
      file.close();
      return;
    }

    YAML::Emitter out;
    out << YAML::BeginSeq;

    for (int i = 0; i < waypoints_pos.size(); i++)
    {
      out << YAML::BeginMap;
      std::vector< double > points_vec;
      points_vec.push_back(waypoints_pos[i].getOrigin().x());
      points_vec.push_back(waypoints_pos[i].getOrigin().y());
      points_vec.push_back(waypoints_pos[i].getOrigin().z());

      double rx, ry, rz;

      tf::Matrix3x3 m(waypoints_pos[i].getRotation());
      m.getRPY(rx, ry, rz, 1);
      points_vec.push_back(RAD2DEG(rx));
      points_vec.push_back(RAD2DEG(ry));
      points_vec.push_back(RAD2DEG(rz));

      out << YAML::Key << "name";
      out << YAML::Value << (i + 1);
      out << YAML::Key << "point";
      out << YAML::Value << YAML::Flow << points_vec;
      out << YAML::EndMap;
    }

    out << YAML::EndSeq;

    std::ofstream myfile;
    myfile.open(fileName.toStdString().c_str());
    myfile << out.c_str();
    myfile.close();
  }
}
示例#25
0
int main()
{
   YAML::Emitter out;
   out << YAML::BeginMap;
   out << YAML::Key << "key";
   out << YAML::Value << "value";
   out << YAML::Comment("Comment");
   out << YAML::EndMap;
   std::cout << "Here's the output YAML:\n" << out.c_str() << std::endl; 
   return 0;
}
void TrackExtractor::headerinfo(std::ostream &os) {
     YAML::Emitter out;
     toYAML(out);
     os << out.c_str() << "\n\n";
     os << outputname << "\ncontains the analysis of " <<"\n" << fstub << "\nstored in the following format:\n";
     os << tb->saveDescription();
     string fgname = fstub + "foreground." + extension;
     if (pe != NULL) {
         os << "\n\nWriting autogenerated foreground image to " << fgname << "\n";
     }
}
示例#27
0
void save_gui_cfg()
{
	YAML::Emitter out;
	out.SetSeqFormat(YAML::Flow);
	out << g_gui_cfg;

	// Save to file
	s_gui_cfg.seek(0);
	s_gui_cfg.trunc(0);
	s_gui_cfg.write(out.c_str(), out.size());
}
示例#28
0
std::string Motion::dump()
{
	YAML::Emitter em;

	motionToNode(em);

	std::stringstream oss;
	oss << em.c_str() << std::endl;


	return oss.str();
}
示例#29
0
    void MetadataList::Save(const boost::filesystem::path& filepath) {
        BOOST_LOG_TRIVIAL(trace) << "Saving metadata list to: " << filepath;
        YAML::Emitter yout;
        yout.SetIndent(2);
        yout << YAML::BeginMap
            << YAML::Key << "plugins" << YAML::Value << Plugins()
            << YAML::Key << "globals" << YAML::Value << messages
            << YAML::EndMap;

        boost::filesystem::ofstream uout(filepath);
        uout << yout.c_str();
        uout.close();
    }
示例#30
0
void SettingsHandler::saveSettings()
{
    mutex.lock();

    YAML::Emitter out;
    out << S;

    settingsFile->open(QFile::WriteOnly | QFile::Text);
    settingsFile->write(out.c_str(), out.size());
    settingsFile->close();

    mutex.unlock();
}