Exemple #1
0
void print_ptree(std::ostream& os, const boost::property_tree::ptree& pt, int depth)
{
	typedef bp::ptree::const_iterator c_it;

	if(pt.empty())
		os << "'" << pt.data() << "'\n";
	else
	{
		std::string pad("");
		pad.assign(depth*4,' ');
		++depth;
		std::string pad2 = pad + "    ";

		if(is_list(pt))
		{
			os << "[\n";
			for(c_it it=pt.begin(); it!=pt.end(); ++it)
			{
				os << pad2;
				print_ptree(os, it->second, depth);
			}
			os << pad << "]\n";
		}
		else
		{
			os << "{\n";
			for(c_it it=pt.begin(); it!=pt.end(); ++it)
			{
				os << pad2 << "'" << it->first << "': ";
				print_ptree(os, it->second, depth);
			}
			os << pad << "}\n";
		}
	}
}
	bool deserialize_json (bool & upgraded, boost::property_tree::ptree & tree_a)
	{
		auto error (false);
		if (!tree_a.empty ())
		{
			auto text_l (tree_a.get <std::string> ("thing"));
			if (text_l == "junktest")
			{
				upgraded = true;
				text_l = "changed";
				tree_a.put ("thing", text_l);
			}
			if (text_l == "error")
			{
				error = true;
			}
			text = text_l;
		}
		else
		{
			upgraded = true;
			text = "created";
			tree_a.put ("thing", text);
		}
		return error;
	}
Exemple #3
0
void genOSXPlistPrefValue(const pt::ptree& tree,
                          const Row& base,
                          unsigned int level,
                          QueryData& results) {
  if (tree.empty()) {
    Row r = base;
    r["value"] = tree.data();
    results.push_back(std::move(r));
    // No more levels to parse.
    return;
  }

  for (const auto& item : tree) {
    Row r = base;
    if (r["subkey"].size() > 0) {
      r["subkey"] += '/';
      if (item.first.size() == 0) {
        r["subkey"] += std::to_string(level++);
      }
    }

    r["subkey"] += item.first;
    genOSXPlistPrefValue(item.second, r, level, results);
  }
}
Exemple #4
0
bool rai_daemon::daemon_config::deserialize_json (bool & upgraded_a, boost::property_tree::ptree & tree_a)
{
    auto error (false);
	try
	{
		if (!tree_a.empty ())
		{
			auto version_l (tree_a.get_optional <std::string> ("version"));
			if (!version_l)
			{
				tree_a.put ("version", "1");
				version_l = "1";
			}
			upgraded_a |= upgrade_json (std::stoull (version_l.get ()), tree_a);
			rpc_enable = tree_a.get <bool> ("rpc_enable");
			auto rpc_l (tree_a.get_child ("rpc"));
			error |= rpc.deserialize_json (rpc_l);
			auto & node_l (tree_a.get_child ("node"));
			error |= node.deserialize_json (upgraded_a, node_l);
			opencl_enable = tree_a.get <bool> ("opencl_enable");
			auto & opencl_l (tree_a.get_child ("opencl"));
			error |= opencl.deserialize_json (opencl_l);
		}
		else
		{
			upgraded_a = true;
			serialize_json (tree_a);
		}
	}
	catch (std::runtime_error const &)
	{
		error = true;
	}
	return error;
}
size_t ProteinSequence::ParseUniprotPtree(const boost::property_tree::ptree& rt_tree) {
	using namespace boost::property_tree;

	if (rt_tree.empty())
		return 0;

	BOOST_FOREACH(const ptree::value_type& v, rt_tree) {
		if (v.first == "accession") {
			add_accession(v.second.data());
		}
		else if (v.first == "name") {
			vector<string> tokens;
			boost::split(tokens, v.second.data(), is_any_of("_"));
			if (tokens.size() != 2)
				cerr << "Warning: name tokens not equal to 2" << endl;
			else {
				set_name(tokens[0]);
				set_species(tokens[1]);
			}
		}
		else if (v.first == "reference") {
			const ptree &ptree_citation = v.second.get_child("citation", EmptyPtree());
			BOOST_FOREACH(const ptree::value_type& v2, ptree_citation) {
				if (v2.first == "dbReference") {
					string db = boost::to_upper_copy(v2.second.get("<xmlattr>.type", string()));
					if (db == "PUBMED") {
						int pmid = v2.second.get("<xmlattr>.id", -1);
						if (pmid < 0)
							cerr << "Warning: pmid not valid" << endl;
						else
							add_ref_pmid(pmid);
					}
				}
			}
		}
		else if (v.first == "dbReference") {
			string db = boost::to_upper_copy(v.second.get("<xmlattr>.type", string()));
			if (db == "GO") {
				string str_id = v.second.get("<xmlattr>.id", string());
				size_t pos = str_id.rfind(":") + 1;
				str_id = str_id.substr(pos);
				if (str_id.empty()) {
					cerr << "Warning: GO id is empty" << endl;
				}
				else {
					ProteinSequence::GOType go;
					BOOST_FOREACH(const ptree::value_type& v2, v.second) {
						string type = v2.second.get("<xmlattr>.type", string());
						if (type == "term")
							go.term_ = v2.second.get("<xmlattr>.value", string());
						else if (type == "evidence")
							go.evidence_ = v2.second.get("<xmlattr>.value", string());
					}
					go.id_ = atoi(str_id.data());
					add_go_term(go);
				}
			}
 extracted_ptree_iterator(const extracted_ptree& extracted_ptree,
                          const pqrs::string::replacement& replacement,
                          const boost::property_tree::ptree& pt) :
   extracted_ptree_(extracted_ptree),
   stack_size_(extracted_ptree.stack_.size() + 1)
 {
   if (! pt.empty()) {
     extracted_ptree_.stack_.push(stack_data(pt, replacement));
     extract_include_();
   }
 }
Exemple #7
0
	bool deserialize_json (bool & upgraded_a, boost::property_tree::ptree & tree_a)
	{
		auto error (false);
		if (!tree_a.empty ())
		{
			auto version_l (tree_a.get_optional<std::string> ("version"));
			if (!version_l)
			{
				tree_a.put ("version", "1");
				version_l = "1";
				upgraded_a = true;
			}
			upgraded_a |= upgrade_json (std::stoull (version_l.get ()), tree_a);
			auto wallet_l (tree_a.get<std::string> ("wallet"));
			auto account_l (tree_a.get<std::string> ("account"));
			auto & node_l (tree_a.get_child ("node"));
			rpc_enable = tree_a.get<bool> ("rpc_enable");
			auto & rpc_l (tree_a.get_child ("rpc"));
			opencl_enable = tree_a.get<bool> ("opencl_enable");
			auto & opencl_l (tree_a.get_child ("opencl"));
			try
			{
				error |= wallet.decode_hex (wallet_l);
				error |= account.decode_account (account_l);
				error |= node.deserialize_json (upgraded_a, node_l);
				error |= rpc.deserialize_json (rpc_l);
				error |= opencl.deserialize_json (opencl_l);
				if (wallet.is_zero ())
				{
					rai::random_pool.GenerateBlock (wallet.bytes.data (), wallet.bytes.size ());
					upgraded_a = true;
				}
			}
			catch (std::logic_error const &)
			{
				error = true;
			}
		}
		else
		{
			serialize_json (tree_a);
			upgraded_a = true;
		}
		return error;
	}
void printTree (boost::property_tree::ptree &pt, int level) {
  if (pt.empty()) {
    std::cout << "\""<< pt.data()<< "\"";
  } else {
    if (level) std::cout << std::endl; 
    std::cout << indent(level) << "{" << std::endl;     
    for (boost::property_tree::ptree::iterator pos = pt.begin(); pos != pt.end();) {
      std::cout << indent(level+1) << "\"" << pos->first << "\": "; 
      printTree(pos->second, level + 1); 
      ++pos; 
      if (pos != pt.end()) {
        std::cout << ","; 
      }
      std::cout << std::endl;
    } 
    std::cout << indent(level) << " }";     
  } 
  return; 
}
Exemple #9
0
void drawSnake(boost::property_tree::ptree &snakeData, std::unique_ptr<QPainter> &painter, std::unique_ptr<label> &l) {
	if (snakeData.empty()) {
		painter->fillRect(500, 0, 50, 500, Qt::darkGray);
	}
	else {
		if (snakeData.get<std::string>("game_status") == "GAME OVER") {
			QFont font;
			font.setPixelSize(50);
			font.setBold(true);
			painter->setFont(font);
			painter->drawText(snakeData.get<int>("table.width") * 2, snakeData.get<int>("table.height") * 2, "GAME OVER");
			painter->drawText(snakeData.get<int>("table.width") * 2 + 60, snakeData.get<int>("table.height") * 2 + 50, "SCORE:");
			painter->drawText(snakeData.get<int>("table.width") * 2 + 130, snakeData.get<int>("table.height") * 2 + 100, QString::number(snakeData.get<int>("game_score")));
			painter->drawText(snakeData.get<int>("table.width") * 2, snakeData.get<int>("table.height") * 2 + 150, "F5 - New Game");
		}
		else {
			if (l->direction == Direction::newGame)l->direction = Direction::right;
			QFont font;
			font.setPixelSize(10);
			font.setBold(true);
			painter->setFont(font);
			painter->fillRect(0, 0, snakeData.get<int>("table.width") * 10, snakeData.get<int>("table.height") * 10, Qt::gray);
			painter->drawPixmap(snakeData.get<int>("snakefood.x") * 10, snakeData.get<int>("snakefood.y") * 10, 10, 10, QPixmap("strawberry.png"));
			painter->fillRect(snakeData.get<int>("table.width") * 10, 0, 50, snakeData.get<int>("table.height") * 10, Qt::darkGray);
			painter->drawText(snakeData.get<int>("table.width") * 10 + 5, 10, "SCORE:");
			painter->drawText(snakeData.get<int>("table.width") * 10 + 20, 10 + 20, QString::number(snakeData.get<int>("game_score")));
			for (int j = 0; j < snakeData.get<int>("numberofsnakes"); j++) {
				for (int i = 0; i < snakeData.get<int>("snakebody."+std::to_string(j)+".length"); i++) {
					painter->fillRect(snakeData.get<int>("snakebody."+std::to_string(j)+".point." + std::to_string(i) + ".x") * 10, snakeData.get<int>("snakebody."+std::to_string(j)+".point." + std::to_string(i) + ".y") * 10, 10, 10, Qt::Dense2Pattern);
				};
			}
			
		}
	}
	

};
void
mergePropertyTrees (boost::property_tree::ptree &ptMerged,
                    const boost::property_tree::ptree &ptSecond, int level )
{
  // Value or object or array
  if (level > 0 && ptSecond.empty() ) {
    // Copy value
    ptMerged = ptSecond;
  } else if (level > 0 && ptSecond.count (std::string() ) == ptSecond.size() ) {
    // Copy array
    ptMerged = ptSecond;
  } else {
    auto it = ptSecond.begin();

    for (; it != ptSecond.end(); ++it) {
      boost::property_tree::ptree child = ptMerged.get_child (it->first.data(),
                                          boost::property_tree::ptree() );
      mergePropertyTrees (child, it->second, level + 1);

      ptMerged.erase (it->first.data() );
      ptMerged.add_child (it->first.data(), child);
    }
  }
}
Exemple #11
0
void utility::setup(const boost::property_tree::ptree &ptree) {
  if (!ptree.empty()) BOOST_THROW_EXCEPTION(error("not implemented"));
}