void PipelineReaderXML::parseElement_Pipeline(const ptree& tree)
{
    Stage *stage = NULL;
    Stage *writer = NULL;

    map_t attrs;
    collect_attributes(attrs, tree);

    std::string version = "";
    if (attrs.count("version"))
        version = attrs["version"];
    if (version != "1.0")
        throw pdal_error("PipelineReaderXML: unsupported pipeline xml version");

    for (auto iter = tree.begin(); iter != tree.end(); ++iter)
    {
        const std::string& name = iter->first;
        const ptree subtree = iter->second;

        if (name == "Reader" || name == "Filter" )
        {
            stage = parseElement_anystage(name, subtree);
        }
        else if (name == "Writer")
        {
            writer = parseElement_Writer(subtree);
        }
        else if (name == "<xmlattr>")
        {
            // ignore it, already parsed
        }
        else
        {
            throw pdal_error("PipelineReaderXML: xml reader invalid child of "
                "ReaderPipeline element");
        }
    }

    if (writer && stage)
    {
        throw pdal_error("PipelineReaderXML: extra nodes at front of "
            "writer pipeline");
    }
}
Example #2
0
///////////////////////////////////////////////////////////////////////////////
/// @fn CMessage::CMessage
/// @description From a ptree, creates a CMessage
/// @pre None
/// @post The CMessage has been initalized from a ptree.
///////////////////////////////////////////////////////////////////////////////
CMessage::CMessage( const ptree &pt )
{
    Logger.Trace << __PRETTY_FUNCTION__ << std::endl;
    try
    {
        std::string time_tmp;
        // Get the source host's ID and store it in the m_src variable.
        // An exception is thrown if "message.source" does not exist.
        m_srcUUID = pt.get< std::string >("message.source");
        m_remotehost.hostname = pt.get< std::string >("message.hostname");
        m_remotehost.port = pt.get< std::string >("message.port");
        m_sequenceno = pt.get< unsigned int >("message.sequenceno");
        m_protocol = pt.get< std::string >("message.protocol");
        m_sendtime = pt.get< boost::posix_time::ptime >("message.sendtime");
        m_handler = pt.get< std::string >("message.handler");
        try
        {
           m_expiretime = pt.get< boost::posix_time::ptime >("message.expiretime");
        }
        catch( boost::property_tree::ptree_error &e )
        {
            m_expiretime = boost::posix_time::ptime();
        }
        if(HasExpireTime())
        {
            m_never_expires = true;
        }
        m_status = static_cast< StatusType >
            (pt.get< unsigned int >("message.status"));

        // Iterate over the "message.modules" section and store all found
        // in the m_modules set. These indicate sub-ptrees that algorithm
        // modules have added.
        m_submessages = pt.get_child("message.submessages");
        m_properties = pt.get_child("message.properties");

    }
    catch( boost::property_tree::ptree_error &e )
    {
         Logger.Error << "Invalid CMessage ptree format:"
                 << e.what() << std::endl;
         throw;
    }
}
Example #3
0
  void process_pde_text(PdeTextP text, ptree& node) {
    PdfTextState ts;

    switch (text->GetType())
    {
    case kPdeText:
    {
      node.put("type", "text_paragraph");
      std::wstring s;
      s.resize(text->GetText(nullptr, 0));
      text->GetText((wchar_t*)s.c_str(), s.size());
      node.put("text", w2utf8(s.c_str()));
      text->GetTextState(&ts);
      auto num_lines = text->GetNumTextLines();
      for (auto i = 0; i < num_lines; i++) {
        ptree line_node;
        PdeTextLineP text_line = text->GetTextLine(i);
        process_pde_element((PdeElementP)text_line, line_node);
        node.add_child("element", line_node);
      }
    }
    break;
    case kPdeTextLine:
    {
      PdeTextLineP text_line = (PdeTextLine*)text;
      node.put("type", "text_line");
      std::wstring s;
      s.resize(text_line->GetText(nullptr, 0));
      text_line->GetText((wchar_t*)s.c_str(), s.size());
      node.put("text", w2utf8(s.c_str()));
      text_line->GetTextState(&ts);
      auto num_word = text_line->GetNumWords();
      for (auto i = 0; i < num_word; i++) {
        ptree word_node;
        PdeWordP text_word = text_line->GetWord(i);
        process_pde_element((PdeElementP)text_word, word_node);
        node.add_child("element", word_node);
      }
    }
    break;
    case kPdeWord:
    {
      PdeWordP word = (PdeWord*)text;
      node.put("type", "text_word");
      std::wstring s;
      s.resize(word->GetText(nullptr, 0));
      word->GetText((wchar_t*)s.c_str(), s.size());
      node.put("text", w2utf8(s.c_str()));
      word->GetTextState(&ts);
    }
    break;
    }
    process_pdf_text_state(ts, node);
  }
Example #4
0
		gradient::gradient(element* doc, const ptree& pt)
			: core_attribs(pt),
			coord_system_(GradientCoordSystem::OBJECT_BOUNDING_BOX),
			spread_(GradientSpreadMethod::PAD)
		{
			// Process attributes
			auto attributes = pt.get_child_optional("<xmlattr>");
			if(attributes) {
				auto xlink_href = attributes->get_child_optional("xlink:xref");
				auto transforms = attributes->get_child_optional("gradientTransforms");
				auto units = attributes->get_child_optional("gradientUnits");
				auto spread = attributes->get_child_optional("spreadMethod");

				if(transforms) {
					transforms_ = transform::factory(transforms->data());
				}
				if(xlink_href) {
					xlink_href_ = xlink_href->data();
				}
				if(units) {
					std::string csystem = units->data();
					if(csystem == "userSpaceOnUse") {
						coord_system_ = GradientCoordSystem::USERSPACE_ON_USE;
					} else if(csystem =="objectBoundingBox") {
						coord_system_ = GradientCoordSystem::OBJECT_BOUNDING_BOX;
					} else {
						ASSERT_LOG(false, "Unrecognised 'gradientUnits' value: " << csystem);
					}
				}
				if(spread) {
					std::string spread_val = units->data();
					if(spread_val == "pad") {
						spread_ = GradientSpreadMethod::PAD;
					} else if(spread_val =="reflect") {
						spread_ = GradientSpreadMethod::REFLECT;
					} else if(spread_val =="repeat") {
						spread_ = GradientSpreadMethod::REPEAT;
					} else {
						ASSERT_LOG(false, "Unrecognised 'spreadMethod' value: " << spread_val);
					}
				}

				// Process child elements
				for(auto& v : pt) {
					if(v.first == "stop") {
						stops_.emplace_back(new gradient_stop(doc, v.second));
					} else if(v.first == "<xmlattr>") {
						// ignore
					} else if(v.first == "<xmlcomment>") {
						// ignore
					} else {
						ASSERT_LOG(false, "unexpected child element in gradient stop list: " << v.first);
					}
				}
			}
		}
Example #5
0
    bool ConfigTree::paramFromPtree(ptree fromPtree, ConfigParameter &toParam)
    {
        CONFIGSYS_DEBUG_CALLS;

        std::string typStr = fromPtree.get<std::string>("type");
        value_type vt = stringToValueType(typStr);
        
        toParam = ConfigParameter(vt);

        toParam.setDescription(fromPtree.get("desc", ""));

        std::string modStr = fromPtree.get("modified", "false");
        toParam.setModified(modStr.compare("true") == 0);

        std::string lockStr = fromPtree.get("locked", "false");
        toParam.setLocked(lockStr.compare("true") == 0);

        return addPtreeValueandRangeToParam(fromPtree, toParam);
    }
Example #6
0
void CompShapePolygon::writeToPropertyTree(ptree& propTree) const
{
    for ( size_t i = 0; i < getVertexCount(); ++i )
    {
        ptree vertexPropTree;
        vertexPropTree.add("x", m_vertices[i].x);
        vertexPropTree.add("y", m_vertices[i].y);
        propTree.add_child("polygon.vertex", vertexPropTree);
    }
}
Example #7
0
void CompShapePolygon::loadFromPropertyTree(const ptree& propTree)
{
    foreach(const ptree::value_type &v, propTree.get_child("polygon"))
    {
        const ptree& vertex = v.second;
        float x = vertex.get<float>("x");
        float y = vertex.get<float>("y");
        m_vertices.push_back( Vector2D(x, y) );
    }
}
Example #8
0
File: api.cpp Project: cppan/cppan
ptree api_call(const Remote &r, const String &api, ptree request)
{
    request.put("auth.user", r.user);
    request.put("auth.token", r.token);

    HttpRequest req = httpSettings;
    req.type = HttpRequest::POST;
    req.url = r.url + "/api/" + api;
    req.data = ptree2string(request);
    auto resp = url_request(req);
    auto ret = string2ptree(resp.response);
    if (resp.http_code != 200)
    {
        auto e = ret.get<String>("error", "");
        throw std::runtime_error(e);
    }

    return string2ptree(resp.response);
}
Example #9
0
template<typename T> static void
unparseElements(ptree& tree, const std::string& key, const T& elements)
{
    if (elements.size()) {
        ptree list;
        for (const auto& elem : elements)
           list.push_back({"", unparse(elem)});
        tree.add_child(key, list);
    }
}
Example #10
0
	boost::shared_ptr<T> createSprite(ptree params = ptree())
	{
		boost::shared_ptr<T> newSprite(new T(graphicsMgr));

		if(!params.empty())
			newSprite->set(params);

		this->addSprite(newSprite);
		return newSprite;
	};
void MultiMatcher::writeSelf(ptree& writeTo) const {

    writeTo.put(OPERATE_MODE_KEY,OPERATE_MODE_MAP_NAME[m_operateMode]);

    int index=0;

    ptree values;

    for(auto &child : m_values){
        ptree childTree;

        write(child,childTree);

        values.add_child(MATCHER_KEY,childTree);
    }

    writeTo.put_child(VALUES_KEY,values);

}
Example #12
0
void scxml_parser::parse_state(const ptree &pt, const boost::shared_ptr<state> &parent)
{
	try {
		using namespace boost::algorithm;
		const ptree &xmlattr = pt.get_child("<xmlattr>");
		boost::shared_ptr<state> st = boost::make_shared<state>();
		st->id = xmlattr.get<string>("id");
		if(parent) {
			using_compound = true;
			st->parent = parent;
		}
		boost::optional<string> initial(xmlattr.get_optional<string>("initial"));
		if(initial) split(st->initial.target, *initial, is_any_of(" "), token_compress_on);
		if(st->initial.target.size() > 1) parallel_target_sizes.insert(st->initial.target.size());
		st->type = xmlattr.get_optional<string>("type");
		m_scxml.states.push_back(st);
		state_list::iterator state_i = --m_scxml.states.end();

		for (ptree::const_iterator it = pt.begin(); it != pt.end(); ++it) {
			if (it->first == "<xmlcomment>") ; // ignore comments
			else if (it->first == "<xmlattr>") ; // ignore, parsed above
			else if (it->first == "state") parse_state(it->second, st);
			else if (it->first == "history") parse_state(it->second, st);
			else if (it->first == "parallel") parse_parallel(it->second, st);
			else if (it->first == "transition") state_i->get()->transitions.push_back(parse_transition(it->second));
			else if (it->first == "onentry") state_i->get()->entry_actions = parse_entry(it->second);
			else if (it->first == "onexit") state_i->get()->exit_actions = parse_entry(it->second);
			else if (it->first == "initial") state_i->get()->initial = parse_initial(it->second);
			else cerr << "warning: unknown item '" << it->first << "' in <state>" << endl;
		}

		// if initial state is not set, use first state in document order
		// if parent is parallel put all states in initial
		if(parent && (parent->initial.target.empty() || (parent->type && *parent->type == "parallel"))) {
			parent->initial.target.push_back(st->id);
		}
	}
	catch (ptree_error e) {
		cerr << "error: state: " << e.what() << endl;
		exit(1);
	}
}
Example #13
0
void ProperyTreeUtils::write(ptree & properties, const std::vector<uint8_t> & data) {
	ptree propertiesData {};

	for(const uint8_t & value: data){
		ptree propertyValue {boost::lexical_cast<std::string>((int)value)};
		propertiesData.push_back({DATA_VALUE_NAME, propertyValue});
	}

	properties.put_child(DATA_NAME, propertiesData);

}
Example #14
0
	/*
	<scriptComponent>
	    <scriptObject constructor="addPlayer" destructor="removePlayer" />
	    <scriptData actorType="player"/>
	</scriptComponent>
	*/
	bool ScriptComponent::vInit(const ptree componentNode) {
		optional<const ptree&> optScriptObject = componentNode.get_child_optional(SCRIPT_OBJECT_NODE_NAME);
		if (optScriptObject.is_initialized()) {
			bool result = readScriptObjectNode(optScriptObject.get());
			if (!result) {
				return false;
			}
		}

		optional<const ptree&> optScriptData = componentNode.get_child_optional(SCRIPT_DATA_NODE_NAME);
		if (optScriptData.is_initialized()) {
			bool result = readScriptDataNode(optScriptData.get());
			if (!result) {
				return false;
			}
		}


		return true;
	};
Example #15
0
Chat::Ptr TgTypeParser::parseJsonAndGetChat(const ptree& data) const {
	Chat::Ptr result(new Chat);
	result->id = data.get<int64_t>("id");
	string type = data.get<string>("type");
	if (type == "private") {
		result->type = Chat::Type::Private;
	} else if (type == "group") {
		result->type = Chat::Type::Group;
	} else if (type == "supergroup") {
		result->type = Chat::Type::Supergroup;
	} else if (type == "channel") {
		result->type = Chat::Type::Channel;
	}
	result->title = data.get("title", "");
	result->username = data.get("username", "");
	result->firstName = data.get<string>("first_name", "");
	result->lastName = data.get("last_name", "");

	return result;
}
Example #16
0
Filter MakeFilter(const ptree& pt)
{
	Filter filter;
	filter.enable = pt.get<bool>("Enable");
	filter.text = pt.get<std::string>("Text");
	filter.matchType = StringToMatchType(pt.get<std::string>("MatchType"));
	filter.filterType = StringToFilterType(pt.get<std::string>("FilterType"));
	filter.bgColor = MakeColor(pt.get_child("BackColor"));
	filter.fgColor = MakeColor(pt.get_child("TextColor"));
	return filter;
}
shared_ptr<ProbabilisticWvmClassifier> ProbabilisticWvmClassifier::load(const ptree& subtree)
{
	pair<double, double> sigmoidParams = loadSigmoidParamsFromMatlab(subtree.get<string>("thresholdsFile"));
	// Load the detector and thresholds:
	shared_ptr<WvmClassifier> wvm = WvmClassifier::loadFromMatlab(subtree.get<string>("classifierFile"), subtree.get<string>("thresholdsFile"));
	shared_ptr<ProbabilisticWvmClassifier> pwvm = make_shared<ProbabilisticWvmClassifier>(wvm, sigmoidParams.first, sigmoidParams.second);

	pwvm->getWvm()->setLimitReliabilityFilter(subtree.get("threshold", 0.0f));

	return pwvm;
}
Example #18
0
void CompPhysics::loadFromPropertyTree(const ptree& propTree)
{
    float linearDamping = propTree.get("damping.linear", 0.0f);
    float angularDamping = propTree.get("damping.angular", 0.0f);

    bool fixedRotation = propTree.get("isFixedRotation", false);

    bool isBullet = propTree.get("isBullet", false);

    Vector2D gravitationPoint;
    gravitationPoint.x = propTree.get("gravitationPoint.x", 0.0f);
    gravitationPoint.y = propTree.get("gravitationPoint.y", 0.0f);

    BodyDef body_def;
    body_def.angularDamping = angularDamping;
    body_def.fixedRotation = fixedRotation;
    body_def.bullet = isBullet;
    body_def.linearDamping = linearDamping;

    setLocalGravitationPoint(gravitationPoint);

    m_shapeInfos.clear();
    foreach(const ptree::value_type &v, propTree)
    {
        if (v.first != "shape")
            continue;

        const ptree& shapeProps = v.second;
        std::string shapeName = shapeProps.get<std::string>("comp_id");

        float density = shapeProps.get("density", 0.0f);
        float friction = shapeProps.get("friction", 0.0f);
        float restitution = shapeProps.get("restitution", 0.0f);

        bool isSensor = shapeProps.get("isSensor", false);

        addShapeDef(boost::make_shared<ShapeDef>(shapeName, density, friction, restitution, isSensor));
    }

    setBodyDef(body_def);
}
Example #19
0
    bool ConfigTree::ptreeFromParam(ConfigParameter fromParam, ptree &toPtree)
    {
        CONFIGSYS_DEBUG_CALLS;

        toPtree = ptree();

        toPtree.put("desc", fromParam.getDescription());
        
        std::string modStr = (fromParam.isModified())? "true" : "false";
        toPtree.put("modified", modStr);

        std::string lockStr = (fromParam.isLocked())? "true" : "false";
        toPtree.put("locked", lockStr);


        value_type vt = fromParam.getType();
        std::string typStr = makeValueTypeString(vt);
        toPtree.put("type", typStr);
        
        return addParamValueandRangeToPtree(fromParam, toPtree);
    }
Example #20
0
scxml_parser::transition scxml_parser::parse_initial(const ptree &pt)
{
	scxml_parser::transition initial;
	initial.event = "initial";

	try {

		for (ptree::const_iterator it = pt.begin(); it != pt.end(); ++it) {
			if (it->first == "<xmlcomment>") ; // ignore comments
			else if (it->first == "transition") initial = *parse_transition(it->second);
			else cerr << "warning: unknown item '" << it->first << "' in <initial>" << endl;
		}

	}
	catch (ptree_error e) {
		cerr << "error: initial: " << e.what() << endl;
		exit(1);
	}

	return initial;
}
Example #21
0
//------------------------------------------------------------------------------
void
Image::set(ptree pt)
{
    if(pt.get_child_optional("UV"))        this->setUV(Box(pt.get_child("UV")), getBoolFromPT(pt, "UV.normalized", false));
    if(pt.get_child_optional("NinePatch")) this->setNinePatchData(NinePatchData(pt.get_child("NinePatch")));
    if(pt.get_child_optional("color"))     this->color = Color(pt.get("color", "#FFF"));
};
Example #22
0
void game_object:: init(game *g, ptree tree) {

	this->m_name = tree.get<string>("name");
	this->m_desc = tree.get<string>("m_desc");
	this->id = tree.get<unsigned long>("id");

	ptree childs = tree.get_child("children");
	for (auto it = childs.begin(); it != childs.end(); ++it) {
		game_object * child = initializers[it->first](g, it->second);
		child->move_to(*this);
	}

};
Example #23
0
void LayerConfiguration::ReadPtree(const ptree& pt,
								   const wxString& proj_path)
{
    layer_title = pt.get("title", "");
	
	// create DataSource instance from <datasource>...
	const ptree& subtree = pt.get_child("datasource");
	string type_str = subtree.get<string>("type");
	datasource = IDataSource::CreateDataSource(type_str, subtree, proj_path);

	layer_name = pt.get("layername", "");

	// create VarOrderPtree instance from <variable_order>...
	if (!variable_order) variable_order = new VarOrderPtree(pt, proj_path);
	// create CustomClassifPtree instance from <custom_classifications>...
	if (!custom_classifs) custom_classifs = new CustomClassifPtree(pt,
																   proj_path);
	// create WeightsManPtree instance from <spatial_weights>...
	if (!spatial_weights) spatial_weights = new WeightsManPtree(pt, proj_path);
	// create DefaultVarsPtree instance from <default_vars>...
	if (!default_vars) default_vars = new DefaultVarsPtree(pt, proj_path);
}
Example #24
0
File: Info.cpp Project: cyosp/MPA
string Info::executeGetRequest(ptree & root)
{
	string ret = MPAO::DEFAULT_JSON_ID;

	if( urlPairs.size() == 1 )
	{
		ptree versionPtree;
		versionPtree.put("version", MPA::version);
		root.push_back(std::make_pair("infos", versionPtree));
	}

	return ret;
}
Example #25
0
void MsgPrinter::addToArray(ptree& root, string name, map<string, string>& object) {

	static const string array_sufix = "..";

	optional<ptree&> child = root.get_child_optional(name);
	if (child.is_initialized()) {
		child.get().push_front(
				make_pair("", getItem(object))
			);
	} else {
		put(root, name + array_sufix, object);
	}
}
Example #26
0
void CameraProps::save(ptree & pt) {
	pt.put("device.device", device);
	pt.put("device.io", convIOMethod(io));
	pt.put("device.video_standard", convStandard(standard));
	pt.put("device.width", width);
	pt.put("device.height", height);
	pt.put("device.channel", channel);
}
Example #27
0
	void save(ptree & pt) {
		pt.put("directory", directory);
		pt.put("pattern", pattern);
		pt.put("sort", sort);
		pt.put("prefetch", prefetch);
		pt.put("triggered", triggered);
		pt.put("loop", loop);
	}
Example #28
0
Request::Request(const ptree &pt, const Storage &storage) {
	ptree::const_assoc_iterator it;
	storage.checkReady();

	indexName = pt.get<string>("index", "id");
	tableName = pt.get<string>("from");

	string api = pt.get<string>("api_key");
	APIKey = string(); for (size_t i=0; i<api.size() && APIKey.size()<=32; i++) if (isalnum(api[i])) APIKey += api[i];

	mode = Mode::Default;
	it = pt.find("mode"); if ( it != pt.not_found() ) {
		string modeString = pt.get<string>("mode");
		if (modeString == "count") mode = Mode::Count;
	}

	offset = pt.get<size_t>("offset", 0);
	limit = pt.get<size_t>("limit", 10);
	if (limit > 100) limit = 100;
	const Table &tbl = storage.activeSlotConst().getTableByNameConst(tableName);

	string name;
	name = "where"; it = pt.find(name); if ( it != pt.not_found() ) {BOOST_FOREACH(const ptree::value_type &v, pt.get_child(name)) { filters.push_back( ColumnCondition(v, tbl, ColumnCondition::OperType::Compare) ); } }
Example #29
0
void CameraProps::load(const ptree & pt) {
	LOG(LINFO) << "Loading settings for CameraV4L\n";
	device   =              pt.get("device.device", "/dev/video0");
	io       = convIOMethod(pt.get("device.io", "MMAP"));
	standard = convStandard(pt.get("device.video_standard", "PAL"));
	width    =              pt.get("device.width", 640);
	height   =              pt.get("device.height", 480);
	channel  =              pt.get("device.channel", "Composite");
}
Example #30
0
void scxml_parser::parse_scxml(const ptree &pt)
{
	try {
		using namespace boost::algorithm;
		const ptree &xmlattr = pt.get_child("<xmlattr>");
		boost::optional<string> initial(xmlattr.get_optional<string>("initial"));
		if(initial) split(m_scxml.initial.target, *initial, is_any_of(" "), token_compress_on);
		if(m_scxml.initial.target.size() > 1) parallel_target_sizes.insert(m_scxml.initial.target.size());
		m_scxml.name = xmlattr.get<string>("name", m_scxml.name);

		for (ptree::const_iterator it = pt.begin(); it != pt.end(); ++it) {
			if (it->first == "<xmlcomment>") ; // ignore comments
			else if (it->first == "<xmlattr>") ; // ignore, parsed above
			else if (it->first == "state") parse_state(it->second, boost::shared_ptr<state>());
			else if (it->first == "history") parse_state(it->second, boost::shared_ptr<state>());
			else if (it->first == "parallel") parse_parallel(it->second, boost::shared_ptr<state>());
			else if (it->first == "initial") m_scxml.initial = parse_initial(it->second);
			else cerr << "warning: unknown item '" << it->first << "' in <scxml>" << endl;
		}

		// if initial state is not set, use first state in document order
		if(m_scxml.initial.target.empty()) {
			if(m_scxml.states.size()) {
				m_scxml.initial.target.push_back((*m_scxml.states.begin())->id);
			}
			else {
				cerr << "error: could not set initial state" << endl;
				exit(1);
			}
		}
	}
	catch (ptree_error e) {
		cerr << "error: scxml: " << e.what() << endl;
		exit(1);
	}
}