示例#1
0
GenericReply::Ptr TgTypeParser::parseJsonAndGetGenericReply(const boost::property_tree::ptree& data) const {
	if (data.find("force_reply") != data.not_found()) {
		return static_pointer_cast<GenericReply>(parseJsonAndGetForceReply(data));
	} else if (data.find("hide_keyboard") != data.not_found()) {
		return static_pointer_cast<GenericReply>(parseJsonAndGetReplyKeyboardHide(data));
	} else {
		return static_pointer_cast<GenericReply>(parseJsonAndGetReplyKeyboardMarkup(data));
	}
}
示例#2
0
void Settings::merge(const boost::property_tree::ptree& from,
                     boost::property_tree::ptree& to,
                     bool overwrite)
{
    // Is this a single value or a subtree?
    if (!from.data().empty()) {
        // Single value
        if (overwrite || to.data().empty()) {
            to.put_value(from.data());
        }
        return;
    }

    // Subtree
    for (const auto& fromEntry : from) {
        // Does the key exist in the destination?
        auto toIt = to.find(fromEntry.first);
        if (toIt == to.not_found()) {
            ptree::ptree child;

            // Recurse into the new child
            merge(fromEntry.second, child, overwrite);

            // Create a path object because ptree uses '.' as a path delimiter
            // when strings are used
            ptree::ptree::path_type treePath = createPath(fromEntry.first);
            to.add_child(treePath, child);
        } else {
            // Recurse into the subtrees
            merge(fromEntry.second, toIt->second, overwrite);
        }
    }
}
示例#3
0
void json_hydrator::read_module_path(const boost::property_tree::ptree& pt,
    model& m, qname& qn) const {
    const auto i(pt.find(module_path_key));
    if (i == pt.not_found())
        return;

    for (auto j(i->second.begin()); j != i->second.end(); ++j) {
        const auto module_name(j->second.get_value<std::string>());
        qn.module_path().push_back(module_name);

        qname module_qn;
        module_qn.simple_name(module_name);
        module_qn.model_name(model_name(m));
        auto mp(qn.module_path());
        mp.pop_back();
        module_qn.module_path(mp);

        const auto i(m.modules().find(module_qn));
        if (i == m.modules().end()) {
            module mod;
            mod.name(module_qn);
            mod.origin_type(m.origin_type());
            mod.generation_type(m.generation_type());
            m.modules().insert(std::make_pair(module_qn, mod));
        }
    }
}
示例#4
0
void NetworkManagerHandler::setSettings(const boost::property_tree::ptree &requestPt)
{
    if (requestPt.find("type") != requestPt.not_found())
    {
        NetworkInterfaces::InterfaceSettings settings;
        settings.interface = _interfaceName;
        settings.type = requestPt.get<std::string>("type");
        settings.autoConnect = requestPt.get<bool>("auto", true);

        for (boost::property_tree::ptree::const_iterator it = requestPt.begin(); it != requestPt.end(); ++it)
        {
            if (it->first != "type")
                settings.arguments[it->first] = it->second.get_value<std::string>();
        }

        NetworkInterfaces::writeInterfaceSettings(kNetworkInterfacesFile, settings);

        if (_interfaceName != qpcrApp.wirelessManager()->interfaceName())
        {
            NetworkInterfaces::ifdown(_interfaceName);
            NetworkInterfaces::ifup(_interfaceName);
        }
        else
            wifiConnect();
    }
    else
    {
        setStatus(Poco::Net::HTTPResponse::HTTP_BAD_REQUEST);
        setErrorString("type must be set");
    }
}
示例#5
0
dynamic::object json_hydrator::
create_dynamic_extensions(const boost::property_tree::ptree& pt,
    const dynamic::scope_types st) const {
    const auto i(pt.find(extensions_key));
    if (i == pt.not_found())
        return dynamic::object();

    dynamic::object r;
    std::list<std::pair<std::string, std::string> > kvps;
    for (auto j(i->second.begin()); j != i->second.end(); ++j) {
        const auto field_name(j->first);
        const auto field_value(j->second.get_value<std::string>());
        kvps.push_back(std::make_pair(field_name, field_value));
    }
    return dynamic_workflow_.execute(st, kvps);
}
示例#6
0
	PTreeConfigSettings::ParseResult				PTreeConfigSettings::Parse( const boost::property_tree::ptree&		sectionToParse )
	{
		for( const std::string& requiredField : m_requiredFields )
		{
			if( sectionToParse.find( requiredField ) == sectionToParse.not_found() )
			{
				return( ParseResult::Failure( ErrorCodes::MISSING_REQUIRED_FIELD, std::string( "Missing Required Field: " ) + requiredField ));
			}
		}

		for( const boost::property_tree::ptree::value_type& field : sectionToParse )
		{
			SetField( field.first, field.second.get_value<std::string>() );
		}

		return( ParseResult::Success() );
	}
std::shared_ptr<SchemaType> XSDSchemaParser::getSchemaType(const pt::ptree &typeTree, bool nameRequired)
{
    std::string typeName = getXSDAttributeValue(typeTree, "<xmlattr>.name", nameRequired, "");

    std::shared_ptr<SchemaType> pCfgType = std::make_shared<SchemaType>(typeName);
    std::shared_ptr<SchemaTypeLimits> pLimits;
    auto restriction = typeTree.find("xs:restriction");
    if (restriction != typeTree.not_found())
    {
        std::string baseType = getXSDAttributeValue(restriction->second, "<xmlattr>.base");
        std::shared_ptr<SchemaType> pType = std::make_shared<SchemaType>(*(m_pSchemaItem->getSchemaValueType(baseType)));

        pLimits = pType->getLimits();

        if (!restriction->second.empty())
        {
            pt::ptree restrictTree = restriction->second.get_child("", pt::ptree());
            if (std::dynamic_pointer_cast<SchemaTypeIntegerLimits>(pLimits) != nullptr)
            {
                std::shared_ptr<SchemaTypeIntegerLimits> pBaseIntLimits = std::dynamic_pointer_cast<SchemaTypeIntegerLimits>(pLimits);
                std::shared_ptr<SchemaTypeIntegerLimits> pIntLimits = std::make_shared<SchemaTypeIntegerLimits>(*pBaseIntLimits);
                parseIntegerTypeLimits(restrictTree, pIntLimits);
                pLimits = pIntLimits;
            }
            else if (std::dynamic_pointer_cast<SchemaTypeStringLimits>(pLimits) != nullptr)
            {
                std::shared_ptr<SchemaTypeStringLimits> pBaseStringimits = std::dynamic_pointer_cast<SchemaTypeStringLimits>(pLimits);
                std::shared_ptr<SchemaTypeStringLimits> pStringimits = std::make_shared<SchemaTypeStringLimits>(*pBaseStringimits);
                parseStringTypeLimits(restrictTree, pStringimits);
                pLimits = pStringimits;
            }
            else
            {
                std::string msg = "Unsupported base type(" + baseType + ")";
                throw(ParseException(msg));
            }
        }
    }

    pCfgType->setLimits(pLimits);
    return pCfgType;
}
示例#8
0
	void SceneObject::read(boost::property_tree::ptree pt){
		using boost::property_tree::ptree;

		if(pt.find("body") != pt.not_found())
			body.read(pt.get_child("body"));
	}
示例#9
0
void hydrator::read_element(const boost::property_tree::ptree& pt,
    yarn::intermediate_model& m) const {

    yarn::name_builder b;
    const auto in_global_module(pt.get(in_global_module_key, false));
    if (!in_global_module)
        b.model_name(m.name().location());

    const auto simple_name_value(pt.get<std::string>(simple_name_key));
    b.simple_name(simple_name_value);

    const auto i(pt.find(internal_modules_key));
    if (i != pt.not_found()) {
        std::list<std::string> ipp;
        for (auto& item : pt.get_child(internal_modules_key))
            ipp.push_back(item.second.get_value<std::string>());

        if (!ipp.empty())
            b.internal_modules(ipp);
        else {
            BOOST_LOG_SEV(lg, debug) << "Ignoring empty internal module path. "
                                     << "Type: " << simple_name_value;
        }
    }

    yarn::name n(b.build());
    const auto documentation(pt.get_optional<std::string>(documentation_key));

    const auto lambda([&](yarn::element& e) {
            BOOST_LOG_SEV(lg, debug) << "Processing element: " << n.qualified();
            e.name(n);
            e.origin_type(m.origin_type());
            e.generation_type(m.generation_type());
            e.in_global_module(in_global_module);

            if (documentation)
                e.documentation(*documentation);

            const auto scope(dynamic::scope_types::entity);
            e.extensions(create_dynamic_extensions(pt, scope));
        });

    const auto meta_type_value(pt.get<std::string>(meta_type_key));
    if (meta_type_value == meta_type_object_value) {
        yarn::object o;
        lambda(o);

        const auto ot(pt.get_optional<std::string>(object_type_key));
        o.object_type(to_object_type(ot));
        m.objects().insert(std::make_pair(n.qualified(), o));
    } else if (meta_type_value == meta_type_primitive_value) {
        yarn::primitive p;
        const auto dit(pt.get(is_default_enumeration_type_key, false));
        p.is_default_enumeration_type(dit);
        lambda(p);
        m.primitives().insert(std::make_pair(n.qualified(), p));
    }
    else {
        BOOST_LOG_SEV(lg, error) << invalid_meta_type << meta_type_value;
        BOOST_THROW_EXCEPTION(
            hydration_error(invalid_meta_type + meta_type_value));
    }
}
示例#10
0
static boost::property_tree::ptree ptree_to_xml_(const boost::property_tree::ptree& ptree)
{
    boost::property_tree::ptree out= boost::property_tree::ptree();
    //copy all children
    for (boost::property_tree::ptree::const_assoc_iterator i=ptree.ordered_begin(); i != ptree.not_found(); i++ )
    {
        if(i->second.find("") != i->second.not_found())
        {
            //colapse array
            for (boost::property_tree::ptree::const_assoc_iterator j=i->second.ordered_begin(); j != i->second.not_found(); j++ )
            {
                out.add_child(i->first, ptree_to_xml_(j->second));
            }
        }
        else
            out.add_child(i->first, ptree_to_xml_(i->second));
    }
    out.put_value(ptree.get_value<std::string>());
    return out;
}