void linear_population_growth_generator::parseConfig( boost::property_tree::ptree & config ) {

    if( config.get_child_optional( "A" ) == boost::none ) {
        config.put( "A", m_A);
    } else {
        m_A = config.get<double>( "A", m_A );
    }

    if( config.get_child_optional( "B" ) == boost::none ) {
        config.put("B", m_B );
    } else {
        m_B = config.get<double>( "B", m_B );
    }
}
Example #2
0
	void Key::serialize(boost::property_tree::ptree& node)
	{
		node.put("<xmlattr>.keyStorageType", d_key_storage->getType());
		node.put("IsCiphered", (d_storeCipheredData && !d_isEmpty));
		cipherKeyData(node);
		d_key_storage->serialize(node);
	}
Example #3
0
    void Key::cipherKeyData(boost::property_tree::ptree& node)
    {
        if (!d_storeCipheredData || d_isEmpty)
        {
            node.put("Data", toString());
        }
        else
        {
            std::string secureKey = ((d_cipherKey == "") ? Key::secureAiKey : d_cipherKey);
            openssl::AESSymmetricKey aes = openssl::AESSymmetricKey::createFromPassphrase(secureKey);
            openssl::AESInitializationVector iv = openssl::AESInitializationVector::createNull();
            openssl::AESCipher aescipher;

            std::vector<unsigned char> divaesbuf;
            std::string strdata = "Data";
            std::vector<unsigned char> keynamebuf = std::vector<unsigned char>(strdata.begin(), strdata.end());
            keynamebuf.resize(32, 0x00);
            aescipher.cipher(keynamebuf, divaesbuf, aes, iv, false);
            openssl::AESSymmetricKey divaes = openssl::AESSymmetricKey::createFromData(divaesbuf);

            strdata = toString();
            std::vector<unsigned char> keybuf = std::vector<unsigned char>(strdata.begin(), strdata.end());
            std::vector<unsigned char> cipheredkey;
            aescipher.cipher(keybuf, cipheredkey, divaes, iv, true);

            node.put("Data", BufferHelper::toBase64(cipheredkey));
        }
    }
Example #4
0
 void ServerOptions::save(boost::property_tree::ptree& pt) const
 {
   pt.put("hashaid.charset", this->get<std::string>("charset"));
   pt.put("hashaid.length", this->get<unsigned int>("length"));
   if (this->is_set("salt"))
     pt.put("hashaid.salt", this->get<std::string>("salt"));
   pt.put("hashaid.type", this->get<std::string>("type"));
 }
 void ValueDataField::serialize(boost::property_tree::ptree& node)
 {
     DataField::serialize(node);
     node.put("IsFixedField", d_isFixedField);
     node.put("IsIdentifier", d_isIdentifier);
     node.put("DataRepresentation", d_dataRepresentation->getType());
     node.put("DataType", d_dataType->getType());
     node.put("Length", d_length);
 }
Example #6
0
void
OpusComponent::save( boost::property_tree::ptree& pt )
{
    pt.put( "opus.eads.component." + M_name + ".name", M_name );
    pt.put( "opus.eads.component." + M_name + ".k", M_k );
    pt.put( "opus.eads.component." + M_name + ".rhoC", M_rhoC );
    pt.put( "opus.eads.component." + M_name + ".Q", M_Q );
    pt.put( "opus.eads.component." + M_name + ".h", M_h );
    pt.put( "opus.eads.component." + M_name + ".e", M_e );
}
void ISO7816ReaderUnitConfiguration::serialize(boost::property_tree::ptree& node)
{
    node.put("SAMType", d_sam_type);
    node.put("SAMReaderName", d_sam_reader_name);
    boost::property_tree::ptree knode;
    knode.put("KeyNo", d_keyno_unlock);
    if (d_sam_key_unlock)
    {
        d_sam_key_unlock->serialize(knode);
    }
    node.add_child("SAMKey", knode);
}
void SortedAlleleAlphabet2::logState( boost::property_tree::ptree & log ) {
    std::string key = "symbol_database";
    log.put( key + ".count", m_db.size() );
    log.put( key + ".active_count", m_db.size() - m_free_list.count());
    log.put( key + ".symbol_per_block", bitset_type::bits_per_block );
    log.put( key + ".max_block_per_region", (m_db.size() / bitset_type::bits_per_block) + 1 );

    std::ostringstream oss;

    for( unsigned int i = 0; i < m_db.size(); ++i ) {
        if( !m_free_list[i] ) {
            oss.str("");
            oss.clear();
            oss << ".symbol." << i;
            log.put( key + oss.str(), m_db[i].first );
        }
    }

    variant_db_t::iterator first = m_db.begin();

    /*
        free_ranges::iterator it = m_free_ranges.begin();
        boost::property_tree::ptree fr;
        while( it != m_free_ranges.end() ) {
            boost::property_tree::ptree p, q, r, s, t;
            p.put("", it->first.lower() );
            q.put("", it->first.upper() );
            r.push_back( std::make_pair("", p));
            r.push_back( std::make_pair("", q));

            index_interval_type::iterator idx_it = it->second.begin();
            while( idx_it != it->second.end() ) {
                boost::property_tree::ptree _p, _q, _s;
                _p.put("", idx_it->lower() );
                _q.put("", idx_it->upper() );

                _s.push_back( std::make_pair( "", _p ) );
                _s.push_back( std::make_pair( "", _q ) );
                s.push_back( std::make_pair("", _s));
                ++idx_it;
            }

            t.push_back( std::make_pair( "", r ) );
            t.push_back( std::make_pair( "", s ) );
            fr.push_back( std::make_pair( "", t ));
            ++it;
        }

        log.add_child( key + ".free_ranges", fr );
    */
}
 void ISO7816ReaderUnitConfiguration::serialize(boost::property_tree::ptree& node)
 {
     node.put("SAMType", d_sam_type);
     node.put("SAMReaderName", d_sam_reader_name);
     boost::property_tree::ptree knode;
     knode.put("KeyNo", d_keyno_unlock);
     if (d_sam_key_unlock)
     {
         d_sam_key_unlock->serialize(knode);
     }
     node.add_child("SAMKey", knode);
     node.put("CheckSAMReaderIsAvailable", d_check_sam_reader_available);
     node.put("AutoConnectToSAMReader", d_auto_connect_sam_reader);
 }
Example #10
0
void CTopoRequirement::saveToPropertyTree(boost::property_tree::ptree& _pt)
{
    try
    {
        std::string tag("topology.declrequirement.<xmlattr>");
        _pt.put(tag + ".name", getName());
        _pt.put(tag + ".value", getValue());
        _pt.put(tag + ".type", RequirementTypeToTag(getRequirementType()));
    }
    catch (exception& error) // ptree_error, runtime_error
    {
        throw logic_error("Unable to save requirement " + getName() + " error:" + error.what());
    }
}
Example #11
0
 void Key::serialize(boost::property_tree::ptree& node)
 {
     node.put("<xmlattr>.keyStorageType", d_key_storage->getType());
     if (d_key_diversification)
     {
         boost::property_tree::ptree newnode;
         newnode.put("<xmlattr>.keyDiversificationType", d_key_diversification->getType());
         d_key_diversification->serialize(newnode);
         node.add_child("KeyDiversification", newnode);
     }
     node.put("IsCiphered", (d_storeCipheredData && !d_isEmpty));
     cipherKeyData(node);
     d_key_storage->serialize(node);
 }
Example #12
0
 void ReaderUnit::serialize(boost::property_tree::ptree& node)
 {
     node.put("<xmlattr>.type", getReaderProvider()->getRPType());
     d_readerUnitConfig->serialize(node);
     if (getDataTransport())
     {
         node.put("TransportType", getDataTransport()->getTransportType());
         getDataTransport()->serialize(node);
     }
     else
     {
         node.put("TransportType", "");
     }
 }
    void recordResults( boost::property_tree::ptree & log ) {

        typedef ac::accumulator_set< size_type, ac::stats< ac::tag::min, ac::tag::mean, ac::tag::max, ac::tag::variance, ac::tag::median, ac::tag::count > > accumulator_t;

        accumulator_t   col_accum, row_accum;

        boost::property_tree::ptree dist, lfreq;

        // maximum frequency for an allele is bounded by the number of sequences (rows) in the population
        std::vector< size_type > freq( m_indices.size(), 0 );

        // evaluate allele (column) statistics
        size_type i = 0;
        while( i < m_column_margin_size ) {
            size_type v = m_column_margin[i++];
            clotho::utility::add_value_array( dist, v );
            col_accum( v );
            freq[v]++;
        }


        clotho::utility::add_value_array(lfreq, freq.begin(), freq.end() );

        log.put_child( "distribution", dist );
        log.put_child( "frequency_distribution", lfreq );

        log.put( "stats.sequences_per_allele.min", ac::min( col_accum ) );
        log.put( "stats.sequences_per_allele.max", ac::max( col_accum ) );
        log.put( "stats.sequences_per_allele.mean", ac::mean( col_accum ) );
        log.put( "stats.sequences_per_allele.median", ac::median( col_accum ) );
        log.put( "stats.sequences_per_allele.variance", ac::variance( col_accum ) );
        log.put( "stats.sequences_per_allele.total", ac::count(col_accum) );

        // evaluate sequence (row) statistics
        i = 0;
        while( i < m_row_margin_size ) {
            if( m_indices.test(i) ) {
                row_accum( m_row_margin[ i ] );
            }
            ++i;
        }

        log.put( "stats.alleles_per_sequence.min", ac::min( row_accum ) );
        log.put( "stats.alleles_per_sequence.max", ac::max( row_accum ) );
        log.put( "stats.alleles_per_sequence.mean", ac::mean( row_accum ) );
        log.put( "stats.alleles_per_sequence.median", ac::median( row_accum ) );
        log.put( "stats.alleles_per_sequence.variance", ac::variance( row_accum ) );
        log.put( "stats.alleles_per_sequence.total", ac::count(row_accum) );
    }
Example #14
0
void rai_daemon::daemon_config::serialize_json (boost::property_tree::ptree & tree_a)
{
	tree_a.put ("version", "2");
	tree_a.put ("rpc_enable", rpc_enable);
	boost::property_tree::ptree rpc_l;
	rpc.serialize_json (rpc_l);
	tree_a.add_child ("rpc", rpc_l);
	boost::property_tree::ptree node_l;
	node.serialize_json (node_l);
	tree_a.add_child ("node", node_l);
	tree_a.put ("opencl_enable", opencl_enable);
	boost::property_tree::ptree opencl_l;
	opencl.serialize_json (opencl_l);
	tree_a.add_child ("opencl", opencl_l);
}
Example #15
0
void CContentParser::ParseItem(std::string& sSource, boost::property_tree::ptree& xmlResult)
{
    static boost::regex expression(Settings::Instance().GetItemExpression());

    // Контейнер для значений
    std::vector< std::string > vecRawValues;

    if (!boost::regex_split(std::back_inserter(vecRawValues), sSource, expression))
        throw std::runtime_error("Failed to parse item.");

    for (unsigned int i = 0; i < vecRawValues.size(); ++i)
    {
        std::string sName = ms_pNames[i];
        if (sName.empty())
            continue;

        std::string& sToken = vecRawValues[i];
        if (!sToken.empty())
        {
            if (sName == "phone")
                ParsePhone(sToken);
            else
            {
                boost::algorithm::trim(sToken);
                if (sToken[sToken.size() - 1] == ',')
                    boost::algorithm::erase_last(sToken, ",");
            }

            xmlResult.put(sName, sToken);
        }
    }
}
void updateOnly(boost::property_tree::ptree &dest, bool ignoreEmptyUpdates, const boost::property_tree::ptree::path_type &childPath, const boost::property_tree::ptree &child) {
    if(ignoreEmptyUpdates && (child.data().empty() || child.data().find_first_not_of(" \n\t\r") == std::string::npos)) return;
    if(!dest.get_optional<std::string>(childPath)) {
        throw PropertyTree::KeyNotFoundException(std::string("Could not find the destination '") + childPath.dump() + "' to update with '" + child.data() + "'.");
    }
    dest.put(childPath, child.data());
}
Example #17
0
bool CSaveGameController::saveXMLTree(boost::property_tree::ptree &pt)
{
    // Write the xml-file
    using boost::property_tree::ptree;
#if BOOST_VERSION >= 105600
    boost::property_tree::xml_writer_settings<std::string> settings('\t', 1);
#else
    boost::property_tree::xml_writer_settings<char> settings('\t', 1);
#endif

    // The savegame internal name
    pt.put("GameState.<xmlattr>.name", m_statename);

    std::ofstream StateFile;
    bool open = OpenGameFileW( StateFile, m_stateXMLfilename, std::ofstream::binary );

    if (!open)
    {
        std::string fullpath = GetFullFileName(m_stateXMLfilename);
        gLogging.textOut("Error saving \"" + fullpath + "\". Please check the status of that path.\n" );
        return false;
    }

    write_xml( StateFile, pt, settings );

    return true;
}
static std::string
loadFile (boost::property_tree::ptree &config,
          const boost::filesystem::path &file)
{
  boost::filesystem::path extension = file.extension();
  boost::filesystem::path extension2 = file.stem().extension();
  std::string fileName = file.filename().string();
  boost::property_tree::ptree readConfig;

  if (extension2.string() == ".conf") {
    if (extension.string() == ".json") {
      boost::property_tree::read_json (file.string(), readConfig);
    } else if (extension.string() == ".info") {
      boost::property_tree::read_info (file.string(), readConfig);
    } else if (extension.string() == ".ini") {
      boost::property_tree::read_ini (file.string(), readConfig);
    } else if (extension.string() == ".xml") {
      boost::property_tree::read_xml (file.string(), readConfig);
    } else {
      throw ParseException ("Unknonw file format");
    }
  } else {
    throw ParseException ("Unknonw file format");
  }

  mergePropertyTrees (config, readConfig);

  config.put ("configPath", file.parent_path().string() );

  fileName = fileName.substr (0, fileName.size() - extension.string().size() );
  fileName = fileName.substr (0, fileName.size() - extension2.string().size() );

  return fileName;
}
Example #19
0
/*******************************************************************************
Function: nmbls::simpletemplate::enterfor
Description: Whilst rendering parse a for section, it will bomb out after one
itteration if no end is found. For command format
for i = lowervariable:uppervariable
for i = lowervariable:increby:uppervariable
Date: 15.12.2017
Author: Nick Knight
*******************************************************************************/
nmbls::simpletemplatechunklist::iterator nmbls::simpletemplate::enterfor( boost::property_tree::ptree &tree, simpletemplatechunklist::iterator start, std::string &out )
{
  std::string command = boost::algorithm::join( start->command, "" );
  std::vector < std::string > parts;

  boost::split( parts, command, boost::is_any_of( "=:" ) );

  int incrby = 1;
  int endi = 0;
  if( 4 == parts.size() )
  {
    incrby = std::stoi( parts[ 2 ] );
    endi = std::stoi( parts[ 3 ] );
  }
  else
  {
    endi = std::stoi( parts[ 2 ] );
  }

  start++;
  simpletemplatechunklist::iterator it;
  for ( int starti = std::stoi( parts[ 1 ] ); starti <= endi; starti += incrby  )
  {
    tree.put( parts[ 0 ], starti );
    it = this->render( tree, start, out );
  }

  return it;
}
Example #20
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;
}
Example #21
0
void PipelineWriter::write_option_ptree(boost::property_tree::ptree& tree, const Options& opts)
{
    boost::property_tree::ptree m_tree = opts.toPTree();

    boost::property_tree::ptree::const_iterator iter = m_tree.begin();
    while (iter != m_tree.end())
    {
        if (iter->first != "Option")
            throw pdal_error("malformed Options ptree");
        const boost::property_tree::ptree& optionTree = iter->second;
        
        // we want to create this:
        //      ...
        //      <Option name="file">foo.las</Option>
        //      ...

        const std::string& name = optionTree.get_child("Name").get_value<std::string>();
        const std::string& value = optionTree.get_child("Value").get_value<std::string>();
        
        boost::property_tree::ptree& subtree = tree.put("Option", value);
        subtree.put("<xmlattr>.name", name);

        ++iter;
    }

    return;
}
Example #22
0
void Set::convert_colour( bp::ptree& ptree , const std::string& name )
{
	auto value = ptree.get_optional<std::string>(name);
	if( !value ) return;
	auto out = convert_colour( *value );
	ptree.put( name , out );
}
Example #23
0
void Set::convert_float( bp::ptree& ptree , const std::string& name )
{
	auto value = ptree.get_optional<std::string>(name);
	if( !value ) return;
	std::replace( value->begin() , value->end() , ',' , '.' );
	ptree.put( name , value );
}
Example #24
0
void
CVarPlatform::
serialize(boost::property_tree::ptree &node)
{
    auto &posNode = node.put("target", "");
    posNode.put("<xmlattr>.x", target.x);
    posNode.put("<xmlattr>.y", target.y);
}
Example #25
0
void Set::upgrade_option( bp::ptree& ptree , const std::string& prev , const std::string& curr )
{
	auto opt = ptree.get_optional<std::string>( prev );
	if( opt ) {
		ptree.put( curr ,*opt);
		ptree.erase( prev );
	}
}
void write_sequence_section(boost::property_tree::ptree& data, 
                            const std::string& key,
                            const std::vector<T>& values) {
  for (size_t i = 0; i < values.size(); ++i) {
    // make the 4 digit suffix
    std::stringstream strm;
    strm.fill('0'); strm.width(4); strm << i;
    data.put(key + "." + strm.str(), values[i]);
  }
}
Example #27
0
	void serialize_json (boost::property_tree::ptree & tree_a)
	{
		std::string wallet_string;
		wallet.encode_hex (wallet_string);
		tree_a.put ("version", "4");
		tree_a.put ("wallet", wallet_string);
		tree_a.put ("account", account.to_account ());
		boost::property_tree::ptree node_l;
		node.serialize_json (node_l);
		tree_a.add_child ("node", node_l);
		boost::property_tree::ptree rpc_l;
		rpc.serialize_json (rpc_l);
		tree_a.add_child ("rpc", rpc_l);
		tree_a.put ("rpc_enable", rpc_enable);
		tree_a.put ("opencl_enable", opencl_enable);
		boost::property_tree::ptree opencl_l;
		opencl.serialize_json (opencl_l);
		tree_a.add_child ("opencl", opencl_l);
	}
void URLConfig::ModifyCfg(bool is_https, uint16_t port)
{
	std::stringstream ss;

	m_is_https = is_https;
	m_protocol = is_https ? HTTPS : HTTP;
	m_port = port;

	namespace PT = boost::property_tree;
	try //Parse the configuration file
	{
		PT::ptree root;
		root.put("protocol", m_protocol);
		root.put("host", m_host);
		root.put("port", m_port);
		root.put("main_path", m_main_path);
		root.put("login_path", m_login_path);
		root.put("logout_path", m_logout_path);
		root.put("menu_auth_path", m_menu_auth_path);
		root.put("user_msg_count_path", m_user_msg_count_path);
		root.put("user_msg_path", m_user_msg_path);
		root.put("modify_pwd_path", m_modify_pwd_path);
		PT::write_json(ss, root, true);
	}
	catch (...) // Catch the exception in order for logging.
	{
		LOG_ERROR(L"组Json字符流时出错,请检查!");
		throw; // Don't swallow the exception!
	}

	try
	{
		AES_CBC::EncryptToFile(ss.str(), CIPHER_TEXT_FILE);

#ifdef _DEBUG // Save to plain text file under debug mode.
		std::ofstream ofs(PLAIN_TEXT_FILE, std::ios_base::out | std::ios_base::binary);
		if (!ofs.is_open())
			throw std::exception(("打开文件" + PLAIN_TEXT_FILE + "失败!").c_str());
		ofs << ss.str();
		ofs.close();
#endif
	}
	catch (std::exception& ex)
	{
		LOG_ERROR(gbk_2_wstr(ex.what()));
	}
}
Example #29
0
void CompPathMove::writeToPropertyTree(boost::property_tree::ptree& propTree) const
{
    if (m_pathId != "")
        propTree.put("path_id", m_pathId);
    if (m_repeat == true)
        propTree.put("repeat", m_repeat);
    if (m_resetAngle == true)
        propTree.put("resetAngle", m_resetAngle);
    //propTree.put("velocity", m_velocity);

    foreach(const PathMovePoint& p, m_points)
    {
        ptree pointPropTree;
        switch (p.mode)
        {
        case PathMovePoint::Uniform:
            pointPropTree.add(cMode, cModeUniform);
            if (p.time != 0.0f)
                pointPropTree.add(cTime, p.time);
            else if (p.linVel != 0.0f)
                pointPropTree.add(cLinVel, p.linVel);
            else
                pointPropTree.add(cAngVel, p.angVel);
            break;
        case PathMovePoint::Accelerated:
            pointPropTree.add(cMode, cModeAccelerated);
            if (p.linAccel != 0.0f)
            {
                pointPropTree.add(cLinAccel, p.linAccel);
                if (p.topLinVel != 0.0f)
                    pointPropTree.add(cTopLinVel, p.topLinVel);
            }
            else
            {
                pointPropTree.add(cAngAccel, p.angAccel);
                if (p.topAngVel != 0.0f)
                    pointPropTree.add(cTopAngVel, p.topAngVel);
            }
            break;
        }
        propTree.add_child(cPoint, pointPropTree);
    }
Example #30
0
void ConstraintList::serialize(boost::property_tree::ptree& tree) const {
  boost::property_tree::ptree expressions;
  for (const auto& constraint : constraints_) {
    boost::property_tree::ptree child;
    child.put("op", constraint.op);
    child.put("expr", constraint.expr);
    expressions.push_back(std::make_pair("", child));
  }
  tree.add_child("list", expressions);
  tree.put("affinity", columnTypeName(affinity));
}